diff --git a/src/layout/compoenets/LeftMenu.vue b/src/layout/compoenets/LeftMenu.vue index 4848d55..2e686f9 100644 --- a/src/layout/compoenets/LeftMenu.vue +++ b/src/layout/compoenets/LeftMenu.vue @@ -5,14 +5,14 @@ import { RouteRecordRaw } from "vue-router"; import Intro from "@/intro"; import "intro.js/introjs.css"; import confetti from "canvas-confetti/src/confetti.js"; -import { useFrpcProcessStore } from "@/store/frpcProcess"; +import { useFrpcDesktopStore } from "@/store/frpcDesktop"; import pkg from "../../../package.json"; defineComponent({ name: "AppMain" }); -const frpcProcessStore = useFrpcProcessStore(); +const frpcDesktopStore = useFrpcDesktopStore(); const routes = ref>([]); const guideSteps = ref({ Home: { diff --git a/src/main.ts b/src/main.ts index 0baa59a..c27eeb2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,9 +9,7 @@ import { IconifyIconOnline } from "./components/IconifyIcon"; import { createPinia } from "pinia"; -import { on, onListener } from "@/utils/ipcUtils"; -import { ipcRouters, listeners } from "../electron/core/IpcRouter"; -import { useFrpcProcessStore } from "@/store/frpcProcess"; +import { useFrpcDesktopStore } from "@/store/frpcDesktop"; const pinia = createPinia(); @@ -26,17 +24,10 @@ app .mount("#app") .$nextTick(() => { postMessage({ payload: "removeLoading" }, "*"); - - const frpcProcessStore = useFrpcProcessStore(); - - onListener(listeners.watchFrpcProcess, data => { - console.log("watchFrpcProcess", data); - frpcProcessStore.setRunning(data); - }); - - on(ipcRouters.LAUNCH.getStatus, data => { - console.log("getStatus", data); - frpcProcessStore.setRunning(data); - }); - }); + const frpcDesktopStore = useFrpcDesktopStore(); + frpcDesktopStore.onListenerFrpcProcessRunning(); + frpcDesktopStore.onListenerDownloadedVersion(); + frpcDesktopStore.refreshDownloadedVersion(); + }) + .then(r => {}); diff --git a/src/store/frpcDesktop.ts b/src/store/frpcDesktop.ts new file mode 100644 index 0000000..7b97f1e --- /dev/null +++ b/src/store/frpcDesktop.ts @@ -0,0 +1,36 @@ +import { defineStore } from "pinia"; +import { on, onListener, send } from "@/utils/ipcUtils"; +import { ipcRouters, listeners } from "../../electron/core/IpcRouter"; + +export const useFrpcDesktopStore = defineStore("frpcDesktop", { + state: () => ({ isRunning: false, versions: [] }), + getters: { + running: state => state.isRunning, + downloadedVersions: state => state.versions + }, + actions: { + onListenerFrpcProcessRunning() { + onListener(listeners.watchFrpcProcess, data => { + console.log("watchFrpcProcess", data); + this.isRunning = data; + }); + + on(ipcRouters.LAUNCH.getStatus, data => { + console.log("getStatus", data); + this.isRunning = data; + }); + }, + + onListenerDownloadedVersion() { + on(ipcRouters.VERSION.getDownloadedVersions, data => { + this.versions = data; + }); + }, + refreshRunning() { + send(ipcRouters.LAUNCH.getStatus); + }, + refreshDownloadedVersion() { + send(ipcRouters.VERSION.getDownloadedVersions); + } + } +}); diff --git a/src/store/frpcProcess.ts b/src/store/frpcProcess.ts deleted file mode 100644 index d237c3d..0000000 --- a/src/store/frpcProcess.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { defineStore } from "pinia"; -import { send } from "@/utils/ipcUtils"; -import { ipcRouters } from "../../electron/core/IpcRouter"; - -export const useFrpcProcessStore = defineStore("frpcProcess", { - state: () => ({ isRunning: false }), - getters: { - running: state => state.isRunning - }, - actions: { - setRunning(running: boolean) { - this.isRunning = running; - }, - refreshRunning() { - send(ipcRouters.LAUNCH.getStatus); - } - } -}); diff --git a/src/views/config/index.vue b/src/views/config/index.vue index dff7ed5..68f4478 100644 --- a/src/views/config/index.vue +++ b/src/views/config/index.vue @@ -9,6 +9,7 @@ import { on, removeRouterListeners, send } from "@/utils/ipcUtils"; import { ipcRouters } from "../../../electron/core/IpcRouter"; import _ from "lodash"; import confetti from "canvas-confetti/src/confetti.js"; +import { useFrpcDesktopStore } from "@/store/frpcDesktop"; defineComponent({ name: "Config" @@ -195,6 +196,7 @@ const visibles = reactive({ }); const exportConfigType = ref("toml"); +const frpcDesktopStore = useFrpcDesktopStore(); const handleSubmit = useDebounceFn(() => { if (!formRef.value) return; @@ -232,16 +234,16 @@ const checkAndResetVersion = () => { } }; -const handleLoadDownloadedVersion = () => { - send(ipcRouters.VERSION.getDownloadedVersions); -}; +// const handleLoadDownloadedVersion = () => { +// send(ipcRouters.VERSION.getDownloadedVersions); +// }; const handleLoadSavedConfig = () => { send(ipcRouters.SERVER.getServerConfig); }; onMounted(() => { - handleLoadDownloadedVersion(); + // handleLoadDownloadedVersion(); handleLoadSavedConfig(); on(ipcRouters.SERVER.getServerConfig, data => { @@ -267,7 +269,7 @@ onMounted(() => { }); on(ipcRouters.SYSTEM.selectLocalFile, data => { - console.log('data', data); + console.log("data", data); if (!data.canceled) { switch (currSelectLocalFileType.value) { case 1: @@ -577,14 +579,17 @@ onUnmounted(() => { clearable >
- + 手动刷新 diff --git a/src/views/download/index.vue b/src/views/download/index.vue index 3e1e970..a78bb89 100644 --- a/src/views/download/index.vue +++ b/src/views/download/index.vue @@ -7,6 +7,7 @@ import { useDebounceFn } from "@vueuse/core"; import IconifyIconOffline from "@/components/IconifyIcon/src/iconifyIconOffline"; import { on, removeRouterListeners, send } from "@/utils/ipcUtils"; import { ipcRouters } from "../../../electron/core/IpcRouter"; +import { useFrpcDesktopStore } from "@/store/frpcDesktop"; defineComponent({ name: "Download" @@ -23,6 +24,7 @@ const mirrors = ref>([ name: "github" } ]); +const frpcDesktopStore = useFrpcDesktopStore(); /** * 获取版本 @@ -60,35 +62,9 @@ const handleDeleteVersion = useDebounceFn((version: FrpcVersion) => { send(ipcRouters.VERSION.deleteDownloadedVersion, { githubReleaseId: version.githubReleaseId }); - // ipcRenderer.send("github.deleteVersion", { - // id: version.id, - // absPath: version.absPath - // }); }); }, 300); -// const handleInitDownloadHook = () => { -// ipcRenderer.on("Download.deleteVersion.hook", (event, args) => { -// const { err, data } = args; -// if (!err) { -// loading.value++; -// ElMessage({ -// type: "success", -// message: "删除成功" -// }); -// handleLoadVersions(); -// } -// }); -// ipcRenderer.on("Download.importFrpFile.hook", (event, args) => { -// const { success, data } = args; -// console.log(args); -// -// // if (err) { - -// // } -// }); -// }; - const handleMirrorChange = () => { handleLoadAllVersions(); }; @@ -97,7 +73,6 @@ onMounted(() => { handleLoadAllVersions(); on(ipcRouters.VERSION.getVersions, data => { - console.log("versionData", data); versions.value = data.map(m => { m.githubCreatedAt = moment(m.githubCreatedAt).format("YYYY-MM-DD"); return m as FrpcVersion; @@ -106,7 +81,6 @@ onMounted(() => { }); on(ipcRouters.VERSION.downloadVersion, data => { - console.log("downloadData", data); const { githubReleaseId, completed, percent } = data; if (completed) { downloading.value.delete(githubReleaseId); @@ -122,6 +96,7 @@ onMounted(() => { Number(Number(percent * 100).toFixed(2)) ); } + frpcDesktopStore.refreshDownloadedVersion(); }); on(ipcRouters.VERSION.deleteDownloadedVersion, () => { @@ -131,6 +106,7 @@ onMounted(() => { message: "删除成功" }); handleLoadAllVersions(); + frpcDesktopStore.refreshDownloadedVersion(); }); on( @@ -144,6 +120,7 @@ onMounted(() => { message: "导入成功" }); handleLoadAllVersions(); + frpcDesktopStore.refreshDownloadedVersion(); } }, (bizCode: string, message: string) => { @@ -176,7 +153,6 @@ onUnmounted(() => {