mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-07-30 13:41:45 +00:00
94 lines
3.1 KiB
TypeScript
94 lines
3.1 KiB
TypeScript
import type { CapacitorElectronConfig } from '@capacitor-community/electron';
|
|
import { getCapacitorElectronConfig, setupElectronDeepLinking } from '@capacitor-community/electron';
|
|
import type { MenuItemConstructorOptions } from 'electron';
|
|
import { app, MenuItem } from 'electron';
|
|
import electronIsDev from 'electron-is-dev';
|
|
import unhandled from 'electron-unhandled';
|
|
import { autoUpdater } from 'electron-updater';
|
|
import path from 'path'
|
|
import { ElectronCapacitorApp, setupContentSecurityPolicy, setupReloadWatcher } from './setup';
|
|
|
|
// Graceful handling of unhandled errors.
|
|
unhandled();
|
|
|
|
// Define our menu templates (these are optional)
|
|
const trayMenuTemplate: (MenuItemConstructorOptions | MenuItem)[] = [new MenuItem({ label: 'Quit App', role: 'quit' })];
|
|
const appMenuBarMenuTemplate: (MenuItemConstructorOptions | MenuItem)[] = [
|
|
{ role: process.platform === 'darwin' ? 'appMenu' : 'fileMenu' },
|
|
{ role: 'viewMenu' },
|
|
{ role: 'editMenu' },
|
|
];
|
|
|
|
// Get Config options from capacitor.config
|
|
const capacitorFileConfig: CapacitorElectronConfig = getCapacitorElectronConfig();
|
|
|
|
// Initialize our app. You can pass menu templates into the app here.
|
|
// const myCapacitorApp = new ElectronCapacitorApp(capacitorFileConfig);
|
|
export const myCapacitorApp = new ElectronCapacitorApp(capacitorFileConfig, trayMenuTemplate, appMenuBarMenuTemplate);
|
|
|
|
// If deeplinking is enabled then we will set it up here.
|
|
if (capacitorFileConfig.electron?.deepLinkingEnabled) {
|
|
setupElectronDeepLinking(myCapacitorApp, {
|
|
customProtocol: capacitorFileConfig.electron.deepLinkingCustomProtocol ?? 'mycapacitorapp',
|
|
});
|
|
}
|
|
|
|
// If we are in Dev mode, use the file watcher components.
|
|
if (electronIsDev) {
|
|
setupReloadWatcher(myCapacitorApp);
|
|
}
|
|
|
|
const checkForUpdates = async () => {
|
|
try {
|
|
await autoUpdater.checkForUpdatesAndNotify();
|
|
} catch (error) {
|
|
console.error("Error checking for updates:", error);
|
|
}
|
|
};
|
|
|
|
// Run Application
|
|
(async () => {
|
|
await app.whenReady();
|
|
|
|
// Set Content Security Policy
|
|
setupContentSecurityPolicy(myCapacitorApp.getCustomURLScheme());
|
|
|
|
// Initialize the app
|
|
await myCapacitorApp.init();
|
|
|
|
|
|
|
|
const win = myCapacitorApp.getMainWindow();
|
|
if (win) {
|
|
win.webContents.session.setPreloads([path.join(__dirname, 'preload.js')]); // optional if not using capacitor-managed preload
|
|
win.webContents.setWindowOpenHandler(() => ({ action: 'deny' }));
|
|
|
|
|
|
}
|
|
|
|
// Start update checks
|
|
checkForUpdates();
|
|
setInterval(checkForUpdates, 24 * 60 * 60 * 1000);
|
|
})();
|
|
|
|
|
|
// Handle when all of our windows are close (platforms have their own expectations).
|
|
app.on('window-all-closed', function () {
|
|
// On OS X it is common for applications and their menu bar
|
|
// to stay active until the user quits explicitly with Cmd + Q
|
|
if (process.platform !== 'darwin') {
|
|
app.quit();
|
|
}
|
|
});
|
|
|
|
// When the dock icon is clicked.
|
|
app.on('activate', async function () {
|
|
// On OS X it's common to re-create a window in the app when the
|
|
// dock icon is clicked and there are no other windows open.
|
|
if (myCapacitorApp.getMainWindow().isDestroyed()) {
|
|
await myCapacitorApp.init();
|
|
}
|
|
});
|
|
|
|
// Place all ipc or other electron api calls and custom functionality under this line
|