Skip to content

Commit 46b9044

Browse files
committed
优化:快捷键触发独立窗口显示不展示主窗口
1 parent bbed29a commit 46b9044

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

electron/mapi/manager/clipboard/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ export const ManagerClipboard = {
117117
return EncodeUtil.aesEncode(dataJson, this.encryptKey)
118118
},
119119
decrypt(data: string): ClipboardHistoryRecord {
120-
data = EncodeUtil.aesDecode(data, this.encryptKey)
121120
try {
121+
data = EncodeUtil.aesDecode(data, this.encryptKey)
122122
return JSON.parse(data) as ClipboardHistoryRecord
123123
} catch (e) {
124124
return null

electron/mapi/manager/manager.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ export const Manager = {
8888
exec(action.data.command)
8989
break
9090
case ActionTypeEnum.WEB:
91-
if (!await ManagerPluginEvent.isMainWindowShown(null, null)) {
92-
await ManagerPluginEvent.showMainWindow(null, null)
93-
}
9491
await ManagerWindow.open(plugin, action)
9592
break
9693
case ActionTypeEnum.CODE:

electron/mapi/manager/plugin/event.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,11 @@ export const ManagerPluginEvent = {
341341
return AppConfig.version
342342
},
343343
outPlugin: async (context: PluginContext, data: any) => {
344-
await ManagerWindow.close(context._plugin);
344+
const option: any = {}
345+
if (context && context._window) {
346+
option.window = context._window
347+
}
348+
await ManagerWindow.close(context._plugin, option);
345349
},
346350
isDarkColors: async (context: PluginContext, data: any) => {
347351
return await AppsMain.shouldDarkMode()

electron/mapi/manager/window/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {Log} from "../../log/main";
1212
import {Events} from "../../event/main";
1313
import {ManagerSystem} from "../system";
1414
import {AppsMain} from "../../app/main";
15+
import {ManagerPluginEvent} from "../plugin/event";
1516

1617
const browserViews = new Map<WebContents, BrowserView>()
1718
const detachWindows = new Map<WebContents, BrowserWindow>()
@@ -264,8 +265,11 @@ export const ManagerWindow = {
264265
const view = win.getBrowserView()
265266
await executePluginHooks(view, 'SubInputChange', keywords);
266267
},
267-
async close(plugin?: PluginRecord, option?: {}) {
268+
async close(plugin?: PluginRecord, option?: {
269+
window?: BrowserWindow
270+
}) {
268271
if (mainWindowView && (!plugin || mainWindowView._plugin.name === plugin.name)) {
272+
// 主窗口插件
269273
await executePluginHooks(mainWindowView, 'PluginExit', null).then()
270274
await executeHooks(AppRuntime.mainWindow, 'PluginExit', null).then()
271275
removeBrowserViews(mainWindowView)
@@ -274,7 +278,11 @@ export const ManagerWindow = {
274278
mainWindowView.webContents?.destroy();
275279
} else {
276280
// detach的插件窗口
277-
//TODO
281+
if (option.window) {
282+
option.window.close()
283+
} else {
284+
Log.error('ManagerWindow.close', 'windowNotFound')
285+
}
278286
}
279287
},
280288
async openMainPluginDevTools(plugin: PluginRecord, option?: {}) {
@@ -293,6 +301,9 @@ export const ManagerWindow = {
293301
width: number,
294302
height: number,
295303
}) {
304+
if (!await ManagerPluginEvent.isMainWindowShown(null, null)) {
305+
await ManagerPluginEvent.showMainWindow(null, null)
306+
}
296307
// console.log('showInMainWindow', view._plugin.name, option)
297308
if (mainWindowView) {
298309
await this.close(mainWindowView._plugin)

0 commit comments

Comments
 (0)