Update src/main.js
Some checks failed
Build Electron / Build Electron (push) Has been cancelled
Build Electron / Build Dockerfile (push) Has been cancelled

This commit is contained in:
2025-07-20 23:44:17 -04:00
parent 7596bdad6a
commit 0e626a0838

View File

@@ -1,61 +1,62 @@
const dns = require('dns'); const dns = require('dns');
const env = require('./environment'); const env = require('./environment');
const electron = require('electron'); const electron = require('electron');
const fs = require('fs'); const fs = require('fs');
const http = require('http'); const http = require('http');
const https = require('https'); const https = require('https');
const path = require('path'); const path = require('path');
let win; let win;
const iconPath = path.join(__dirname, 'favicon.png'); const iconPath = path.join(__dirname, 'favicon.png');
// Check internet connectivity // Check internet connectivity
async function online() { async function online() {
return new Promise(resolve => { return new Promise(resolve => {
dns.lookup('google.com', err => resolve(!err)); dns.lookup('google.com', err => resolve(!err));
}); });
} }
// Download icon // Download icon
async function downloadIcon() { async function downloadIcon() {
if(!await online()) return Promise.resolve(); if(!await online()) return Promise.resolve();
const iconUrl = `${env.url}/favicon.png`; const iconUrl = `${env.url}/favicon.png`;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const file = fs.createWriteStream(iconPath); const file = fs.createWriteStream(iconPath);
const proto = env.url.startsWith('https://') ? https : http; const proto = env.url.startsWith('https://') ? https : http;
proto.get(iconUrl, res => { proto.get(iconUrl, res => {
if(res.statusCode !== 200) return; // Incase we are offline if(res.statusCode !== 200) return; // Incase we are offline
res.pipe(file); res.pipe(file);
file.on('finish', () => file.close(resolve)); file.on('finish', () => file.close(resolve));
}).on('error', reject); }).on('error', reject);
}); });
} }
async function createWindow() { async function createWindow() {
await downloadIcon(); await downloadIcon();
win = new electron.BrowserWindow({ win = new electron.BrowserWindow({
width: 1000, width: 1000,
height: 800, height: 800,
icon: iconPath, icon: iconPath,
webPreferences: { webPreferences: {
preload: path.join(__dirname, 'preload.js'), preload: path.join(__dirname, 'preload.js'),
contextIsolation: true, contextIsolation: true,
enableRemoteModule: false, enableRemoteModule: false,
nodeIntegration: false nodeIntegration: false
} }
}); });
win.setMenu(null); win.setMenu(null);
electron.globalShortcut.register('Control+Shift+I', () => { electron.globalShortcut.register('Control+Shift+I', () => {
if (win) win.webContents.openDevTools(); if (win) win.webContents.openDevTools();
}); });
electron.ipcMain.on('electron-environment', (event) => event.returnValue = env); electron.ipcMain.on('electron-environment', (event) => event.returnValue = env);
win.loadURL(env.url); win.loadURL(env.url);
win.setTitle(env.title);
win.on('closed', () => win = null);
} win.on('closed', () => win = null);
}
electron.app.on('ready', createWindow);
electron.app.on('activate', () => { if(win === null) createWindow(); }); electron.app.on('ready', createWindow);
electron.app.on('activate', () => { if(win === null) createWindow(); });