Skip to content

Commit

Permalink
feat: monitor window zoom to ensure normal window
Browse files Browse the repository at this point in the history
  • Loading branch information
Linkontoask committed Nov 28, 2020
1 parent 4cc53ed commit 8602ff4
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/electron/event/ipc-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
}
5 changes: 1 addition & 4 deletions src/electron/event/ipc-main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion src/electron/event/ipc-renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ 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,
LyriceAction,
UpdateType
} from '../action-types'

export const getWindow = () => remote.BrowserWindow.getFocusedWindow()

type Message = unknown
type ActionType = Action | MiddlewareView | LyriceAction | UpdateType

Expand All @@ -33,4 +35,5 @@ export function sendSyncIpcRendererEvent<T>(
export interface IpcRenderer {
sendAsyncIpcRendererEvent: (action: ActionType, ...message: Message[]) => void
sendSyncIpcRendererEvent: <T>(action: ActionType, ...message: Message[]) => T
getWindow: () => BrowserWindow | null
}
3 changes: 2 additions & 1 deletion src/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})

Expand Down
2 changes: 1 addition & 1 deletion src/iconfont/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
14 changes: 14 additions & 0 deletions src/pages/header/view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => (
<header class="header">
<Logo></Logo>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/sidebar/view/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8602ff4

Please sign in to comment.