115 lines
2.9 KiB
JavaScript
115 lines
2.9 KiB
JavaScript
const { app, BrowserWindow, Menu, ipcMain, session } = require('electron/main')
|
|
const path = require('node:path')
|
|
//const { session } = require('electron')
|
|
const {machineId, machineIdSync} = require('node-machine-id')
|
|
|
|
// run this as early in the main process as possible
|
|
if (require('electron-squirrel-startup')) app.quit();
|
|
|
|
const filter = {
|
|
urls: ['https://*.manage.backone.cloud/*']
|
|
}
|
|
let device_id = machineIdSync()
|
|
|
|
Menu.setApplicationMenu(null);
|
|
|
|
const createWindow = () => {
|
|
const win = new BrowserWindow({
|
|
width: 1440,
|
|
height: 900,
|
|
title: 'Client',
|
|
//titleBarStyle: 'hidden',
|
|
tabbingIdentifier: 'clientTabs',
|
|
webPreferences: {
|
|
preload: path.join(__dirname, 'preload.js')
|
|
},
|
|
//...(process.platform !== 'darwin' ? { titleBarOverlay: true } : {})
|
|
})
|
|
//win.setMenu(null)
|
|
//win.setTitle(`App Name - Version ${app.getVersion()}`);
|
|
//win.setTitle(`Client ${app.getVersion()}`);
|
|
|
|
|
|
/*
|
|
win.on('app-command', (e, cmd) => {
|
|
if (cmd === 'browser-backward') {
|
|
if (win.webContents.canGoBack()) {
|
|
win.webContents.goBack();
|
|
}
|
|
} else if (cmd === 'browser-forward') {
|
|
if (win.webContents.canGoForward()) {
|
|
win.webContents.goForward();
|
|
}
|
|
}
|
|
});
|
|
*/
|
|
|
|
|
|
session.defaultSession.webRequest.onBeforeSendHeaders(filter, (details, callback) => {
|
|
details.requestHeaders['User-Agent'] = 'BackOne-Client';
|
|
details.requestHeaders['Device-Id'] = device_id;
|
|
callback({ requestHeaders: details.requestHeaders })
|
|
})
|
|
|
|
//win.loadURL('https://nexus.manage.backone.cloud/', {userAgent: 'BackOne-Admin'})
|
|
//win.loadFile('index.html', {userAgent: 'BackOne-Admin'})
|
|
win.loadFile('index.html')
|
|
|
|
// Handle the 'nav:back' event from the renderer process
|
|
/*
|
|
ipcMain.handle('nav:back', () => {
|
|
if (mainWindow.webContents.canGoBack()) {
|
|
mainWindow.webContents.goBack();
|
|
}
|
|
});
|
|
*/
|
|
//win.loadURL('https://nexus.manage.backone.cloud/')
|
|
//const ses = win.webContents.session
|
|
//ses.clearCache()
|
|
}
|
|
|
|
app.on('ready', async () => {
|
|
// Clear the default session's cache before the window is ready to load content
|
|
try {
|
|
await session.defaultSession.clearCache();
|
|
console.log('Cache cleared successfully on app start.');
|
|
} catch (err) {
|
|
console.error('Failed to clear cache:', err);
|
|
}
|
|
|
|
createWindow();
|
|
|
|
|
|
// Quit app when all windows are closed, except on macOS (common pattern)
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') {
|
|
app.quit();
|
|
}
|
|
});
|
|
|
|
app.on('activate', () => {
|
|
// Recreate a window in the app when the dock icon is clicked (macOS)
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
createWindow();
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
app.whenReady().then(() => {
|
|
createWindow()
|
|
|
|
app.on('activate', () => {
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
|
createWindow()
|
|
}
|
|
})
|
|
})
|
|
|
|
app.on('window-all-closed', () => {
|
|
if (process.platform !== 'darwin') app.quit()
|
|
})
|
|
*/
|