aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPriyansh <[email protected]>2020-12-22 18:39:20 +0530
committerPriyansh <[email protected]>2020-12-22 18:39:20 +0530
commitfb873ec2c3cb71cd478e6d48b424ddbba67cab0a (patch)
tree29e763f84d54d24152a212ec19cdfad2d56235b5 /src
parent6593dc005ae8d8f94e7c6644e3af4026e57cd2bf (diff)
downloadstyx-fb873ec2c3cb71cd478e6d48b424ddbba67cab0a.tar.xz
styx-fb873ec2c3cb71cd478e6d48b424ddbba67cab0a.zip
App rewrite using typescript
Diffstat (limited to 'src')
-rw-r--r--src/app.ts4
-rw-r--r--src/preload.ts14
-rw-r--r--src/renderer.ts6
-rw-r--r--src/windowCreator.ts43
4 files changed, 67 insertions, 0 deletions
diff --git a/src/app.ts b/src/app.ts
new file mode 100644
index 0000000..b85e318
--- /dev/null
+++ b/src/app.ts
@@ -0,0 +1,4 @@
+import { app, BrowserWindow } from 'electron';
+import windowCreator from './windowCreator';
+
+windowCreator.main(app, BrowserWindow);
diff --git a/src/preload.ts b/src/preload.ts
new file mode 100644
index 0000000..30290eb
--- /dev/null
+++ b/src/preload.ts
@@ -0,0 +1,14 @@
+// All of the Node.js APIs are available in the preload process.
+// It has the same sandbox as a Chrome extension.
+window.addEventListener("DOMContentLoaded", () => {
+ const replaceText = (selector: string, text: string) => {
+ const element = document.getElementById(selector);
+ if (element) {
+ element.innerText = text;
+ }
+ };
+
+ for (const type of ["chrome", "node", "electron"]) {
+ replaceText(`${type}-version`, process.versions[type as keyof NodeJS.ProcessVersions]);
+ }
+});
diff --git a/src/renderer.ts b/src/renderer.ts
new file mode 100644
index 0000000..66042ac
--- /dev/null
+++ b/src/renderer.ts
@@ -0,0 +1,6 @@
+// This file is required by the app.html file and will
+// be executed in the renderer process for that window.
+// No Node.js APIs are available in this process unless
+// nodeIntegration is set to true in webPreferences.
+// Use preload.js to selectively enable features
+// needed in the renderer process.
diff --git a/src/windowCreator.ts b/src/windowCreator.ts
new file mode 100644
index 0000000..859ee03
--- /dev/null
+++ b/src/windowCreator.ts
@@ -0,0 +1,43 @@
+import { BrowserWindow } from 'electron';
+import * as path from 'path';
+
+export default class windowCreator {
+ static mainWindow: Electron.BrowserWindow;
+ static application: Electron.App;
+ static BrowserWindow;
+ private static onWindowAllClosed() {
+ if (process.platform !== 'darwin') {
+ windowCreator.application.quit();
+ }
+ }
+
+ private static onClose() {
+ // Dereference the window object.
+ windowCreator.mainWindow = null;
+ }
+
+ private static onReady() {
+ windowCreator.mainWindow = new windowCreator.BrowserWindow({
+ width: 800,
+ height: 600,
+ webPreferences: {
+ preload: path.join(__dirname, 'preload.js'),
+ nodeIntegration: true
+ },
+ });
+ windowCreator.mainWindow
+ .loadURL('file://' + __dirname + '/../app.html');
+ windowCreator.mainWindow.on('closed', windowCreator.onClose);
+ }
+
+ static main(app: Electron.App, browserWindow: typeof BrowserWindow) {
+ // we pass the Electron.App object and the
+ // Electron.BrowserWindow into this function
+ // so this class has no dependencies. This
+ // makes the code easier to write tests for
+ windowCreator.BrowserWindow = browserWindow;
+ windowCreator.application = app;
+ windowCreator.application.on('window-all-closed', windowCreator.onWindowAllClosed);
+ windowCreator.application.on('ready', windowCreator.onReady);
+ }
+}