From e0bc0516226c00e418261603a819ccf74193ce54 Mon Sep 17 00:00:00 2001 From: 8cy <50817549+8cy@users.noreply.github.com> Date: Mon, 22 Jun 2020 15:47:46 -0700 Subject: woah :star: --- index.js | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 index.js (limited to 'index.js') diff --git a/index.js b/index.js new file mode 100644 index 0000000..19a6b58 --- /dev/null +++ b/index.js @@ -0,0 +1,94 @@ +'use strict'; +const path = require('path'); +const { app, BrowserWindow, Menu, session } = require('electron'); +/// const {autoUpdater} = require('electron-updater'); +const {is} = require('electron-util'); +const unhandled = require('electron-unhandled'); +const debug = require('electron-debug'); +const contextMenu = require('electron-context-menu'); +const config = require('./config'); + +const menuEnable = config.get('menuEnable'); +const menu = require('./menu'); + +unhandled(); +contextMenu(); + +const debugEnable = config.get('debugEnable'); +if (debugEnable) debug(); + +// Note: Must match `build.appId` in package.json +app.setAppUserModelId('com.sin.monkey-type-desktop'); + +// Uncomment this before publishing your first version. +// It's commented out as it throws an error if there are no published versions. +// if (!is.development) { +// const FOUR_HOURS = 1000 * 60 * 60 * 4; +// setInterval(() => { +// autoUpdater.checkForUpdates(); +// }, FOUR_HOURS); +// +// autoUpdater.checkForUpdates(); +// } + +// Prevent window from being garbage collected +let mainWindow; + +const createMainWindow = async () => { + const win = new BrowserWindow({ + title: app.name, + show: false, + width: 960, + height: 540, + icon: path.join(__dirname, '/static/icon.png') + }); + + win.on('ready-to-show', () => { + win.show(); + }); + + win.on('closed', () => { + // Dereference the window + // For multiple windows store them in an array + mainWindow = undefined; + }); + + await win.loadURL("https://monkey-type.com/"); + + return win; +}; + +// Prevent multiple instances of the app +if (!app.requestSingleInstanceLock()) { + app.quit(); +} + +app.on('second-instance', () => { + if (mainWindow) { + if (mainWindow.isMinimized()) { + mainWindow.restore(); + } + + mainWindow.show(); + } +}); + +app.on('window-all-closed', () => { + if (!is.macos) { + app.quit(); + } +}); + +app.on('activate', async () => { + if (!mainWindow) { + mainWindow = await createMainWindow(); + } +}); + +(async () => { + await app.whenReady(); + menuEnable ? Menu.setApplicationMenu(menu) : Menu.setApplicationMenu(null); + mainWindow = await createMainWindow(); + + session.defaultSession.cookies.get({}).then(cookies => console.log(cookies)); +})(); -- cgit v1.2.3