summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/index.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/main/index.ts b/src/main/index.ts
new file mode 100644
index 0000000..a4beb71
--- /dev/null
+++ b/src/main/index.ts
@@ -0,0 +1,51 @@
+import { app, BrowserWindow } from 'electron';
+import * as path from 'path';
+import { format as formatUrl } from 'url';
+
+const isDevelopment = process.env.NODE_ENV !== 'production';
+
+let mainWindow: BrowserWindow|null = null;
+
+function getIndexURL(): string {
+ if (isDevelopment)
+ return `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`;
+
+ return formatUrl({
+ pathname: path.join(__dirname, 'index.html'),
+ protocol: 'file',
+ slashes: true,
+ });
+}
+
+function createMainWindow(): BrowserWindow {
+ const window = new BrowserWindow();
+
+ if (isDevelopment)
+ window.webContents.openDevTools();
+
+ window.loadURL(getIndexURL());
+
+ window.on('closed', () => {
+ mainWindow = null;
+ });
+
+ window.webContents.on('devtools-opened', () => {
+ window.webContents.focus();
+ });
+
+ return window;
+}
+
+app.on('window-all-closed', () => {
+ if (process.platform !== 'darwin')
+ app.quit();
+});
+
+app.on('activate', () => {
+ if (!mainWindow)
+ mainWindow = createMainWindow();
+});
+
+app.on('ready', () => {
+ mainWindow = createMainWindow();
+});