summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2018-12-08 12:39:18 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2018-12-08 12:39:18 +0100
commitb3950330e3351437f153c6c1debb3821d6e28864 (patch)
tree0b381b523045bd59cd679825a11976a45813fc24 /src/main
parent439dcf391784ea3abb61473c74b9c27fcd9fdc2d (diff)
downloadrpgedit-b3950330e3351437f153c6c1debb3821d6e28864.tar
rpgedit-b3950330e3351437f153c6c1debb3821d6e28864.zip
Create Electron app
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();
+});