* Create main window * MARK: cMainWindow * @param {function} openCallback
(openCallback, doSplashScreen = true)
| 985 | * @param {function} openCallback |
| 986 | */ |
| 987 | createMainWindow (openCallback, doSplashScreen = true) { |
| 988 | |
| 989 | this.win.main = this.createSubWindow('main', { noSelect : false, show : !doSplashScreen, preload : 'sharedWindow' }) |
| 990 | |
| 991 | this.win.main.on('closed', () => { |
| 992 | this.win.main = null |
| 993 | app.quit() |
| 994 | }) |
| 995 | |
| 996 | if ( doSplashScreen ) { |
| 997 | this.win.splash = this.createSubWindow('splash', { center : true, fixed : true, frame : false, move : false, useCustomTitle : false }) |
| 998 | this.win.splash.loadURL(`file://${path.join(this.#path.render, 'splash.html')}?version=${app.getVersion()}`) |
| 999 | |
| 1000 | this.win.splash.on('closed', () => { this.win.splash = null }) |
| 1001 | } |
| 1002 | |
| 1003 | this.win.main.loadFile(path.join(this.#path.render, 'main.html')) |
| 1004 | |
| 1005 | if ( ! this.hasCrashed ) { |
| 1006 | this.win.main.webContents.session.setPermissionCheckHandler((_, permission) => { |
| 1007 | if (permission === 'hid') { return true } |
| 1008 | return false |
| 1009 | }) |
| 1010 | |
| 1011 | this.win.main.webContents.session.on('select-hid-device', (event, details, callback) => { |
| 1012 | event.preventDefault() |
| 1013 | const selectedDevice = details.deviceList.find((device) => { |
| 1014 | return device.vendorId === 0x340d && device.productId === 0x1710 |
| 1015 | }) |
| 1016 | callback(selectedDevice?.deviceId) |
| 1017 | }) |
| 1018 | } |
| 1019 | |
| 1020 | this.win.main.webContents.on('did-finish-load', () => { |
| 1021 | if ( doSplashScreen ) { |
| 1022 | setTimeout(() => { |
| 1023 | this.win.main.show() |
| 1024 | this.safeClose('splash') |
| 1025 | this.destroyAndFocus('splash') |
| 1026 | }, 2000) |
| 1027 | } |
| 1028 | const showCount = setInterval(() => { |
| 1029 | if ( this.isVisible('main') ) { |
| 1030 | clearInterval(showCount) |
| 1031 | openCallback() |
| 1032 | if ( this.#debug && ( !Object.hasOwn(this.devTools, 'main') || this.devTools.main === null ) ) { |
| 1033 | this.devTools.main = this.createSubWindow('devtools', { |
| 1034 | show : true, |
| 1035 | useCustomTitle : false, |
| 1036 | }) |
| 1037 | this.win.main.webContents.setDevToolsWebContents(this.devTools.main.webContents) |
| 1038 | this.win.main.webContents.openDevTools({ |
| 1039 | activate : false, |
| 1040 | mode : 'detach', |
| 1041 | }) |
| 1042 | this.devTools.main.minimize() |
| 1043 | |
| 1044 | setTimeout(() => { |
no test coverage detected