From 6d082826deb5fe0f8fa75c8c5a4beb316ce129e4 Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Sat, 1 Jul 2023 13:24:23 +0100 Subject: [PATCH] Style changes for main and preload --- main.cjs | 33 +++++++++++++-------------------- preload.cjs | 9 ++++----- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/main.cjs b/main.cjs index 88a0ac5f..7ae70cf4 100644 --- a/main.cjs +++ b/main.cjs @@ -1,11 +1,11 @@ // Modules to control application life and create native browser window const { app, dialog, ipcMain, BrowserWindow } = require('electron'); const path = require('path'); -const { autoUpdater } = require("electron-updater"); - -app.commandLine.appendSwitch("enable-experimental-web-platform-features"); - +const { autoUpdater } = require('electron-updater'); const contextMenu = require('electron-context-menu'); + +app.commandLine.appendSwitch('enable-experimental-web-platform-features'); + contextMenu({ labels: { cut: 'Cut', @@ -33,20 +33,9 @@ contextMenu({ inspect: true }); -// This is used to set capabilities of the app: protocol in onready event below -// protocol.registerSchemesAsPrivileged([{ -// scheme: 'app', -// privileges: { -// standard: true, -// secure: true, -// allowServiceWorkers: true, -// supportFetchAPI: true -// } -// }]); - let mainWindow; -function createWindow() { +function createWindow () { // Create the browser window. mainWindow = new BrowserWindow({ // titleBarStyle: 'hidden', @@ -56,6 +45,12 @@ function createWindow() { minHeight: 480, autoHideMenuBar: true, icon: path.join(__dirname, 'www/img/icons/kiwix-64.png'), + // titleBarStyle: 'hidden', + // titleBarOverlay: { + // color: '#000000', + // symbolColor: '#ffffff', + // height: 16 + // }, webPreferences: { preload: path.join(__dirname, 'preload.cjs'), nativeWindowOpen: true, @@ -69,7 +64,7 @@ function createWindow() { mainWindow.loadFile('www/index.html'); } -function registerListeners() { +function registerListeners () { ipcMain.on('file-dialog', function (event) { dialog.showOpenDialog(mainWindow, { filters: [ @@ -109,7 +104,7 @@ function registerListeners() { console.log('Download is paused'); mainWindow.webContents.send('dl-received', 'paused'); } else { - let newReceivedBytes = item.getReceivedBytes(); + const newReceivedBytes = item.getReceivedBytes(); if (newReceivedBytes - receivedBytes < 250000) return; receivedBytes = newReceivedBytes; mainWindow.webContents.send('dl-received', receivedBytes); @@ -153,7 +148,6 @@ app.whenReady().then(() => { createWindow(); registerListeners(); - var appName = app.getName(); console.log('App name: ' + appName); @@ -177,7 +171,6 @@ app.whenReady().then(() => { // dock icon is clicked and there are no other windows open. if (BrowserWindow.getAllWindows().length === 0) createWindow(); }); - }); // Quit when all windows are closed. diff --git a/preload.cjs b/preload.cjs index 7382ac55..c78fd1b5 100644 --- a/preload.cjs +++ b/preload.cjs @@ -13,14 +13,14 @@ console.log('Window location: ' + window.location.pathname + '\nStore publisher const { ipcRenderer, contextBridge } = require('electron'); const { open, read, close, stat, readdir } = require('fs'); -console.log("Inserting required Electron functions into DOM..."); +console.log('Inserting required Electron functions into DOM...'); // DEV: FOR ELECTRON ^12 DO IT THIS WAY: contextBridge.exposeInMainWorld('fs', { - open: open, + open: open, read: read, readdir: readdir, - close: close, + close: close, stat: stat }); // Exposed events and Event callback for electronAPI (you can add events to listen to, so long as main.js sends a message with name of the event) @@ -50,7 +50,7 @@ contextBridge.exposeInMainWorld('dialog', { callback(data); }); } - }); +}); // window.Buffer = Buffer; @@ -59,4 +59,3 @@ contextBridge.exposeInMainWorld('dialog', { // win.session.cookies.get({}, (error, cookies) => { // console.log(cookies); // }); -