Skip to content

Commit ef16263

Browse files
committed
update color mode
1 parent 64e4594 commit ef16263

File tree

3 files changed

+25
-31
lines changed

3 files changed

+25
-31
lines changed

src/components/Frameworks/Navigation/index.vue

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<span class="color-mode" @click="switchColorMode">
1111
<el-icon v-if="isMatchColorMode('light')"><Sunny /></el-icon>
1212
<el-icon v-else-if="isMatchColorMode('dark')"><Moon /></el-icon>
13-
<el-icon v-else-if="isMatchColorMode('system')"><Setting /></el-icon>
1413
</span>
1514
</div>
1615
<router-link
@@ -80,49 +79,40 @@ export default {
8079
},
8180
methods: {
8281
initColorMode: function () {
83-
if (window.matchMedia("(prefers-color-scheme: light)").matches)
82+
if (window.matchMedia("(prefers-color-scheme: light)").matches) {
8483
document.querySelector("html").classList.remove("dark")
85-
else document.querySelector("html").classList.add("dark")
84+
this.colorMode = "light"
85+
} else {
86+
document.querySelector("html").classList.add("dark")
87+
this.colorMode = "dark"
88+
}
89+
90+
console.log(
91+
this.colorMode,
92+
window.matchMedia("(prefers-color-scheme: light)").matches
93+
)
8694
},
8795
handleOpenUserArea: function () {
8896
this.$router.push({ path: "/userArea" })
8997
},
9098
handleKeepDrag: () => false,
9199
isMatchColorMode: function (mode) {
100+
if (this.$router.currentRoute.value.path === "/setting") return false
92101
if (mode && this) return this.colorMode === mode
93102
return false
94103
},
95104
switchColorMode: function () {
96105
this.$conf.getConfPromise().then((data) => {
97-
switch (this.colorMode) {
98-
case "light": {
99-
data.data.userSetting.colorSchemeMode = "light"
100-
ipcRenderer.send("color-schemeMode-light")
101-
break
102-
}
103-
case "dark": {
104-
data.data.userSetting.colorSchemeMode = "dark"
105-
ipcRenderer.send("color-schemeMode-dark")
106-
break
107-
}
108-
case "system": {
109-
data.data.userSetting.colorSchemeMode = "system"
110-
ipcRenderer.send("color-schemeMode-system")
111-
break
112-
}
113-
default:
114-
break
115-
}
116-
if (this.colorMode === "light") {
117-
this.colorMode = "dark"
118-
} else if (this.colorMode === "dark") {
119-
this.colorMode = "system"
120-
} else if (this.colorMode === "system") {
121-
this.colorMode = "light"
122-
}
106+
ipcRenderer.send(
107+
`color-schemeMode-${this.colorMode === "light" ? "dark" : "light"}`
108+
)
109+
110+
data.data.userSetting.colorSchemeMode = this.colorMode
123111
this.handleStorgeSetting(data.data, () => {
124-
this.initColorMode()
125-
console.log(data.data.userSetting.colorSchemeMode)
112+
setTimeout(() => {
113+
this.initColorMode()
114+
this.$public.emit("update-color-mode", this.colorMode)
115+
}, 0)
126116
})
127117
})
128118
},

src/components/Setting/local/index.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ export default {
130130
this.$refs.opDomain.initOption(appInfo.domain)
131131
this.$refs.opPort.initOption(appInfo.port)
132132
})
133+
this.$public.on("update-color-mode", (mode) => {
134+
this.appTheme.value = mode
135+
})
133136
},
134137
mounted() {},
135138
methods: {

src/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ app.config.globalProperties.$utils = utils
2121
app.config.globalProperties.$conf = appConfig
2222
app.config.globalProperties.$leetcode = leetcode
2323
app.config.globalProperties.$public = new mitt()
24+
app.config.globalProperties.$router = router
2425

2526
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
2627
app.component(key, component)

0 commit comments

Comments
 (0)