Skip to content

Commit

Permalink
feat: keep window size
Browse files Browse the repository at this point in the history
  • Loading branch information
Linkontoask committed Dec 27, 2020
1 parent 67007d5 commit 143ce87
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/config/style.config.less
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@md-width: 1366px;
@md-width: 1024px;
@md-height: 700px;
8 changes: 4 additions & 4 deletions src/electron/event/ipc-main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ export const onIpcMainEvent = (win: BrowserWindow) => {
store.set('downloadPath', arg)
downloadPath = arg
})
ipcMain.on(Action.MINIMIZE_WINDOW, (event: IpcMainEvent, arg) => {
ipcMain.on(Action.MINIMIZE_WINDOW, (event: IpcMainEvent) => {
win.minimize()
})
ipcMain.on(Action.MAXIMIZE_WINDOW, (event: IpcMainEvent, arg) => {
ipcMain.on(Action.MAXIMIZE_WINDOW, (event: IpcMainEvent) => {
win.maximize()
})
ipcMain.on(Action.RESTORE_WINDOW, (event: IpcMainEvent, arg) => {
ipcMain.on(Action.RESTORE_WINDOW, (event: IpcMainEvent) => {
win.restore()
})
ipcMain.on(Action.CLOSE_WINDOW, (event: IpcMainEvent, arg) => {
ipcMain.on(Action.CLOSE_WINDOW, (event: IpcMainEvent) => {
win.close()
syrice && syrice.close()
})
Expand Down
3 changes: 3 additions & 0 deletions src/layout/container.less
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
width: 100%;
height: 80px;
transform: matrix(1, 0, 0, 1, 0, 0) !important;
& .schedule {
display: none;
}
}
&-md {
width: @md-width;
Expand Down
16 changes: 9 additions & 7 deletions src/layout/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ export const Container = defineComponent({

const { screenSize } = toRefs(useState())

watch(screenSize, v => {
if (v === LayoutSize.MD) {
startDrag.value()
} else {
stopDrag.value()
}
})
if (VUE_APP_PLATFORM === Platform.BROWSER) {
watch(screenSize, v => {
if (v === LayoutSize.MD) {
startDrag.value()
} else {
stopDrag.value()
}
})
}

onMounted(() => {
if (VUE_APP_PLATFORM === Platform.BROWSER) {
Expand Down
20 changes: 10 additions & 10 deletions src/pages/header/view/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { defineComponent, ref } from 'vue'
import { computed, defineComponent, ref } from 'vue'
import { Action } from '@/electron/event/action-types'
import { importIpc } from '@/electron/event/ipc-browser'
import { Logo } from '../component/logo'
import { PushShift } from '../component/push-shift'
import { Setting } from '../component/setting'
import { Search } from '../component/search'
import { LayoutActions } from '@/interface'
import { LayoutActions, LayoutSize } from '@/interface'
import { useLayoutModule } from '@/modules/index'
import { Platform } from '@/config/build'
import './index.less'
Expand All @@ -21,9 +21,8 @@ const actionToClass = {
export const Header = defineComponent({
name: 'Header',
setup() {
const windowSize = ref('enlarge')

const { useMutations } = useLayoutModule()
const { useState, useMutations } = useLayoutModule()
const state = useState()

const handleWindowControl = (action: Action) => {
if (VUE_APP_PLATFORM === Platform.BROWSER) {
Expand All @@ -36,12 +35,14 @@ export const Header = defineComponent({
}
}

const windowSize = computed(() => {
return state.screenSize === LayoutSize.MD ? 'enlarge' : 'shrink'
})

const windowsChangeSize = () => {
if (windowSize.value === 'shrink') {
windowSize.value = 'enlarge'
handleWindowControl(Action.RESTORE_WINDOW)
} else {
windowSize.value = 'shrink'
handleWindowControl(Action.MAXIMIZE_WINDOW)
}
}
Expand All @@ -52,9 +53,8 @@ export const Header = defineComponent({
const win = event.getWindow()
if (win) {
const isMax = win.isMaximized()
isMax
? (windowSize.value = 'shrink')
: (windowSize.value = 'enlarge')
const size = isMax ? LayoutSize.LG : LayoutSize.MD
useMutations(LayoutActions.CHANGE_WINDOW_SIZE, size)
}
})
})
Expand Down
8 changes: 0 additions & 8 deletions src/pages/main/view/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,3 @@
}
}
}

.container {
&-sm {
.main-container {
display: none;
}
}
}
1 change: 1 addition & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ plugins.push(
paths: [
'Auth.user',
'Header.themeColor',
'Layout',
'Footer.musicStack',
'Footer.musciHistory',
'Footer.volume',
Expand Down

0 comments on commit 143ce87

Please sign in to comment.