refac: prohibit downloads and disable GPU acceleration
All checks were successful
Build/release / action-release (push) Successful in 3m13s
All checks were successful
Build/release / action-release (push) Successful in 3m13s
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { dialog, BrowserWindow, ShareMenu } from "electron";
|
||||
import { dialog, BrowserWindow } from "electron";
|
||||
import { getValue, setValue } from "./store.js";
|
||||
import { ElectronBlocker } from "@ghostery/adblocker-electron";
|
||||
import prompt from "electron-prompt";
|
||||
|
||||
@@ -14,8 +14,13 @@ export function setValue(key, value) {
|
||||
export function getValueOrDefault(key, defaultValue) {
|
||||
const value = store.get(key);
|
||||
if (value === undefined) {
|
||||
store.set(key, defaultValue);
|
||||
return defaultValue;
|
||||
try {
|
||||
console.log(key)
|
||||
store.set(key, defaultValue);
|
||||
return defaultValue;
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -23,7 +28,7 @@ export function getValueOrDefault(key, defaultValue) {
|
||||
getValueOrDefault("enterprise-or-normal", "?auth=2");
|
||||
getValueOrDefault("websites-in-new-window", "false");
|
||||
getValueOrDefault("autohide-menubar", "true");
|
||||
getValueOrDefault("useragentstring", useragents.Windows);
|
||||
getValueOrDefault("useragentstring", useragents.WindowsChrome);
|
||||
getValueOrDefault("blockadsandtrackers", "false");
|
||||
getValueOrDefault("dynamicicons", "true");
|
||||
getValueOrDefault("autoupdate", "false");
|
||||
|
||||
65
app/main.js
65
app/main.js
@@ -10,7 +10,6 @@ import checkInternetConnected from "check-internet-connected";
|
||||
import domains from "./domains.json" with { type: "json" };
|
||||
import contextMenu from "electron-context-menu";
|
||||
import updaterpkg from "electron-updater";
|
||||
import ElectronDl from "electron-dl";
|
||||
import menulayout from "./config/menu.js";
|
||||
import logpkg from "electron-log";
|
||||
|
||||
@@ -26,9 +25,7 @@ console.log = _log;
|
||||
Object.assign(console, functions);
|
||||
|
||||
function createWindow() {
|
||||
//const enterpriseOrNormal = getValue("enterprise-or-normal");
|
||||
//const custompage = getValue("custompage");
|
||||
const partition = partition = "persist:work";
|
||||
const partition = "persist:work";
|
||||
|
||||
const win = new BrowserWindow({
|
||||
width: Math.round(getScreenWidth() * getValue("windowWidth")),
|
||||
@@ -42,6 +39,11 @@ function createWindow() {
|
||||
},
|
||||
});
|
||||
|
||||
win.webContents.session.on('will-download', (event, item) => {
|
||||
event.preventDefault(); // Blocks the download entirely
|
||||
console.log(`Blocked download attempt: ${item.getURL()}`);
|
||||
});
|
||||
|
||||
win.setAutoHideMenuBar(getValue("autohide-menubar") === "true");
|
||||
|
||||
const splash = new BrowserWindow({
|
||||
@@ -52,6 +54,7 @@ function createWindow() {
|
||||
icon: join(__dirname, "/assets/icons/png/1024x1024.png"),
|
||||
});
|
||||
|
||||
// Careful, this loading animation relies fully on that page.
|
||||
splash.loadURL(`https://agam778.github.io/MS-365-Electron/loading`);
|
||||
|
||||
//The following line is regarding the starting page.
|
||||
@@ -65,8 +68,7 @@ function createWindow() {
|
||||
win.show();
|
||||
if (getValue("blockadsandtrackers") === "true") {
|
||||
ElectronBlocker.fromPrebuiltAdsAndTracking(fetch).then((blocker) => {
|
||||
// Only enable if not already enabled
|
||||
try {
|
||||
try { // Only enable if not already enabled
|
||||
blocker.enableBlockingInSession(win.webContents.session);
|
||||
} catch (e) {
|
||||
console.warn("Adblocker already enabled for this session");
|
||||
@@ -76,45 +78,6 @@ function createWindow() {
|
||||
});
|
||||
}
|
||||
|
||||
ElectronDl({
|
||||
dlPath: "./downloads",
|
||||
onStarted: (item) => {
|
||||
dialog.showMessageBox({
|
||||
type: "info",
|
||||
title: "Downloading File",
|
||||
message: `Downloading "${item.getFilename()}" to "${item.getSavePath()}"`,
|
||||
buttons: ["OK"],
|
||||
});
|
||||
},
|
||||
onCompleted: () => {
|
||||
dialog.showMessageBox({
|
||||
type: "info",
|
||||
title: "Download Completed",
|
||||
message: `Downloading Completed! Please check your "Downloads" folder.`,
|
||||
buttons: ["OK"],
|
||||
});
|
||||
},
|
||||
onError: (item) => {
|
||||
dialog.showMessageBox({
|
||||
type: "error",
|
||||
title: "Download failed",
|
||||
message: `Downloading "${item.getFilename()}" failed :(`,
|
||||
buttons: ["OK"],
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
contextMenu({
|
||||
showInspectElement: false,
|
||||
showServices: false,
|
||||
});
|
||||
|
||||
Menu.setApplicationMenu(Menu.buildFromTemplate(menulayout));
|
||||
|
||||
app.on("ready", () => {
|
||||
createWindow();
|
||||
});
|
||||
|
||||
app.on("web-contents-created", (event, contents) => {
|
||||
contents.setWindowOpenHandler(({ url }) => {
|
||||
const urlObject = new URL(url);
|
||||
@@ -383,3 +346,15 @@ app.on("ready", function () {
|
||||
autoUpdater.checkForUpdatesAndNotify();
|
||||
}
|
||||
});
|
||||
|
||||
contextMenu({
|
||||
showInspectElement: false,
|
||||
showServices: false,
|
||||
});
|
||||
|
||||
Menu.setApplicationMenu(Menu.buildFromTemplate(menulayout));
|
||||
|
||||
app.disableHardwareAcceleration();
|
||||
app.on("ready", () => {
|
||||
createWindow();
|
||||
});
|
||||
@@ -56,7 +56,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"start": "electron .",
|
||||
"build": "electron-builder",
|
||||
"build": "electron-builder --publish never",
|
||||
"pack": "electron-builder --dir",
|
||||
"dist": "electron-builder"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user