MCPcopy Index your code
hub / github.com/ZToolsCenter/ZTools / register

Method register

src/main/utils/devToolsShortcut.ts:32–59  ·  view source on GitHub ↗

* 注册当前焦点的 DevTools 快捷键 * @param target 需要打开开发者工具的 WebContents

(target: Electron.WebContents)

Source from the content-addressed store, hash-verified

30 * @param target 需要打开开发者工具的 WebContents
31 */
32 public register(target: Electron.WebContents): void {
33 // 如果已经注册且目标相同,无需重复注册
34 if (this.currentTarget?.id === target.id && globalShortcut.isRegistered(this.shortcut)) {
35 return
36 }
37
38 // 先注销可能存在的旧注册
39 this.unregister()
40
41 this.currentTarget = target
42
43 // 注册全局快捷键
44 const ret = globalShortcut.register(this.shortcut, async () => {
45 if (this.currentTarget && !this.currentTarget.isDestroyed()) {
46 console.log(`[DevTools] 触发开发者工具快捷键,目标: ${this.currentTarget.id}`)
47 if (this.currentTarget.isDevToolsOpened()) {
48 this.currentTarget.closeDevTools()
49 } else {
50 const mode = getDevToolsMode()
51 this.currentTarget.openDevTools({ mode })
52 }
53 }
54 })
55
56 if (!ret) {
57 console.error(`[DevTools] 开发者工具快捷键注册失败: ${this.shortcut}`)
58 }
59 }
60
61 /**
62 * 注销快捷键

Callers

nothing calls this directly

Calls 3

unregisterMethod · 0.95
getDevToolsModeFunction · 0.85
registerMethod · 0.65

Tested by

no test coverage detected