From 9bfa680fa42a55749dd2cd6e5b20288b61520c19 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Tue, 28 Dec 2021 01:03:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=A2=E6=88=B7=E7=AB=AF=E5=AD=90?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E6=95=B0=E6=8D=AE=E5=90=8C=E6=AD=A5=E5=88=B0?= =?UTF-8?q?=E4=B8=BB=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main.js | 80 ++++++++++++------- resources/assets/js/App.vue | 11 ++- resources/assets/js/app.js | 19 +++-- resources/assets/js/components/AppDown.vue | 6 +- resources/assets/js/components/LuckySheet.vue | 4 +- resources/assets/js/pages/login.vue | 6 +- resources/assets/js/pages/manage.vue | 12 +-- .../pages/manage/components/ProjectList.vue | 8 +- .../js/pages/manage/components/TaskDetail.vue | 20 ++--- resources/assets/js/pages/manage/file.vue | 4 +- resources/assets/js/pages/single/file.vue | 2 +- resources/assets/js/pages/single/task.vue | 2 +- resources/assets/js/store/actions.js | 38 ++++++++- 13 files changed, 137 insertions(+), 75 deletions(-) diff --git a/electron/main.js b/electron/main.js index 14d6b94d..78806c1a 100644 --- a/electron/main.js +++ b/electron/main.js @@ -42,7 +42,7 @@ function randomString(len) { return pwd; } -function createWindow() { +function createMainWindow() { mainWindow = new BrowserWindow({ width: 1280, height: 800, @@ -53,6 +53,7 @@ function createWindow() { contextIsolation: false } }) + mainWindow.webContents.setUserAgent(mainWindow.webContents.getUserAgent() + " MainTaksWindow/1.0"); if (devloadUrl) { mainWindow.loadURL(devloadUrl).then(r => { @@ -76,24 +77,24 @@ function createWindow() { }) } -function createRouter(arg) { - if (!arg) { +function createSubWindow(args) { + if (!args) { return; } - if (typeof arg !== "object") { - arg = { - path: arg, + if (typeof args !== "object") { + args = { + path: args, config: {}, } } - let name = arg.name || "auto_" + randomString(6); + let name = args.name || "auto_" + randomString(6); let item = subWindow.find(item => item.name == name); let browser = item ? item.browser : null; if (browser) { browser.focus(); - if (arg.force === false) { + if (args.force === false) { return; } } else { @@ -104,11 +105,11 @@ function createRouter(arg) { parent: mainWindow, webPreferences: { preload: path.join(__dirname, 'preload.js'), - devTools: arg.devTools !== false, + devTools: args.devTools !== false, nodeIntegration: true, contextIsolation: false } - }, arg.config || {})) + }, args.config || {})) browser.on('close', function () { let index = subWindow.findIndex(item => item.name == name); if (index > -1) { @@ -117,14 +118,15 @@ function createRouter(arg) { }) subWindow.push({ name, browser }) } + browser.webContents.setUserAgent(browser.webContents.getUserAgent() + " SubTaskWindow/1.0" + (args.userAgent ? (" " + args.userAgent) : "")); if (devloadUrl) { - browser.loadURL(devloadUrl + '#' + (arg.hash || arg.path)).then(r => { + browser.loadURL(devloadUrl + '#' + (args.hash || args.path)).then(r => { }) } else { browser.loadFile('./public/index.html', { - hash: arg.hash || arg.path + hash: args.hash || args.path }).then(r => { }) @@ -132,10 +134,10 @@ function createRouter(arg) { } app.whenReady().then(() => { - createWindow() + createMainWindow() app.on('activate', () => { - if (BrowserWindow.getAllWindows().length === 0) createWindow() + if (BrowserWindow.getAllWindows().length === 0) createMainWindow() }) }) @@ -154,8 +156,8 @@ ipcMain.on('inheritClose', (event) => { event.returnValue = "ok" }) -ipcMain.on('windowRouter', (event, arg) => { - createRouter(arg) +ipcMain.on('windowRouter', (event, args) => { + createSubWindow(args) event.returnValue = "ok" }) @@ -170,34 +172,45 @@ ipcMain.on('windowClose', (event) => { event.returnValue = "ok" }) -ipcMain.on('windowSize', (event, arg) => { +ipcMain.on('windowSize', (event, args) => { const win = BrowserWindow.fromWebContents(event.sender); if (win) { - if (arg.width || arg.height) { - win.setSize(arg.width || win.getSize()[0], arg.height || win.getSize()[1]) + if (args.width || args.height) { + win.setSize(args.width || win.getSize()[0], args.height || win.getSize()[1], args.animate === true) } - if (arg.minWidth || arg.minHeight) { - win.setMinimumSize(arg.minWidth || win.getMinimumSize()[0], arg.minHeight || win.getMinimumSize()[1]) + if (args.minWidth || args.minHeight) { + win.setMinimumSize(args.minWidth || win.getMinimumSize()[0], args.minHeight || win.getMinimumSize()[1]) } - if (arg.maxWidth || arg.maxHeight) { - win.setMaximumSize(arg.maxWidth || win.getMaximumSize()[0], arg.maxHeight || win.getMaximumSize()[1]) + if (args.maxWidth || args.maxHeight) { + win.setMaximumSize(args.maxWidth || win.getMaximumSize()[0], args.maxHeight || win.getMaximumSize()[1]) + } + if (args.center === true) { + win.center(); } } event.returnValue = "ok" }) -ipcMain.on('windowMinSize', (event, arg) => { +ipcMain.on('windowMinSize', (event, args) => { const win = BrowserWindow.fromWebContents(event.sender); if (win) { - win.setMinimumSize(arg.width || win.getMinimumSize()[0], arg.height || win.getMinimumSize()[1]) + win.setMinimumSize(args.width || win.getMinimumSize()[0], args.height || win.getMinimumSize()[1]) } event.returnValue = "ok" }) -ipcMain.on('windowMaxSize', (event, arg) => { +ipcMain.on('windowMaxSize', (event, args) => { const win = BrowserWindow.fromWebContents(event.sender); if (win) { - win.setMaximumSize(arg.width || win.getMaximumSize()[0], arg.height || win.getMaximumSize()[1]) + win.setMaximumSize(args.width || win.getMaximumSize()[0], args.height || win.getMaximumSize()[1]) + } + event.returnValue = "ok" +}) + +ipcMain.on('windowCenter', (event, args) => { + const win = BrowserWindow.fromWebContents(event.sender); + if (win) { + win.center(); } event.returnValue = "ok" }) @@ -212,13 +225,20 @@ ipcMain.on('windowMax', (event) => { event.returnValue = "ok" }) -ipcMain.on('setDockBadge', (event, arg) => { +ipcMain.on('sendForwardMain', (event, args) => { + if (mainWindow) { + mainWindow.webContents.send(args.channel, args.data) + } + event.returnValue = "ok" +}) + +ipcMain.on('setDockBadge', (event, args) => { if(process.platform !== 'darwin'){ // Mac only return; } - if (runNum(arg) > 0) { - app.dock.setBadge(String(arg)) + if (runNum(args) > 0) { + app.dock.setBadge(String(args)) } else { app.dock.setBadge("") } diff --git a/resources/assets/js/App.vue b/resources/assets/js/App.vue index bb262739..e70d62dc 100755 --- a/resources/assets/js/App.vue +++ b/resources/assets/js/App.vue @@ -173,10 +173,10 @@ export default { }, electronEvents() { - if (!this.isElectron) { + if (!this.$Electron) { return; } - const {ipcRenderer} = this.$electron; + const {ipcRenderer} = this.$Electron; ipcRenderer.send('inheritClose'); ipcRenderer.on('windowClose', () => { if (this.$Modal.removeLast()) { @@ -188,6 +188,13 @@ export default { } ipcRenderer.send('windowHidden'); }) + ipcRenderer.on('dispatch', (event, args) => { + if (!this.$store.state.method.isJson(args)) { + return; + } + let {action, data} = args; + this.$store.dispatch(action, data); + }) } } } diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index 0caa3ae5..335ff74b 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -46,12 +46,6 @@ Vue.component('EDropdown', Dropdown); Vue.component('EDropdownMenu', DropdownMenu); Vue.component('EDropdownItem', DropdownItem); -Vue.prototype.isElectron = false; -if (!!__IS_ELECTRON) { - Vue.prototype.isElectron = true; - Vue.prototype.$electron = require('electron') -} - const originalPush = VueRouter.prototype.push VueRouter.prototype.push = function push(location) { return originalPush.call(this, location).catch(err => err) @@ -96,6 +90,8 @@ Vue.prototype.goBack = function (number) { }; Vue.prototype.$A = $A; +Vue.prototype.$Electron = !!__IS_ELECTRON ? require('electron') : null; + Vue.config.productionTip = false; const app = new Vue({ @@ -115,3 +111,14 @@ $A.Notice = app.$Notice; $A.Modal = app.$Modal; $A.store = app.$store; $A.L = app.$L; + +$A.Electron = app.$Electron; +$A.execMainDispatch = (action, data) => { + const navigator = window.navigator && window.navigator.userAgent + if ($A.Electron && navigator && /\s+SubTaskWindow\//.test(navigator)) { + $A.Electron.ipcRenderer.send('sendForwardMain', { + channel: 'dispatch', + data: {action, data}, + }); + } +}; diff --git a/resources/assets/js/components/AppDown.vue b/resources/assets/js/components/AppDown.vue index 07504958..3768d86f 100644 --- a/resources/assets/js/components/AppDown.vue +++ b/resources/assets/js/components/AppDown.vue @@ -1,6 +1,6 @@