Skip to content

Commit

Permalink
♻️ 代码规范化
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Apr 12, 2024
1 parent d9cdea9 commit 2aa0df5
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/components/app/t-switchTheme.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
</template>
<script lang="ts" setup>
import { event } from "@tauri-apps/api";
import { computed, onMounted } from "vue";
import { UnlistenFn } from "@tauri-apps/api/helpers/event";
import { computed, onMounted, onUnmounted } from "vue";
import { useAppStore } from "../../store/modules/app";
// store
const appStore = useAppStore();
// theme
const themeGet = computed({
get() {
return appStore.theme;
Expand All @@ -24,22 +23,29 @@ const themeGet = computed({
appStore.theme = value;
},
});
let themeListener: UnlistenFn;
onMounted(async () => {
await listenOnTheme();
themeListener = await listenOnTheme();
});
async function switchTheme(): Promise<void> {
appStore.changeTheme();
await event.emit("readTheme", themeGet.value);
}
async function listenOnTheme(): Promise<void> {
await event.listen("readTheme", (e) => {
const theme = <string>e.payload;
async function listenOnTheme(): Promise<UnlistenFn> {
return await event.listen<string>("readTheme", (e) => {
const theme = e.payload;
themeGet.value = theme === "default" ? "default" : "dark";
});
}
onUnmounted(() => {
if (themeListener) {
themeListener();
}
});
</script>
<style lang="css" scoped>
.switch-box {
Expand Down

0 comments on commit 2aa0df5

Please sign in to comment.