Wire up setContentProtectionEnable for Windows & macOS (#2379)
This commit is contained in:
@@ -485,6 +485,8 @@ app.on("ready", async () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
global.mainWindow.setContentProtection(store.get("enableContentProtection"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.debug("Ensuring storage is ready");
|
console.debug("Ensuring storage is ready");
|
||||||
if (!(await store.prepareSafeStorage(global.mainWindow.webContents.session))) return;
|
if (!(await store.prepareSafeStorage(global.mainWindow.webContents.session))) return;
|
||||||
|
|||||||
-13
@@ -9,7 +9,6 @@ import { app, autoUpdater, desktopCapturer, ipcMain, powerSaveBlocker, TouchBar,
|
|||||||
|
|
||||||
import IpcMainEvent = Electron.IpcMainEvent;
|
import IpcMainEvent = Electron.IpcMainEvent;
|
||||||
import { randomArray } from "./utils.js";
|
import { randomArray } from "./utils.js";
|
||||||
import { Settings } from "./settings.js";
|
|
||||||
import { getDisplayMediaCallback, setDisplayMediaCallback } from "./displayMediaCallback.js";
|
import { getDisplayMediaCallback, setDisplayMediaCallback } from "./displayMediaCallback.js";
|
||||||
import Store, { clearDataAndRelaunch } from "./store.js";
|
import Store, { clearDataAndRelaunch } from "./store.js";
|
||||||
|
|
||||||
@@ -69,18 +68,6 @@ ipcMain.on("ipcCall", async function (_ev: IpcMainEvent, payload) {
|
|||||||
case "getUpdateFeedUrl":
|
case "getUpdateFeedUrl":
|
||||||
ret = autoUpdater.getFeedURL();
|
ret = autoUpdater.getFeedURL();
|
||||||
break;
|
break;
|
||||||
case "getSettingValue": {
|
|
||||||
const [settingName] = args;
|
|
||||||
const setting = Settings[settingName];
|
|
||||||
ret = await setting.read();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "setSettingValue": {
|
|
||||||
const [settingName, value] = args;
|
|
||||||
const setting = Settings[settingName];
|
|
||||||
await setting.write(value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "setLanguage":
|
case "setLanguage":
|
||||||
global.appLocalization.setAppLocale(args[0]);
|
global.appLocalization.setAppLocale(args[0]);
|
||||||
break;
|
break;
|
||||||
|
|||||||
+11
-2
@@ -54,11 +54,20 @@ contextBridge.exposeInMainWorld("electron", {
|
|||||||
protocol: string;
|
protocol: string;
|
||||||
sessionId: string;
|
sessionId: string;
|
||||||
config: IConfigOptions;
|
config: IConfigOptions;
|
||||||
|
supportedSettings: Record<string, boolean>;
|
||||||
}> {
|
}> {
|
||||||
const [{ protocol, sessionId }, config] = await Promise.all([
|
const [{ protocol, sessionId }, config, supportedSettings] = await Promise.all([
|
||||||
ipcRenderer.invoke("getProtocol"),
|
ipcRenderer.invoke("getProtocol"),
|
||||||
ipcRenderer.invoke("getConfig"),
|
ipcRenderer.invoke("getConfig"),
|
||||||
|
ipcRenderer.invoke("getSupportedSettings"),
|
||||||
]);
|
]);
|
||||||
return { protocol, sessionId, config };
|
return { protocol, sessionId, config, supportedSettings };
|
||||||
|
},
|
||||||
|
|
||||||
|
async setSettingValue(settingName: string, value: any): Promise<void> {
|
||||||
|
return ipcRenderer.invoke("setSettingValue", settingName, value);
|
||||||
|
},
|
||||||
|
async getSettingValue(settingName: string): Promise<any> {
|
||||||
|
return ipcRenderer.invoke("getSettingValue", settingName);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
+51
-3
@@ -5,15 +5,18 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
|||||||
Please see LICENSE files in the repository root for full details.
|
Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { ipcMain } from "electron";
|
||||||
|
|
||||||
import * as tray from "./tray.js";
|
import * as tray from "./tray.js";
|
||||||
import Store from "./store.js";
|
import Store from "./store.js";
|
||||||
|
|
||||||
interface Setting {
|
interface Setting {
|
||||||
read(): Promise<any>;
|
read(): Promise<any>;
|
||||||
write(value: any): Promise<void>;
|
write(value: any): Promise<void>;
|
||||||
|
supported?(): boolean; // if undefined, the setting is always supported
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Settings: Record<string, Setting> = {
|
const Settings: Record<string, Setting> = {
|
||||||
"Electron.autoLaunch": {
|
"Electron.autoLaunch": {
|
||||||
async read(): Promise<any> {
|
async read(): Promise<any> {
|
||||||
return global.launcher.isEnabled();
|
return global.launcher.isEnabled();
|
||||||
@@ -35,7 +38,10 @@ export const Settings: Record<string, Setting> = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Electron.alwaysShowMenuBar": {
|
"Electron.alwaysShowMenuBar": {
|
||||||
// not supported on macOS
|
// This isn't relevant on Mac as Menu bars don't live in the app window
|
||||||
|
supported(): boolean {
|
||||||
|
return process.platform !== "darwin";
|
||||||
|
},
|
||||||
async read(): Promise<any> {
|
async read(): Promise<any> {
|
||||||
return !global.mainWindow!.autoHideMenuBar;
|
return !global.mainWindow!.autoHideMenuBar;
|
||||||
},
|
},
|
||||||
@@ -46,7 +52,10 @@ export const Settings: Record<string, Setting> = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Electron.showTrayIcon": {
|
"Electron.showTrayIcon": {
|
||||||
// not supported on macOS
|
// Things other than Mac support tray icons
|
||||||
|
supported(): boolean {
|
||||||
|
return process.platform !== "darwin";
|
||||||
|
},
|
||||||
async read(): Promise<any> {
|
async read(): Promise<any> {
|
||||||
return tray.hasTray();
|
return tray.hasTray();
|
||||||
},
|
},
|
||||||
@@ -68,4 +77,43 @@ export const Settings: Record<string, Setting> = {
|
|||||||
Store.instance?.set("disableHardwareAcceleration", !value);
|
Store.instance?.set("disableHardwareAcceleration", !value);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"Electron.enableContentProtection": {
|
||||||
|
// Unsupported on Linux https://www.electronjs.org/docs/latest/api/browser-window#winsetcontentprotectionenable-macos-windows
|
||||||
|
// Broken on macOS https://github.com/electron/electron/issues/19880
|
||||||
|
supported(): boolean {
|
||||||
|
return process.platform === "win32";
|
||||||
|
},
|
||||||
|
async read(): Promise<any> {
|
||||||
|
return Store.instance?.get("enableContentProtection");
|
||||||
|
},
|
||||||
|
async write(value: any): Promise<void> {
|
||||||
|
global.mainWindow?.setContentProtection(value);
|
||||||
|
Store.instance?.set("enableContentProtection", value);
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ipcMain.handle("getSupportedSettings", async () => {
|
||||||
|
const supportedSettings: Record<string, boolean> = {};
|
||||||
|
for (const [key, setting] of Object.entries(Settings)) {
|
||||||
|
supportedSettings[key] = setting.supported?.() ?? true;
|
||||||
|
}
|
||||||
|
return supportedSettings;
|
||||||
|
});
|
||||||
|
ipcMain.handle("setSettingValue", async (_ev, settingName: string, value: any) => {
|
||||||
|
const setting = Settings[settingName];
|
||||||
|
if (!setting) {
|
||||||
|
throw new Error(`Unknown setting: ${settingName}`);
|
||||||
|
}
|
||||||
|
console.debug(`Writing setting value for: ${settingName} = ${value}`);
|
||||||
|
await setting.write(value);
|
||||||
|
});
|
||||||
|
ipcMain.handle("getSettingValue", async (_ev, settingName: string) => {
|
||||||
|
const setting = Settings[settingName];
|
||||||
|
if (!setting) {
|
||||||
|
throw new Error(`Unknown setting: ${settingName}`);
|
||||||
|
}
|
||||||
|
const value = await setting.read();
|
||||||
|
console.debug(`Reading setting value for: ${settingName} = ${value}`);
|
||||||
|
return value;
|
||||||
|
});
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ interface StoreData {
|
|||||||
autoHideMenuBar: boolean;
|
autoHideMenuBar: boolean;
|
||||||
locale?: string | string[];
|
locale?: string | string[];
|
||||||
disableHardwareAcceleration: boolean;
|
disableHardwareAcceleration: boolean;
|
||||||
|
enableContentProtection: boolean;
|
||||||
safeStorage?: Record<string, string>;
|
safeStorage?: Record<string, string>;
|
||||||
/** the safeStorage backend used for the safeStorage data as written */
|
/** the safeStorage backend used for the safeStorage data as written */
|
||||||
safeStorageBackend?: SafeStorageBackend;
|
safeStorageBackend?: SafeStorageBackend;
|
||||||
@@ -217,6 +218,10 @@ class Store extends ElectronStore<StoreData> {
|
|||||||
type: "boolean",
|
type: "boolean",
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
enableContentProtection: {
|
||||||
|
type: "boolean",
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
safeStorage: {
|
safeStorage: {
|
||||||
type: "object",
|
type: "object",
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user