From 59d2906c741b8e57aa7a6292d6c968bc8b2c61f5 Mon Sep 17 00:00:00 2001 From: fofolee Date: Mon, 2 May 2022 19:03:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A4=9A=E5=BC=80=E6=A3=80?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/preload.js | 19 +++++++++++++++++++ src/App.vue | 10 ++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/plugin/preload.js b/plugin/preload.js index 01012e7..f8d4ba9 100644 --- a/plugin/preload.js +++ b/plugin/preload.js @@ -23,6 +23,25 @@ window.yuQueClient = axios.create({ } }); +// 检测进程是否存在 +let isProcessExits = pid => { + try { + return process.kill(pid, 0) + } catch (e) { + return false + } +} + +// 多开检测 +window.multiProcessDetection = () => { + let pids = JSON.parse(localStorage.getItem('processes')) || []; + if (pids.length) pids = pids.filter(x => isProcessExits(x)); + pids.push(process.pid) + localStorage.setItem('processes', JSON.stringify(pids)) + if (pids.length > 1) return true; + return false; +} + // axios.defaults.adapter = require('axios/lib/adapters/http') if (!utools.isWindows()) process.env.PATH += ':/usr/local/bin:/usr/local/sbin' diff --git a/src/App.vue b/src/App.vue index f9a0b31..6c30ff7 100644 --- a/src/App.vue +++ b/src/App.vue @@ -68,6 +68,14 @@ export default defineComponent({ _.cloneDeep(defaultProfile), _.cloneDeep(userProfile) ); + // 默认主题色 + this.setCssVar("primary", this.profile.primaryColor); + this.startUpOnce(); + }, + // 插件全生命周期只运行一次,主要针对多开的情况 + startUpOnce() { + if (window.multiProcessDetection()) + return console.log("multiProcess Detected"); // 计划任务 _.forIn(this.profile.crontabs, (cronExp, featureCode) => { this.runCronTask(featureCode, cronExp); @@ -82,8 +90,6 @@ export default defineComponent({ ); console.log("Server Start..."); } - // 默认主题色 - this.setCssVar("primary", this.profile.primaryColor); }, enterPlugin(enter) { // 使用情况统计