From 0e626a0838223dfaa7ff7af05992696001481e6a Mon Sep 17 00:00:00 2001 From: Zakary Timson Date: Sun, 20 Jul 2025 23:44:17 -0400 Subject: [PATCH] Update src/main.js --- src/main.js | 123 ++++++++++++++++++++++++++-------------------------- 1 file changed, 62 insertions(+), 61 deletions(-) diff --git a/src/main.js b/src/main.js index 5ed0ac3..086ba82 100644 --- a/src/main.js +++ b/src/main.js @@ -1,61 +1,62 @@ -const dns = require('dns'); -const env = require('./environment'); -const electron = require('electron'); -const fs = require('fs'); -const http = require('http'); -const https = require('https'); -const path = require('path'); - -let win; -const iconPath = path.join(__dirname, 'favicon.png'); - -// Check internet connectivity -async function online() { - return new Promise(resolve => { - dns.lookup('google.com', err => resolve(!err)); - }); -} - -// Download icon -async function downloadIcon() { - if(!await online()) return Promise.resolve(); - const iconUrl = `${env.url}/favicon.png`; - return new Promise((resolve, reject) => { - const file = fs.createWriteStream(iconPath); - const proto = env.url.startsWith('https://') ? https : http; - proto.get(iconUrl, res => { - if(res.statusCode !== 200) return; // Incase we are offline - res.pipe(file); - file.on('finish', () => file.close(resolve)); - }).on('error', reject); - }); -} - -async function createWindow() { - await downloadIcon(); - win = new electron.BrowserWindow({ - width: 1000, - height: 800, - icon: iconPath, - webPreferences: { - preload: path.join(__dirname, 'preload.js'), - contextIsolation: true, - enableRemoteModule: false, - nodeIntegration: false - } - }); - - win.setMenu(null); - electron.globalShortcut.register('Control+Shift+I', () => { - if (win) win.webContents.openDevTools(); - }); - - electron.ipcMain.on('electron-environment', (event) => event.returnValue = env); - - win.loadURL(env.url); - - win.on('closed', () => win = null); -} - -electron.app.on('ready', createWindow); -electron.app.on('activate', () => { if(win === null) createWindow(); }); +const dns = require('dns'); +const env = require('./environment'); +const electron = require('electron'); +const fs = require('fs'); +const http = require('http'); +const https = require('https'); +const path = require('path'); + +let win; +const iconPath = path.join(__dirname, 'favicon.png'); + +// Check internet connectivity +async function online() { + return new Promise(resolve => { + dns.lookup('google.com', err => resolve(!err)); + }); +} + +// Download icon +async function downloadIcon() { + if(!await online()) return Promise.resolve(); + const iconUrl = `${env.url}/favicon.png`; + return new Promise((resolve, reject) => { + const file = fs.createWriteStream(iconPath); + const proto = env.url.startsWith('https://') ? https : http; + proto.get(iconUrl, res => { + if(res.statusCode !== 200) return; // Incase we are offline + res.pipe(file); + file.on('finish', () => file.close(resolve)); + }).on('error', reject); + }); +} + +async function createWindow() { + await downloadIcon(); + win = new electron.BrowserWindow({ + width: 1000, + height: 800, + icon: iconPath, + webPreferences: { + preload: path.join(__dirname, 'preload.js'), + contextIsolation: true, + enableRemoteModule: false, + nodeIntegration: false + } + }); + + win.setMenu(null); + electron.globalShortcut.register('Control+Shift+I', () => { + if (win) win.webContents.openDevTools(); + }); + + electron.ipcMain.on('electron-environment', (event) => event.returnValue = env); + + win.loadURL(env.url); + win.setTitle(env.title); + + win.on('closed', () => win = null); +} + +electron.app.on('ready', createWindow); +electron.app.on('activate', () => { if(win === null) createWindow(); });