From 8602ff4450326c3f965ebdc6ed7c5fa78f8bbfb1 Mon Sep 17 00:00:00 2001 From: Link Date: Sat, 28 Nov 2020 12:04:32 +0800 Subject: [PATCH] feat: monitor window zoom to ensure normal window --- src/electron/event/ipc-browser.ts | 3 ++- src/electron/event/ipc-main/index.ts | 5 +---- src/electron/event/ipc-renderer/index.ts | 5 ++++- src/electron/main.ts | 3 ++- src/iconfont/index.ts | 2 +- src/pages/header/view/index.tsx | 14 ++++++++++++++ src/pages/sidebar/view/index.less | 2 +- 7 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/electron/event/ipc-browser.ts b/src/electron/event/ipc-browser.ts index 605e4ef5..74c3c60e 100644 --- a/src/electron/event/ipc-browser.ts +++ b/src/electron/event/ipc-browser.ts @@ -4,7 +4,8 @@ export const importIpc = () => { return import('@/electron/event/ipc-renderer').then((v: IpcRenderer) => { return { sendAsyncIpcRendererEvent: v.sendAsyncIpcRendererEvent, - sendSyncIpcRendererEvent: v.sendSyncIpcRendererEvent + sendSyncIpcRendererEvent: v.sendSyncIpcRendererEvent, + getWindow: v.getWindow } }) } diff --git a/src/electron/event/ipc-main/index.ts b/src/electron/event/ipc-main/index.ts index 383dcf87..bbb0746f 100644 --- a/src/electron/event/ipc-main/index.ts +++ b/src/electron/event/ipc-main/index.ts @@ -8,18 +8,15 @@ import { } from '../action-types' export const onIpcMainEvent = (win: BrowserWindow) => { - let bounds = win.getBounds() let syrice: null | BrowserWindow ipcMain.on(Action.MINIMIZE_WINDOW, (event: IpcMainEvent, arg) => { win.minimize() }) ipcMain.on(Action.MAXIMIZE_WINDOW, (event: IpcMainEvent, arg) => { - bounds = win.getBounds() win.maximize() }) ipcMain.on(Action.RESTORE_WINDOW, (event: IpcMainEvent, arg) => { - win.setBounds(bounds, true) - bounds = win.getBounds() + win.restore() }) ipcMain.on(Action.CLOSE_WINDOW, (event: IpcMainEvent, arg) => { win.close() diff --git a/src/electron/event/ipc-renderer/index.ts b/src/electron/event/ipc-renderer/index.ts index 8f188bd3..bdd27cb4 100644 --- a/src/electron/event/ipc-renderer/index.ts +++ b/src/electron/event/ipc-renderer/index.ts @@ -5,7 +5,7 @@ Usually used in the rendering process to send information to the main process, and then process some things that the main process can handle (for example, changing the window, reading notifications) */ -import { ipcRenderer } from 'electron' +import { ipcRenderer, remote, BrowserWindow } from 'electron' import { Action, MiddlewareView, @@ -13,6 +13,8 @@ import { UpdateType } from '../action-types' +export const getWindow = () => remote.BrowserWindow.getFocusedWindow() + type Message = unknown type ActionType = Action | MiddlewareView | LyriceAction | UpdateType @@ -33,4 +35,5 @@ export function sendSyncIpcRendererEvent( export interface IpcRenderer { sendAsyncIpcRendererEvent: (action: ActionType, ...message: Message[]) => void sendSyncIpcRendererEvent: (action: ActionType, ...message: Message[]) => T + getWindow: () => BrowserWindow | null } diff --git a/src/electron/main.ts b/src/electron/main.ts index b0051462..3d82eb18 100644 --- a/src/electron/main.ts +++ b/src/electron/main.ts @@ -33,9 +33,10 @@ function createWindow() { // Use pluginOptions.nodeIntegration, leave this alone // See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info nodeIntegration: (process.env - .ELECTRON_NODE_INTEGRATION as unknown) as boolean + .ELECTRON_NODE_INTEGRATION as unknown) as boolean, // https://github.com/electron/electron/issues/9920 // preload: __dirname + '/electron/preload/index.js' + enableRemoteModule: true } }) diff --git a/src/iconfont/index.ts b/src/iconfont/index.ts index 57987ef6..49981192 100644 --- a/src/iconfont/index.ts +++ b/src/iconfont/index.ts @@ -2,4 +2,4 @@ import $script from 'scriptjs' import { noop } from '@/utils/index' // repair electron packaging '//' protocol problem -$script('//at.alicdn.com/t/font_2132275_edwe4same0b.js', noop) +$script('//at.alicdn.com/t/font_2132275_2fbtdtwvogo.js', noop) diff --git a/src/pages/header/view/index.tsx b/src/pages/header/view/index.tsx index 51940aba..81292530 100644 --- a/src/pages/header/view/index.tsx +++ b/src/pages/header/view/index.tsx @@ -46,6 +46,20 @@ export const Header = defineComponent({ } } + if (VUE_APP_PLATFORM === Platform.ELECTRON) { + window.addEventListener('resize', () => { + importIpc().then(event => { + const win = event.getWindow() + if (win) { + const isMax = win.isMaximized() + isMax + ? (windowSize.value = 'shrink') + : (windowSize.value = 'enlarge') + } + }) + }) + } + return () => (
diff --git a/src/pages/sidebar/view/index.less b/src/pages/sidebar/view/index.less index d9bf7f82..53f22b71 100644 --- a/src/pages/sidebar/view/index.less +++ b/src/pages/sidebar/view/index.less @@ -10,7 +10,7 @@ height: 40px; padding: 0 6px; margin: 2px 0; - font-size: 16px; + font-size: 15px; color: var(--secondary-text); &:hover { color: var(--secondary-text-hover);