Update src/main.js
This commit is contained in:
123
src/main.js
123
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(); });
|
||||
|
||||
Reference in New Issue
Block a user