Skip to content

Commit 86f42c2

Browse files
committed
improve: add logic for main / about windows size change on scale change
1 parent 24478ba commit 86f42c2

File tree

8 files changed

+181
-6
lines changed

8 files changed

+181
-6
lines changed

electron/actions/aboutWindow/create.js

+23-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ import changeViewBackgroundColor
1313
import setViewScale from '../view/setScale.js'
1414
import setAboutViewBounds from '../aboutView/setBounds.js'
1515
import {
16-
isDevelopment
16+
isDevelopment,
17+
windowsDefaultSizes
1718
} from '../../helpers/utils.js'
1819
import {
1920
preloadScriptFilePath
2021
} from '../../helpers/paths.js'
22+
import setAboutWindowScale from './setScale.js'
23+
24+
function handleResize () {
25+
setAboutViewBounds()
26+
}
2127

2228
function handleClose (
2329
event
@@ -30,14 +36,23 @@ function handleClose (
3036
function handleFirstShow () {
3137
setAboutViewBounds()
3238

39+
setAboutWindowScale()
40+
3341
setViewScale(
3442
aboutView
3543
)
3644
}
3745

3846
export default function () {
39-
const aboutWindowWidth = 500
40-
const aboutWindowHeight = 275
47+
const aboutWindowWidth =
48+
windowsDefaultSizes
49+
.about
50+
.width
51+
52+
const aboutWindowHeight =
53+
windowsDefaultSizes
54+
.about
55+
.height
4156

4257
const aboutWindowOptions = {
4358
width: aboutWindowWidth,
@@ -94,6 +109,11 @@ export default function () {
94109
handleFirstShow
95110
)
96111

112+
aboutWindow.on(
113+
'resize',
114+
handleResize
115+
)
116+
97117
aboutWindow.on(
98118
'close',
99119
handleClose
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import getSettingsKey from '../settings/getKey.js'
2+
import getScreenWorkAreaSize from '../screen/getWorkAreaSize.js'
3+
import {
4+
windowsDefaultSizes
5+
} from '../../helpers/utils.js'
6+
7+
export default function () {
8+
const scale =
9+
getSettingsKey(
10+
'layout.scale'
11+
)
12+
13+
const isChangeScale = (
14+
scale >= 0
15+
)
16+
17+
if (isChangeScale) {
18+
const {
19+
width,
20+
height
21+
} = windowsDefaultSizes.about
22+
23+
const widthScaled = width * scale
24+
25+
const heightScaled = height * scale
26+
27+
const {
28+
width: screenWorkAreaWidth,
29+
height: screenWorkAreaHeight
30+
} = getScreenWorkAreaSize()
31+
32+
const minimumWidthScaled =
33+
Math.min(
34+
widthScaled,
35+
screenWorkAreaWidth - 50
36+
)
37+
38+
const minimumHeightScaled =
39+
Math.min(
40+
heightScaled,
41+
screenWorkAreaHeight - 50
42+
)
43+
44+
aboutWindow.setMinimumSize(
45+
minimumWidthScaled,
46+
minimumHeightScaled
47+
)
48+
49+
aboutWindow.setSize(
50+
widthScaled,
51+
heightScaled
52+
)
53+
54+
aboutWindow.center()
55+
}
56+
}

electron/actions/mainWindow/create.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
import {
99
isDevelopment,
1010
wait,
11-
isShowDevTools
11+
isShowDevTools,
12+
windowsDefaultSizes
1213
} from '../../helpers/utils.js'
1314
import {
1415
baseUrl
@@ -32,6 +33,7 @@ import {
3233
import {
3334
preloadScriptFilePath
3435
} from '../../helpers/paths.js'
36+
import setMainWindowScale from './setScale.js'
3537

3638
function handleShow () {
3739
setTrayMenu()
@@ -85,6 +87,8 @@ function handleDidFinishLoad () {
8587
async function handleFirstShow () {
8688
resizeViews()
8789

90+
setMainWindowScale()
91+
8892
setViewScale(
8993
mainView
9094
)
@@ -118,8 +122,15 @@ async function handleFirstShow () {
118122
}
119123

120124
export default function () {
121-
const mainWindowWidth = 900
122-
const mainWindowHeight = 600
125+
const mainWindowWidth =
126+
windowsDefaultSizes
127+
.main
128+
.width
129+
130+
const mainWindowHeight =
131+
windowsDefaultSizes
132+
.main
133+
.height
123134

124135
const mainWindowOptions = {
125136
width: mainWindowWidth,
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import getSettingsKey from '../settings/getKey.js'
2+
import getScreenWorkAreaSize from '../screen/getWorkAreaSize.js'
3+
import {
4+
windowsDefaultSizes
5+
} from '../../helpers/utils.js'
6+
7+
export default function () {
8+
const scale =
9+
getSettingsKey(
10+
'layout.scale'
11+
)
12+
13+
const isChangeScale = (
14+
scale >= 0 &&
15+
!mainWindow.isMaximized()
16+
)
17+
18+
if (isChangeScale) {
19+
const {
20+
width,
21+
height
22+
} = windowsDefaultSizes.main
23+
24+
const widthScaled = width * scale
25+
26+
const heightScaled = height * scale
27+
28+
const {
29+
width: screenWorkAreaWidth,
30+
height: screenWorkAreaHeight
31+
} = getScreenWorkAreaSize()
32+
33+
const minimumWidthScaled =
34+
Math.min(
35+
widthScaled,
36+
screenWorkAreaWidth - 50
37+
)
38+
39+
const minimumHeightScaled =
40+
Math.min(
41+
heightScaled,
42+
screenWorkAreaHeight - 50
43+
)
44+
45+
mainWindow.setMinimumSize(
46+
minimumWidthScaled,
47+
minimumHeightScaled
48+
)
49+
50+
mainWindow.setSize(
51+
widthScaled,
52+
heightScaled
53+
)
54+
55+
mainWindow.center()
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {
2+
screen
3+
} from 'electron'
4+
5+
export default function () {
6+
return screen
7+
.getPrimaryDisplay()
8+
.workAreaSize
9+
}

electron/actions/windows/setScale.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import setMainWindowScale from '../mainWindow/setScale.js'
2+
import setAboutWindowScale from '../aboutWindow/setScale.js'
3+
4+
export default function () {
5+
setMainWindowScale()
6+
7+
setAboutWindowScale()
8+
}

electron/handlers/settings.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import setViewsDarkMode from '../actions/views/setDarkMode.js'
22
import setViewsScale from '../actions/views/setScale.js'
3+
import setWindowsScale from '../actions/windows/setScale.js'
34

45
export function handleIsDarkModeChange () {
56
setViewsDarkMode()
67
}
78

89
export function handleScaleChange () {
10+
setWindowsScale()
11+
912
setViewsScale()
1013
}

electron/helpers/utils.js

+11
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ export const isShowDevTools =
8989
'dev-tools'
9090
)
9191

92+
export const windowsDefaultSizes = {
93+
main: {
94+
width: 900,
95+
height: 600
96+
},
97+
about: {
98+
width: 500,
99+
height: 275
100+
}
101+
}
102+
92103
export function createFolderIfNotExists (
93104
path
94105
) {

0 commit comments

Comments
 (0)