2019-04-10 19:35:55 +09:00
|
|
|
import {
|
|
|
|
app,
|
2019-04-24 20:59:30 +09:00
|
|
|
ipcMain,
|
2019-04-22 19:08:23 +09:00
|
|
|
shell,
|
2019-04-24 20:59:30 +09:00
|
|
|
systemPreferences,
|
|
|
|
Event,
|
2019-04-10 19:35:55 +09:00
|
|
|
Menu,
|
|
|
|
} from 'electron'
|
|
|
|
import {
|
|
|
|
createProtocol,
|
|
|
|
installVueDevtools,
|
|
|
|
} from 'vue-cli-plugin-electron-builder/lib'
|
2019-04-22 19:08:23 +09:00
|
|
|
|
2019-04-10 19:35:55 +09:00
|
|
|
import Window from './Window'
|
2019-04-24 03:40:04 +09:00
|
|
|
import Timeline from './Timeline'
|
2019-04-24 05:13:32 +09:00
|
|
|
import Streaming from './Streaming'
|
2019-04-25 00:52:40 +09:00
|
|
|
import Auth from './Auth'
|
2019-04-10 19:35:55 +09:00
|
|
|
|
|
|
|
const isDevelopment = process.env.NODE_ENV !== 'production'
|
|
|
|
|
|
|
|
export default class Application {
|
2019-04-22 18:39:16 +09:00
|
|
|
private static _instance: Application
|
2019-04-10 19:35:55 +09:00
|
|
|
|
2019-04-24 03:40:04 +09:00
|
|
|
public static get shared(): Application {
|
2019-04-10 19:35:55 +09:00
|
|
|
// 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())
|
2019-04-10 19:35:55 +09:00
|
|
|
}
|
|
|
|
|
2019-04-24 20:59:30 +09:00
|
|
|
public isDarkMode: boolean
|
|
|
|
|
2019-04-10 19:35:55 +09:00
|
|
|
private constructor() {
|
2019-04-24 20:59:30 +09:00
|
|
|
this.isDarkMode = systemPreferences.isDarkMode()
|
2019-04-10 19:35:55 +09:00
|
|
|
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())
|
2019-04-24 20:59:30 +09:00
|
|
|
|
|
|
|
systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', () => {
|
|
|
|
this.isDarkMode = systemPreferences.isDarkMode()
|
|
|
|
Window.windowMap.forEach(win => {
|
|
|
|
win.webContents.send('change-color-theme')
|
|
|
|
})
|
|
|
|
})
|
2019-04-10 19:35:55 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
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())
|
2019-04-10 19:35:55 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!process.env.WEBPACK_DEV_SERVER_URL) createProtocol('app')
|
2019-04-24 03:40:04 +09:00
|
|
|
|
|
|
|
Timeline.ready()
|
2019-04-24 05:13:32 +09:00
|
|
|
Streaming.ready()
|
2019-04-25 00:52:40 +09:00
|
|
|
Auth.ready()
|
2019-04-24 03:40:04 +09:00
|
|
|
|
2019-04-24 20:59:30 +09:00
|
|
|
ipcMain.on('dark-theme', (e: Event) => e.returnValue = this.isDarkMode)
|
|
|
|
|
2019-04-10 19:35:55 +09:00
|
|
|
Window.Main()
|
|
|
|
}
|
|
|
|
|
|
|
|
private onActivated() {
|
2019-04-24 02:56:47 +09:00
|
|
|
if (!Window.windowMap.has('main')) {
|
2019-04-10 19:35:55 +09:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
2019-04-10 19:35:55 +09:00
|
|
|
}
|