Skip to content

Commit 0bd41f7

Browse files
chengdiaonashaofu
authored andcommitted
fix: 修复 macos 截图窗口会新建试图,而不是覆盖在当前界面上
1 parent d00ff54 commit 0bd41f7

File tree

5 files changed

+1172
-1411
lines changed

5 files changed

+1172
-1411
lines changed

packages/electron-screenshots/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"dependencies": {
3838
"debug": "^4.3.4",
3939
"fs-extra": "^11.1.1",
40-
"node-screenshots": "^0.1.2",
40+
"node-screenshots": "^0.1.4",
4141
"react-screenshots": "^0.5.19"
4242
},
4343
"peerDependencies": {

packages/electron-screenshots/src/screenshots.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ export default class Screenshots extends Events {
106106

107107
// 先清除 Kiosk 模式,然后取消全屏才有效
108108
this.$win.setKiosk(false);
109-
this.$win.setSimpleFullScreen(false);
110109
this.$win.blur();
111110
this.$win.blurWebView();
112111
this.$win.unmaximize();
@@ -154,49 +153,53 @@ export default class Screenshots extends Events {
154153

155154
// 复用未销毁的窗口
156155
if (!this.$win || this.$win?.isDestroyed?.()) {
156+
const windowTypes: Record<string, string> = {
157+
darwin: 'panel',
158+
linux: 'dock',
159+
win32: 'toolbar',
160+
};
161+
157162
this.$win = new BrowserWindow({
158163
title: 'screenshots',
159164
x: display.x,
160165
y: display.y,
161166
width: display.width,
162167
height: display.height,
163168
useContentSize: true,
169+
type: windowTypes[process.platform],
164170
frame: false,
165171
show: false,
166172
autoHideMenuBar: true,
167173
transparent: true,
168-
// mac resizable 设置为 true 会导致应用崩溃
169-
resizable: process.platform !== 'darwin',
174+
resizable: false,
170175
movable: false,
176+
minimizable: false,
177+
maximizable: false,
171178
// focusable 必须设置为 true, 否则窗口不能及时响应esc按键,输入框也不能输入
172179
focusable: true,
173-
// mac fullscreenable 设置为 true 会导致应用崩溃
174-
fullscreenable: process.platform !== 'darwin',
180+
skipTaskbar: true,
181+
alwaysOnTop: true,
175182
/**
176183
* linux 下必须设置为false,否则不能全屏显示在最上层
177-
* mac 下设置为false,否则可能会导致程序坞不恢复问题
178-
* https://github.com/nashaofu/screenshots/issues/148
184+
* mac 下设置为false,否则可能会导致程序坞不恢复问题,且与 kiosk 模式冲突
179185
*/
180-
// fullscreen: process.platform === 'darwin',
181-
// 设为true 防止mac新开一个桌面,影响效果
182-
simpleFullscreen: process.platform === 'darwin',
186+
fullscreen: false,
187+
// mac fullscreenable 设置为 true 会导致应用崩溃
188+
fullscreenable: false,
189+
kiosk: true,
183190
backgroundColor: '#00000000',
184191
titleBarStyle: 'hidden',
185-
alwaysOnTop: true,
186-
enableLargerThanScreen: true,
187-
skipTaskbar: true,
188192
hasShadow: false,
189193
paintWhenInitiallyHidden: false,
194+
// mac 特有的属性
195+
roundedCorners: false,
196+
enableLargerThanScreen: false,
190197
acceptFirstMouse: true,
191198
});
192199

193200
this.$win.on('show', () => {
194201
this.$win?.focus();
195-
/**
196-
* 在窗口显示时设置,防止与 fullscreen、x、y、width、height 等冲突, 导致显示效果不符合预期
197-
* mac 下不设置 kiosk 模式,https://github.com/nashaofu/screenshots/issues/148
198-
*/
199-
this.$win?.setKiosk(process.platform !== 'darwin');
202+
this.$win?.setKiosk(true);
200203
});
201204

202205
this.$win.on('closed', () => {
@@ -220,11 +223,6 @@ export default class Screenshots extends Events {
220223

221224
this.$win.blur();
222225
this.$win.setKiosk(false);
223-
224-
if (process.platform === 'darwin') {
225-
this.$win.setSimpleFullScreen(true);
226-
}
227-
228226
this.$win.setBounds(display);
229227
this.$view.setBounds({
230228
x: 0,

0 commit comments

Comments
 (0)