thedesk/src/main/Application.ts

65 lines
1.6 KiB
TypeScript
Raw Normal View History

import {
app,
2019-04-22 19:08:23 +09:00
shell,
Menu,
} from 'electron'
import {
createProtocol,
installVueDevtools,
} from 'vue-cli-plugin-electron-builder/lib'
2019-04-22 19:08:23 +09:00
import Window from './Window'
const isDevelopment = process.env.NODE_ENV !== 'production'
export default class Application {
2019-04-22 18:39:16 +09:00
private static _instance: Application
public static get shared() {
// Do you need arguments? Make it a regular static method instead.
2019-04-22 18:39:16 +09:00
return this._instance || (this._instance = new this())
}
private constructor() {
app.on('window-all-closed', () => this.onWindowAllClosed())
2019-04-22 18:39:16 +09:00
app.on('ready', () => this.onReady())
app.on('activate', () => this.onActivated())
}
public setApplicationMenu(menu: Menu) {
Menu.setApplicationMenu(menu)
}
private onWindowAllClosed() {
if (process.platform !== 'darwin') {
app.quit()
}
}
private async onReady() {
if (isDevelopment && !process.env.IS_TEST) {
// Install Vue Devtools
try {
await installVueDevtools()
} catch (e) {
2019-04-22 13:35:19 +09:00
console.error('Vue Devtools failed to install:', e.toString())
}
}
if (!process.env.WEBPACK_DEV_SERVER_URL) createProtocol('app')
Window.Main()
}
private onActivated() {
if (!Window.single.has('main')) {
Window.Main()
}
}
2019-04-22 19:08:23 +09:00
public static openUrl(event: Event, url: string) {
shell.openExternal(url, {
activate: false
}, (err) => {
if (err) console.log(err)
})
}
}