Remove singleton option
Always singleton:(
This commit is contained in:
parent
4f2da222a1
commit
38657ce31a
|
@ -17,7 +17,6 @@ export interface CreateWindowOptions {
|
||||||
windowName: string
|
windowName: string
|
||||||
loadPath: string
|
loadPath: string
|
||||||
windowOptions?: BrowserWindowConstructorOptions
|
windowOptions?: BrowserWindowConstructorOptions
|
||||||
singleton?: boolean
|
|
||||||
lastAction?: (win: BrowserWindow) => void
|
lastAction?: (win: BrowserWindow) => void
|
||||||
openDevTools?: boolean
|
openDevTools?: boolean
|
||||||
}
|
}
|
||||||
|
@ -25,8 +24,7 @@ export interface CreateWindowOptions {
|
||||||
export default class Window {
|
export default class Window {
|
||||||
public static ApplicationURL: string = process.env.WEBPACK_DEV_SERVER_URL /* `electron:serve`で起動した時 */ || 'app://./' /* ビルドしたアプリ */
|
public static ApplicationURL: string = process.env.WEBPACK_DEV_SERVER_URL /* `electron:serve`で起動した時 */ || 'app://./' /* ビルドしたアプリ */
|
||||||
|
|
||||||
public static single: Map<string, BrowserWindow> = new Map()
|
public static windowMap: Map<string, BrowserWindow> = new Map()
|
||||||
public static list: BrowserWindow[]
|
|
||||||
|
|
||||||
public static Main() {
|
public static Main() {
|
||||||
const opts: CreateWindowOptions = {
|
const opts: CreateWindowOptions = {
|
||||||
|
@ -38,9 +36,8 @@ export default class Window {
|
||||||
height: 600,
|
height: 600,
|
||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
},
|
},
|
||||||
singleton: true,
|
|
||||||
lastAction: (win) => {
|
lastAction: (win) => {
|
||||||
shortcutRegister(win, 'F5', () => this.single.get('main')!.reload())
|
shortcutRegister(win, 'F5', () => this.windowMap.get('main')!.reload())
|
||||||
},
|
},
|
||||||
openDevTools: !process.env.IS_TEST
|
openDevTools: !process.env.IS_TEST
|
||||||
}
|
}
|
||||||
|
@ -62,13 +59,12 @@ export default class Window {
|
||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
titleBarStyle: 'hiddenInset',
|
titleBarStyle: 'hiddenInset',
|
||||||
},
|
},
|
||||||
singleton: true,
|
|
||||||
lastAction: (win) => {
|
lastAction: (win) => {
|
||||||
win.setMenuBarVisibility(false)
|
win.setMenuBarVisibility(false)
|
||||||
win.webContents.on('before-input-event', (event: Event, input: Input) => {
|
win.webContents.on('before-input-event', (event: Event, input: Input) => {
|
||||||
this.single.get('about')!.webContents.setIgnoreMenuShortcuts((process.platform === 'darwin' ? input.meta : input.control) && input.key === 'r')
|
this.windowMap.get('about')!.webContents.setIgnoreMenuShortcuts((process.platform === 'darwin' ? input.meta : input.control) && input.key === 'r')
|
||||||
})
|
})
|
||||||
shortcutRegister(win, 'Esc', () => this.single.get('about')!.destroy())
|
shortcutRegister(win, 'Esc', () => this.windowMap.get('about')!.destroy())
|
||||||
},
|
},
|
||||||
openDevTools: !process.env.IS_TEST
|
openDevTools: !process.env.IS_TEST
|
||||||
}
|
}
|
||||||
|
@ -76,8 +72,8 @@ export default class Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async createWindow(options: CreateWindowOptions) {
|
public static async createWindow(options: CreateWindowOptions) {
|
||||||
if (options.singleton && this.single.has(options.windowName)) {
|
if (this.windowMap.has(options.windowName)) {
|
||||||
this.single.get(options.windowName)!.show()
|
this.windowMap.get(options.windowName)!.show()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let win = new BrowserWindow(options.windowOptions)
|
let win = new BrowserWindow(options.windowOptions)
|
||||||
|
@ -87,7 +83,7 @@ export default class Window {
|
||||||
})
|
})
|
||||||
|
|
||||||
win.on('closed', () => {
|
win.on('closed', () => {
|
||||||
this.single.delete(options.windowName)
|
this.windowMap.delete(options.windowName)
|
||||||
})
|
})
|
||||||
|
|
||||||
let openUrl = (event: Event, url: string) => {
|
let openUrl = (event: Event, url: string) => {
|
||||||
|
@ -106,6 +102,6 @@ export default class Window {
|
||||||
|
|
||||||
if (typeof options.lastAction === 'function') options.lastAction(win)
|
if (typeof options.lastAction === 'function') options.lastAction(win)
|
||||||
|
|
||||||
this.single.set(options.windowName, win)
|
this.windowMap.set(options.windowName, win)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user