diff --git a/src/ElectronNET.Host/api/app.ts b/src/ElectronNET.Host/api/app.ts index d93c41d..942b9c6 100644 --- a/src/ElectronNET.Host/api/app.ts +++ b/src/ElectronNET.Host/api/app.ts @@ -1,313 +1,338 @@ -import { RelaunchOptions, LoginItemSettingsOptions, Settings, AboutPanelOptionsOptions } from "electron"; -import { Socket } from "net"; +import type { Socket } from "net"; +import { + RelaunchOptions, + LoginItemSettingsOptions, + Settings, + AboutPanelOptionsOptions, +} from "electron"; + +let isQuitWindowAllClosed = true; +let electronSocket: Socket; +let appWindowAllClosedEventId: string; -let isQuitWindowAllClosed = true, electronSocket; -let appWindowAllClosedEventId; export = (socket: Socket, app: Electron.App) => { - electronSocket = socket; + electronSocket = socket; - // By default, quit when all windows are closed - app.on('window-all-closed', () => { - // On macOS it is common for applications and their menu bar - // to stay active until the user quits explicitly with Cmd + Q - if (process.platform !== 'darwin' && isQuitWindowAllClosed) { - app.quit(); - } else if (appWindowAllClosedEventId) { - // If the user is on macOS - // - OR - - // If the user has indicated NOT to quit when all windows are closed, - // emit the event. - electronSocket.emit('app-window-all-closed' + appWindowAllClosedEventId); - } + // By default, quit when all windows are closed + app.on("window-all-closed", () => { + // On macOS it is common for applications and their menu bar + // to stay active until the user quits explicitly with Cmd + Q + if (process.platform !== "darwin" && isQuitWindowAllClosed) { + app.quit(); + } else if (appWindowAllClosedEventId) { + // If the user is on macOS + // - OR - + // If the user has indicated NOT to quit when all windows are closed, + // emit the event. + electronSocket.emit("app-window-all-closed" + appWindowAllClosedEventId); + } + }); + + socket.on("quit-app-window-all-closed", (quit) => { + isQuitWindowAllClosed = quit; + }); + + socket.on("register-app-window-all-closed", (id) => { + appWindowAllClosedEventId = id; + }); + + socket.on("register-app-before-quit", (id) => { + app.on("before-quit", (event) => { + event.preventDefault(); + + electronSocket.emit("app-before-quit" + id); }); + }); - socket.on('quit-app-window-all-closed', (quit) => { - isQuitWindowAllClosed = quit; + socket.on("register-app-will-quit", (id) => { + app.on("will-quit", (event) => { + event.preventDefault(); + + electronSocket.emit("app-will-quit" + id); }); + }); - socket.on('register-app-window-all-closed', (id) => { - appWindowAllClosedEventId = id; + socket.on("register-app-browser-window-blur", (id) => { + app.on("browser-window-blur", () => { + electronSocket.emit("app-browser-window-blur" + id); }); + }); - socket.on('register-app-before-quit', (id) => { - app.on('before-quit', (event) => { - event.preventDefault(); - - electronSocket.emit('app-before-quit' + id); - }); + socket.on("register-app-browser-window-focus", (id) => { + app.on("browser-window-focus", () => { + electronSocket.emit("app-browser-window-focus" + id); }); + }); - socket.on('register-app-will-quit', (id) => { - app.on('will-quit', (event) => { - event.preventDefault(); - - electronSocket.emit('app-will-quit' + id); - }); + socket.on("register-app-browser-window-created", (id) => { + app.on("browser-window-created", () => { + electronSocket.emit("app-browser-window-created" + id); }); + }); - socket.on('register-app-browser-window-blur', (id) => { - app.on('browser-window-blur', () => { - electronSocket.emit('app-browser-window-blur' + id); - }); + socket.on("register-app-web-contents-created", (id) => { + app.on("web-contents-created", () => { + electronSocket.emit("app-web-contents-created" + id); }); + }); - socket.on('register-app-browser-window-focus', (id) => { - app.on('browser-window-focus', () => { - electronSocket.emit('app-browser-window-focus' + id); - }); + socket.on("register-app-accessibility-support-changed", (id) => { + app.on( + "accessibility-support-changed", + (event, accessibilitySupportEnabled) => { + electronSocket.emit( + "app-accessibility-support-changed" + id, + accessibilitySupportEnabled, + ); + }, + ); + }); + + socket.on("appQuit", () => { + app.quit(); + }); + + socket.on("appExit", (exitCode = 0) => { + app.exit(exitCode); + }); + + socket.on("appRelaunch", (options) => { + app.relaunch(options as RelaunchOptions); + }); + + socket.on("appFocus", (options) => { + app.focus(options); + }); + + socket.on("appHide", () => { + app.hide(); + }); + + socket.on("appShow", () => { + app.show(); + }); + + socket.on("appGetAppPath", () => { + const path = app.getAppPath(); + electronSocket.emit("appGetAppPathCompleted", path); + }); + + socket.on("appSetAppLogsPath", (path) => { + app.setAppLogsPath(path); + }); + + socket.on("appGetPath", (name) => { + const path = app.getPath(name); + electronSocket.emit("appGetPathCompleted", path); + }); + + socket.on("appGetFileIcon", async (path, options) => { + let error = {}; + + if (options) { + const nativeImage = await app + .getFileIcon(path, options) + .catch((errorFileIcon) => (error = errorFileIcon)); + + electronSocket.emit("appGetFileIconCompleted", [error, nativeImage]); + } else { + const nativeImage = await app + .getFileIcon(path) + .catch((errorFileIcon) => (error = errorFileIcon)); + + electronSocket.emit("appGetFileIconCompleted", [error, nativeImage]); + } + }); + + socket.on("appSetPath", (name, path) => { + app.setPath(name, path); + }); + + socket.on("appGetVersion", () => { + const version = app.getVersion(); + electronSocket.emit("appGetVersionCompleted", version); + }); + + socket.on("appGetName", () => { + electronSocket.emit("appGetNameCompleted", app.name); + }); + + socket.on("appSetName", (name) => { + app.name = name; + }); + + socket.on("appGetLocale", () => { + const locale = app.getLocale(); + electronSocket.emit("appGetLocaleCompleted", locale); + }); + + socket.on("appAddRecentDocument", (path) => { + app.addRecentDocument(path); + }); + + socket.on("appClearRecentDocuments", () => { + app.clearRecentDocuments(); + }); + + socket.on("appSetAsDefaultProtocolClient", (protocol, path, args) => { + const success = app.setAsDefaultProtocolClient(protocol, path, args); + electronSocket.emit("appSetAsDefaultProtocolClientCompleted", success); + }); + + socket.on("appRemoveAsDefaultProtocolClient", (protocol, path, args) => { + const success = app.removeAsDefaultProtocolClient(protocol, path, args); + electronSocket.emit("appRemoveAsDefaultProtocolClientCompleted", success); + }); + + socket.on("appIsDefaultProtocolClient", (protocol, path, args) => { + const success = app.isDefaultProtocolClient(protocol, path, args); + electronSocket.emit("appIsDefaultProtocolClientCompleted", success); + }); + + socket.on("appSetUserTasks", (tasks) => { + const success = app.setUserTasks(tasks); + electronSocket.emit("appSetUserTasksCompleted", success); + }); + + socket.on("appGetJumpListSettings", () => { + const jumpListSettings = app.getJumpListSettings(); + electronSocket.emit("appGetJumpListSettingsCompleted", jumpListSettings); + }); + + socket.on("appSetJumpList", (categories) => { + app.setJumpList(categories); + }); + + socket.on("appRequestSingleInstanceLock", () => { + const success = app.requestSingleInstanceLock(); + electronSocket.emit("appRequestSingleInstanceLockCompleted", success); + + app.on("second-instance", (event, args = [], workingDirectory = "") => { + electronSocket.emit("secondInstance", [args, workingDirectory]); }); + }); - socket.on('register-app-browser-window-created', (id) => { - app.on('browser-window-created', () => { - electronSocket.emit('app-browser-window-created' + id); - }); + socket.on("appHasSingleInstanceLock", () => { + const hasLock = app.hasSingleInstanceLock(); + + electronSocket.emit("appHasSingleInstanceLockCompleted", hasLock); + }); + + socket.on("appReleaseSingleInstanceLock", () => { + app.releaseSingleInstanceLock(); + }); + + socket.on("appSetUserActivity", (type, userInfo, webpageUrl) => { + app.setUserActivity(type, userInfo, webpageUrl); + }); + + socket.on("appGetCurrentActivityType", () => { + const activityType = app.getCurrentActivityType(); + electronSocket.emit("appGetCurrentActivityTypeCompleted", activityType); + }); + + socket.on("appInvalidateCurrentActivity", () => { + app.invalidateCurrentActivity(); + }); + + socket.on("appResignCurrentActivity", () => { + app.resignCurrentActivity(); + }); + + socket.on("appSetAppUserModelId", (id) => { + app.setAppUserModelId(id); + }); + + socket.on("appImportCertificate", (options) => { + app.importCertificate(options, (result) => { + electronSocket.emit("appImportCertificateCompleted", result); }); + }); - socket.on('register-app-web-contents-created', (id) => { - app.on('web-contents-created', () => { - electronSocket.emit('app-web-contents-created' + id); - }); + socket.on("appGetAppMetrics", () => { + const processMetrics = app.getAppMetrics(); + electronSocket.emit("appGetAppMetricsCompleted", processMetrics); + }); + + socket.on("appGetGpuFeatureStatus", () => { + const gpuFeatureStatus = app.getGPUFeatureStatus(); + electronSocket.emit("appGetGpuFeatureStatusCompleted", gpuFeatureStatus); + }); + + socket.on("appSetBadgeCount", (count) => { + const success = app.setBadgeCount(count); + electronSocket.emit("appSetBadgeCountCompleted", success); + }); + + socket.on("appGetBadgeCount", () => { + const count = app.getBadgeCount(); + electronSocket.emit("appGetBadgeCountCompleted", count); + }); + + socket.on("appIsUnityRunning", () => { + const isUnityRunning = app.isUnityRunning(); + electronSocket.emit("appIsUnityRunningCompleted", isUnityRunning); + }); + + socket.on("appGetLoginItemSettings", (options) => { + const loginItemSettings = app.getLoginItemSettings( + options as LoginItemSettingsOptions, + ); + electronSocket.emit("appGetLoginItemSettingsCompleted", loginItemSettings); + }); + + socket.on("appSetLoginItemSettings", (settings) => { + app.setLoginItemSettings(settings as Settings); + }); + + socket.on("appIsAccessibilitySupportEnabled", () => { + const isAccessibilitySupportEnabled = app.isAccessibilitySupportEnabled(); + electronSocket.emit( + "appIsAccessibilitySupportEnabledCompleted", + isAccessibilitySupportEnabled, + ); + }); + + socket.on("appSetAccessibilitySupportEnabled", (enabled) => { + app.setAccessibilitySupportEnabled(enabled); + }); + + socket.on("appShowAboutPanel", () => { + app.showAboutPanel(); + }); + + socket.on("appSetAboutPanelOptions", (options) => { + app.setAboutPanelOptions(options as AboutPanelOptionsOptions); + }); + + socket.on("appGetUserAgentFallback", () => { + electronSocket.emit( + "appGetUserAgentFallbackCompleted", + app.userAgentFallback, + ); + }); + + socket.on("appSetUserAgentFallback", (userAgent) => { + app.userAgentFallback = userAgent; + }); + + socket.on("register-app-on-event", (eventName, listenerName) => { + app.on(eventName, (...args) => { + if (args.length > 1) { + electronSocket.emit(listenerName, args[1]); + } else { + electronSocket.emit(listenerName); + } }); + }); - socket.on('register-app-accessibility-support-changed', (id) => { - app.on('accessibility-support-changed', (event, accessibilitySupportEnabled) => { - electronSocket.emit('app-accessibility-support-changed' + id, accessibilitySupportEnabled); - }); - }); - - socket.on('appQuit', () => { - app.quit(); - }); - - socket.on('appExit', (exitCode = 0) => { - app.exit(exitCode); - }); - - socket.on('appRelaunch', (options) => { - app.relaunch(options as RelaunchOptions); - }); - - socket.on('appFocus', (options) => { - app.focus(options); - }); - - socket.on('appHide', () => { - app.hide(); - }); - - socket.on('appShow', () => { - app.show(); - }); - - socket.on('appGetAppPath', () => { - const path = app.getAppPath(); - electronSocket.emit('appGetAppPathCompleted', path); - }); - - socket.on('appSetAppLogsPath', (path) => { - app.setAppLogsPath(path); - }); - - socket.on('appGetPath', (name) => { - const path = app.getPath(name); - electronSocket.emit('appGetPathCompleted', path); - }); - - socket.on('appGetFileIcon', async (path, options) => { - let error = {}; - - if (options) { - const nativeImage = await app.getFileIcon(path, options).catch((errorFileIcon) => error = errorFileIcon); - - electronSocket.emit('appGetFileIconCompleted', [error, nativeImage]); - } else { - const nativeImage = await app.getFileIcon(path).catch((errorFileIcon) => error = errorFileIcon); - - electronSocket.emit('appGetFileIconCompleted', [error, nativeImage]); - } - }); - - socket.on('appSetPath', (name, path) => { - app.setPath(name, path); - }); - - socket.on('appGetVersion', () => { - const version = app.getVersion(); - electronSocket.emit('appGetVersionCompleted', version); - }); - - socket.on('appGetName', () => { - electronSocket.emit('appGetNameCompleted', app.name); - }); - - socket.on('appSetName', (name) => { - app.name = name; - }); - - socket.on('appGetLocale', () => { - const locale = app.getLocale(); - electronSocket.emit('appGetLocaleCompleted', locale); - }); - - socket.on('appAddRecentDocument', (path) => { - app.addRecentDocument(path); - }); - - socket.on('appClearRecentDocuments', () => { - app.clearRecentDocuments(); - }); - - socket.on('appSetAsDefaultProtocolClient', (protocol, path, args) => { - const success = app.setAsDefaultProtocolClient(protocol, path, args); - electronSocket.emit('appSetAsDefaultProtocolClientCompleted', success); - }); - - socket.on('appRemoveAsDefaultProtocolClient', (protocol, path, args) => { - const success = app.removeAsDefaultProtocolClient(protocol, path, args); - electronSocket.emit('appRemoveAsDefaultProtocolClientCompleted', success); - }); - - socket.on('appIsDefaultProtocolClient', (protocol, path, args) => { - const success = app.isDefaultProtocolClient(protocol, path, args); - electronSocket.emit('appIsDefaultProtocolClientCompleted', success); - }); - - socket.on('appSetUserTasks', (tasks) => { - const success = app.setUserTasks(tasks); - electronSocket.emit('appSetUserTasksCompleted', success); - }); - - socket.on('appGetJumpListSettings', () => { - const jumpListSettings = app.getJumpListSettings(); - electronSocket.emit('appGetJumpListSettingsCompleted', jumpListSettings); - }); - - socket.on('appSetJumpList', (categories) => { - app.setJumpList(categories); - }); - - socket.on('appRequestSingleInstanceLock', () => { - const success = app.requestSingleInstanceLock(); - electronSocket.emit('appRequestSingleInstanceLockCompleted', success); - - app.on('second-instance', (event, args = [], workingDirectory = '') => { - electronSocket.emit('secondInstance', [args, workingDirectory]); - }); - }); - - socket.on('appHasSingleInstanceLock', () => { - const hasLock = app.hasSingleInstanceLock(); - - electronSocket.emit('appHasSingleInstanceLockCompleted', hasLock); - }); - - socket.on('appReleaseSingleInstanceLock', () => { - app.releaseSingleInstanceLock(); - }); - - socket.on('appSetUserActivity', (type, userInfo, webpageUrl) => { - app.setUserActivity(type, userInfo, webpageUrl); - }); - - socket.on('appGetCurrentActivityType', () => { - const activityType = app.getCurrentActivityType(); - electronSocket.emit('appGetCurrentActivityTypeCompleted', activityType); - }); - - socket.on('appInvalidateCurrentActivity', () => { - app.invalidateCurrentActivity(); - }); - - socket.on('appResignCurrentActivity', () => { - app.resignCurrentActivity(); - }); - - socket.on('appSetAppUserModelId', (id) => { - app.setAppUserModelId(id); - }); - - socket.on('appImportCertificate', (options) => { - app.importCertificate(options, (result) => { - electronSocket.emit('appImportCertificateCompleted', result); - }); - }); - - socket.on('appGetAppMetrics', () => { - const processMetrics = app.getAppMetrics(); - electronSocket.emit('appGetAppMetricsCompleted', processMetrics); - }); - - socket.on('appGetGpuFeatureStatus', () => { - const gpuFeatureStatus = app.getGPUFeatureStatus(); - electronSocket.emit('appGetGpuFeatureStatusCompleted', gpuFeatureStatus); - }); - - socket.on('appSetBadgeCount', (count) => { - const success = app.setBadgeCount(count); - electronSocket.emit('appSetBadgeCountCompleted', success); - }); - - socket.on('appGetBadgeCount', () => { - const count = app.getBadgeCount(); - electronSocket.emit('appGetBadgeCountCompleted', count); - }); - - socket.on('appIsUnityRunning', () => { - const isUnityRunning = app.isUnityRunning(); - electronSocket.emit('appIsUnityRunningCompleted', isUnityRunning); - }); - - socket.on('appGetLoginItemSettings', (options) => { - const loginItemSettings = app.getLoginItemSettings(options as LoginItemSettingsOptions); - electronSocket.emit('appGetLoginItemSettingsCompleted', loginItemSettings); - }); - - socket.on('appSetLoginItemSettings', (settings) => { - app.setLoginItemSettings(settings as Settings); - }); - - socket.on('appIsAccessibilitySupportEnabled', () => { - const isAccessibilitySupportEnabled = app.isAccessibilitySupportEnabled(); - electronSocket.emit('appIsAccessibilitySupportEnabledCompleted', isAccessibilitySupportEnabled); - }); - - socket.on('appSetAccessibilitySupportEnabled', (enabled) => { - app.setAccessibilitySupportEnabled(enabled); - }); - - socket.on('appShowAboutPanel', () => { - app.showAboutPanel(); - }); - - socket.on('appSetAboutPanelOptions', (options) => { - app.setAboutPanelOptions(options as AboutPanelOptionsOptions); - }); - - socket.on('appGetUserAgentFallback', () => { - electronSocket.emit('appGetUserAgentFallbackCompleted', app.userAgentFallback); - }); - - socket.on('appSetUserAgentFallback', (userAgent) => { - app.userAgentFallback = userAgent; - }); - - socket.on('register-app-on-event', (eventName, listenerName) => { - app.on(eventName, (...args) => { - if (args.length > 1) { - electronSocket.emit(listenerName, args[1]); - } else { - electronSocket.emit(listenerName); - } - }); - }); - - socket.on('register-app-once-event', (eventName, listenerName) => { - app.once(eventName, (...args) => { - if (args.length > 1) { - electronSocket.emit(listenerName, args[1]); - } else { - electronSocket.emit(listenerName); - } - }); + socket.on("register-app-once-event", (eventName, listenerName) => { + app.once(eventName, (...args) => { + if (args.length > 1) { + electronSocket.emit(listenerName, args[1]); + } else { + electronSocket.emit(listenerName); + } }); + }); }; diff --git a/src/ElectronNET.Host/api/autoUpdater.ts b/src/ElectronNET.Host/api/autoUpdater.ts index c1ebb5e..64c5105 100644 --- a/src/ElectronNET.Host/api/autoUpdater.ts +++ b/src/ElectronNET.Host/api/autoUpdater.ts @@ -1,143 +1,192 @@ -import { Socket } from 'net'; -import { autoUpdater } from 'electron-updater'; -let electronSocket; +import type { Socket } from "net"; +import { autoUpdater } from "electron-updater"; + +let electronSocket: Socket; export = (socket: Socket) => { - electronSocket = socket; + electronSocket = socket; - socket.on('register-autoUpdater-error', (id) => { - autoUpdater.on('error', (error) => { - electronSocket.emit('autoUpdater-error' + id, error.message); - }); + socket.on("register-autoUpdater-error", (id) => { + autoUpdater.on("error", (error) => { + electronSocket.emit("autoUpdater-error" + id, error.message); }); + }); - socket.on('register-autoUpdater-checking-for-update', (id) => { - autoUpdater.on('checking-for-update', () => { - electronSocket.emit('autoUpdater-checking-for-update' + id); - }); + socket.on("register-autoUpdater-checking-for-update", (id) => { + autoUpdater.on("checking-for-update", () => { + electronSocket.emit("autoUpdater-checking-for-update" + id); }); + }); - socket.on('register-autoUpdater-update-available', (id) => { - autoUpdater.on('update-available', (updateInfo) => { - electronSocket.emit('autoUpdater-update-available' + id, updateInfo); - }); + socket.on("register-autoUpdater-update-available", (id) => { + autoUpdater.on("update-available", (updateInfo) => { + electronSocket.emit("autoUpdater-update-available" + id, updateInfo); }); + }); - socket.on('register-autoUpdater-update-not-available', (id) => { - autoUpdater.on('update-not-available', (updateInfo) => { - electronSocket.emit('autoUpdater-update-not-available' + id, updateInfo); - }); + socket.on("register-autoUpdater-update-not-available", (id) => { + autoUpdater.on("update-not-available", (updateInfo) => { + electronSocket.emit("autoUpdater-update-not-available" + id, updateInfo); }); + }); - socket.on('register-autoUpdater-download-progress', (id) => { - autoUpdater.on('download-progress', (progressInfo) => { - electronSocket.emit('autoUpdater-download-progress' + id, progressInfo); - }); + socket.on("register-autoUpdater-download-progress", (id) => { + autoUpdater.on("download-progress", (progressInfo) => { + electronSocket.emit("autoUpdater-download-progress" + id, progressInfo); }); + }); - socket.on('register-autoUpdater-update-downloaded', (id) => { - autoUpdater.on('update-downloaded', (updateInfo) => { - electronSocket.emit('autoUpdater-update-downloaded' + id, updateInfo); - }); + socket.on("register-autoUpdater-update-downloaded", (id) => { + autoUpdater.on("update-downloaded", (updateInfo) => { + electronSocket.emit("autoUpdater-update-downloaded" + id, updateInfo); }); + }); - // Properties ***** + // Properties ***** - socket.on('autoUpdater-autoDownload', () => { - electronSocket.emit('autoUpdater-autoDownload-completed', autoUpdater.autoDownload); - }); + socket.on("autoUpdater-autoDownload", () => { + electronSocket.emit( + "autoUpdater-autoDownload-completed", + autoUpdater.autoDownload, + ); + }); - socket.on('autoUpdater-autoDownload-set', (value) => { - autoUpdater.autoDownload = value; - }); + socket.on("autoUpdater-autoDownload-set", (value) => { + autoUpdater.autoDownload = value; + }); - socket.on('autoUpdater-autoInstallOnAppQuit', () => { - electronSocket.emit('autoUpdater-autoInstallOnAppQuit-completed', autoUpdater.autoInstallOnAppQuit); - }); + socket.on("autoUpdater-autoInstallOnAppQuit", () => { + electronSocket.emit( + "autoUpdater-autoInstallOnAppQuit-completed", + autoUpdater.autoInstallOnAppQuit, + ); + }); - socket.on('autoUpdater-autoInstallOnAppQuit-set', (value) => { - autoUpdater.autoInstallOnAppQuit = value; - }); + socket.on("autoUpdater-autoInstallOnAppQuit-set", (value) => { + autoUpdater.autoInstallOnAppQuit = value; + }); - socket.on('autoUpdater-allowPrerelease', () => { - electronSocket.emit('autoUpdater-allowPrerelease-completed', autoUpdater.allowPrerelease); - }); + socket.on("autoUpdater-allowPrerelease", () => { + electronSocket.emit( + "autoUpdater-allowPrerelease-completed", + autoUpdater.allowPrerelease, + ); + }); - socket.on('autoUpdater-allowPrerelease-set', (value) => { - autoUpdater.allowPrerelease = value; - }); + socket.on("autoUpdater-allowPrerelease-set", (value) => { + autoUpdater.allowPrerelease = value; + }); - socket.on('autoUpdater-fullChangelog', () => { - electronSocket.emit('autoUpdater-fullChangelog-completed', autoUpdater.fullChangelog); - }); + socket.on("autoUpdater-fullChangelog", () => { + electronSocket.emit( + "autoUpdater-fullChangelog-completed", + autoUpdater.fullChangelog, + ); + }); - socket.on('autoUpdater-fullChangelog-set', (value) => { - autoUpdater.fullChangelog = value; - }); + socket.on("autoUpdater-fullChangelog-set", (value) => { + autoUpdater.fullChangelog = value; + }); - socket.on('autoUpdater-allowDowngrade', () => { - electronSocket.emit('autoUpdater-allowDowngrade-completed', autoUpdater.allowDowngrade); - }); + socket.on("autoUpdater-allowDowngrade", () => { + electronSocket.emit( + "autoUpdater-allowDowngrade-completed", + autoUpdater.allowDowngrade, + ); + }); - socket.on('autoUpdater-allowDowngrade-set', (value) => { - autoUpdater.allowDowngrade = value; - }); + socket.on("autoUpdater-allowDowngrade-set", (value) => { + autoUpdater.allowDowngrade = value; + }); - socket.on('autoUpdater-updateConfigPath', () => { - electronSocket.emit('autoUpdater-updateConfigPath-completed', autoUpdater.updateConfigPath || ''); - }); + socket.on("autoUpdater-updateConfigPath", () => { + electronSocket.emit( + "autoUpdater-updateConfigPath-completed", + autoUpdater.updateConfigPath || "", + ); + }); - socket.on('autoUpdater-updateConfigPath-set', (value) => { - autoUpdater.updateConfigPath = value; - }); + socket.on("autoUpdater-updateConfigPath-set", (value) => { + autoUpdater.updateConfigPath = value; + }); - socket.on('autoUpdater-currentVersion', () => { - electronSocket.emit('autoUpdater-currentVersion-completed', autoUpdater.currentVersion); - }); + socket.on("autoUpdater-currentVersion", () => { + electronSocket.emit( + "autoUpdater-currentVersion-completed", + autoUpdater.currentVersion, + ); + }); - socket.on('autoUpdater-channel', () => { - electronSocket.emit('autoUpdater-channel-completed', autoUpdater.channel || ''); - }); + socket.on("autoUpdater-channel", () => { + electronSocket.emit( + "autoUpdater-channel-completed", + autoUpdater.channel || "", + ); + }); - socket.on('autoUpdater-channel-set', (value) => { - autoUpdater.channel = value; - }); + socket.on("autoUpdater-channel-set", (value) => { + autoUpdater.channel = value; + }); - socket.on('autoUpdater-requestHeaders', () => { - electronSocket.emit('autoUpdater-requestHeaders-completed', autoUpdater.requestHeaders); - }); + socket.on("autoUpdater-requestHeaders", () => { + electronSocket.emit( + "autoUpdater-requestHeaders-completed", + autoUpdater.requestHeaders, + ); + }); - socket.on('autoUpdater-requestHeaders-set', (value) => { - autoUpdater.requestHeaders = value; - }); + socket.on("autoUpdater-requestHeaders-set", (value) => { + autoUpdater.requestHeaders = value; + }); - socket.on('autoUpdater-checkForUpdatesAndNotify', async (guid) => { - autoUpdater.checkForUpdatesAndNotify().then((updateCheckResult) => { - electronSocket.emit('autoUpdater-checkForUpdatesAndNotify-completed' + guid, updateCheckResult); - }).catch((error) => { - electronSocket.emit('autoUpdater-checkForUpdatesAndNotifyError' + guid, error); - }); - }); + socket.on("autoUpdater-checkForUpdatesAndNotify", async (guid) => { + autoUpdater + .checkForUpdatesAndNotify() + .then((updateCheckResult) => { + electronSocket.emit( + "autoUpdater-checkForUpdatesAndNotify-completed" + guid, + updateCheckResult, + ); + }) + .catch((error) => { + electronSocket.emit( + "autoUpdater-checkForUpdatesAndNotifyError" + guid, + error, + ); + }); + }); - socket.on('autoUpdater-checkForUpdates', async (guid) => { - autoUpdater.checkForUpdates().then((updateCheckResult) => { - electronSocket.emit('autoUpdater-checkForUpdates-completed' + guid, updateCheckResult); - }).catch((error) => { - electronSocket.emit('autoUpdater-checkForUpdatesError' + guid, error); - }); - }); + socket.on("autoUpdater-checkForUpdates", async (guid) => { + autoUpdater + .checkForUpdates() + .then((updateCheckResult) => { + electronSocket.emit( + "autoUpdater-checkForUpdates-completed" + guid, + updateCheckResult, + ); + }) + .catch((error) => { + electronSocket.emit("autoUpdater-checkForUpdatesError" + guid, error); + }); + }); - socket.on('autoUpdater-quitAndInstall', async (isSilent, isForceRunAfter) => { - autoUpdater.quitAndInstall(isSilent, isForceRunAfter); - }); + socket.on("autoUpdater-quitAndInstall", async (isSilent, isForceRunAfter) => { + autoUpdater.quitAndInstall(isSilent, isForceRunAfter); + }); - socket.on('autoUpdater-downloadUpdate', async (guid) => { - const downloadedPath = await autoUpdater.downloadUpdate(); - electronSocket.emit('autoUpdater-downloadUpdate-completed' + guid, downloadedPath); - }); + socket.on("autoUpdater-downloadUpdate", async (guid) => { + const downloadedPath = await autoUpdater.downloadUpdate(); + electronSocket.emit( + "autoUpdater-downloadUpdate-completed" + guid, + downloadedPath, + ); + }); - socket.on('autoUpdater-getFeedURL', async (guid) => { - const feedUrl = await autoUpdater.getFeedURL(); - electronSocket.emit('autoUpdater-getFeedURL-completed' + guid, feedUrl || ''); - }); + socket.on("autoUpdater-getFeedURL", async (guid) => { + const feedUrl = await autoUpdater.getFeedURL(); + electronSocket.emit( + "autoUpdater-getFeedURL-completed" + guid, + feedUrl || "", + ); + }); }; diff --git a/src/ElectronNET.Host/api/browserView.ts b/src/ElectronNET.Host/api/browserView.ts index 81c36f8..8efaa2c 100644 --- a/src/ElectronNET.Host/api/browserView.ts +++ b/src/ElectronNET.Host/api/browserView.ts @@ -1,74 +1,83 @@ -import { Socket } from 'net'; -import { BrowserView } from 'electron'; -const browserViews: BrowserView[] = (global['browserViews'] = global['browserViews'] || []) as BrowserView[]; -let browserView: BrowserView, electronSocket; -const proxyToCredentialsMap: { [proxy: string]: string } = (global['proxyToCredentialsMap'] = global['proxyToCredentialsMap'] || []) as { [proxy: string]: string }; +import type { Socket } from "net"; +import { BrowserView } from "electron"; + +const browserViews: BrowserView[] = (global["browserViews"] = + global["browserViews"] || []) as BrowserView[]; +const proxyToCredentialsMap: { [proxy: string]: string } = (global[ + "proxyToCredentialsMap" +] = global["proxyToCredentialsMap"] || []) as { [proxy: string]: string }; + +let browserView: BrowserView; +let electronSocket: Socket; const browserViewApi = (socket: Socket) => { - electronSocket = socket; + electronSocket = socket; - socket.on('createBrowserView', (options) => { - if (!hasOwnChildreen(options, 'webPreferences', 'nodeIntegration')) { - options = { ...options, webPreferences: { nodeIntegration: true, contextIsolation: false } }; - } - - browserView = new BrowserView(options); - browserView['id'] = browserViews.length + 1; - - if (options.proxy) { - browserView.webContents.session.setProxy({proxyRules: options.proxy}); - } - - if (options.proxy && options.proxyCredentials) { - proxyToCredentialsMap[options.proxy] = options.proxyCredentials; - } - - browserViews.push(browserView); - - electronSocket.emit('BrowserViewCreated', browserView['id']); - }); - - socket.on('browserView-bounds', (id) => { - const bounds = getBrowserViewById(id).getBounds(); - - electronSocket.emit('browserView-bounds-completed', bounds); - }); - - socket.on('browserView-bounds-set', (id, bounds) => { - getBrowserViewById(id).setBounds(bounds); - }); - - socket.on('browserView-setAutoResize', (id, options) => { - getBrowserViewById(id).setAutoResize(options); - }); - - socket.on('browserView-setBackgroundColor', (id, color) => { - getBrowserViewById(id).setBackgroundColor(color); - }); - - function hasOwnChildreen(obj, ...childNames) { - for (let i = 0; i < childNames.length; i++) { - if (!obj || !obj.hasOwnProperty(childNames[i])) { - return false; - } - obj = obj[childNames[i]]; - } - - return true; + socket.on("createBrowserView", (options) => { + if (!hasOwnChildreen(options, "webPreferences", "nodeIntegration")) { + options = { + ...options, + webPreferences: { nodeIntegration: true, contextIsolation: false }, + }; } + + browserView = new BrowserView(options); + browserView["id"] = browserViews.length + 1; + + if (options.proxy) { + browserView.webContents.session.setProxy({ proxyRules: options.proxy }); + } + + if (options.proxy && options.proxyCredentials) { + proxyToCredentialsMap[options.proxy] = options.proxyCredentials; + } + + browserViews.push(browserView); + + electronSocket.emit("BrowserViewCreated", browserView["id"]); + }); + + socket.on("browserView-bounds", (id) => { + const bounds = getBrowserViewById(id).getBounds(); + + electronSocket.emit("browserView-bounds-completed", bounds); + }); + + socket.on("browserView-bounds-set", (id, bounds) => { + getBrowserViewById(id).setBounds(bounds); + }); + + socket.on("browserView-setAutoResize", (id, options) => { + getBrowserViewById(id).setAutoResize(options); + }); + + socket.on("browserView-setBackgroundColor", (id, color) => { + getBrowserViewById(id).setBackgroundColor(color); + }); + + function hasOwnChildreen(obj, ...childNames) { + for (let i = 0; i < childNames.length; i++) { + if (!obj || !obj.hasOwnProperty(childNames[i])) { + return false; + } + obj = obj[childNames[i]]; + } + + return true; + } }; const browserViewMediateService = (browserViewId: number): BrowserView => { - return getBrowserViewById(browserViewId); + return getBrowserViewById(browserViewId); }; function getBrowserViewById(id: number) { - for (let index = 0; index < browserViews.length; index++) { - const browserViewItem = browserViews[index]; - if (browserViewItem['id'] === id) { - return browserViewItem; - } + for (let index = 0; index < browserViews.length; index++) { + const browserViewItem = browserViews[index]; + if (browserViewItem["id"] === id) { + return browserViewItem; } + } } export { browserViewApi, browserViewMediateService }; diff --git a/src/ElectronNET.Host/api/browserWindows.ts b/src/ElectronNET.Host/api/browserWindows.ts index d056f90..a8cd92d 100644 --- a/src/ElectronNET.Host/api/browserWindows.ts +++ b/src/ElectronNET.Host/api/browserWindows.ts @@ -1,12 +1,17 @@ -import { Socket } from "net"; -import { BrowserWindow, Menu, nativeImage } from "electron"; +import * as path from "path"; +import type { Socket } from "net"; +import { BrowserWindow, Menu } from "electron"; + import { browserViewMediateService } from "./browserView"; -const path = require("path"); + const windows: Electron.BrowserWindow[] = (global["browserWindows"] = global["browserWindows"] || []) as Electron.BrowserWindow[]; let readyToShowWindowsIds: number[] = []; -let window, lastOptions, electronSocket; -let mainWindowURL; + +let window; +let lastOptions; +let electronSocket; + const proxyToCredentialsMap: { [proxy: string]: string } = (global[ "proxyToCredentialsMap" ] = global["proxyToCredentialsMap"] || []) as { [proxy: string]: string }; @@ -32,7 +37,7 @@ export = (socket: Socket, app: Electron.App) => { socket.on("register-browserWindow-ready-to-show", (id) => { if (readyToShowWindowsIds.includes(id)) { readyToShowWindowsIds = readyToShowWindowsIds.filter( - (value) => value !== id + (value) => value !== id, ); electronSocket.emit("browserWindow-ready-to-show" + id); } @@ -141,7 +146,11 @@ export = (socket: Socket, app: Electron.App) => { socket.on("register-browserWindow-bounds-changed", (id) => { const window = getWindowById(id); - const cb = () => electronSocket.emit("browserWindow-bounds-changed" + id, window.getBounds()); + const cb = () => + electronSocket.emit( + "browserWindow-bounds-changed" + id, + window.getBounds(), + ); window.on("resize", cb); window.on("move", cb); }); @@ -231,7 +240,7 @@ export = (socket: Socket, app: Electron.App) => { __dirname, "..", "scripts", - "blazor-preload.js" + "blazor-preload.js", ); } @@ -264,7 +273,7 @@ export = (socket: Socket, app: Electron.App) => { window.on("ready-to-show", () => { if (readyToShowWindowsIds.includes(window.id)) { readyToShowWindowsIds = readyToShowWindowsIds.filter( - (value) => value !== window.id + (value) => value !== window.id, ); } else { readyToShowWindowsIds.push(window.id); @@ -531,7 +540,7 @@ export = (socket: Socket, app: Electron.App) => { electronSocket.emit( "browserWindow-isFullScreenable-completed", - fullscreenable + fullscreenable, ); }); @@ -616,7 +625,7 @@ export = (socket: Socket, app: Electron.App) => { .toString(16); electronSocket.emit( "browserWindow-getNativeWindowHandle-completed", - nativeWindowHandle + nativeWindowHandle, ); }); @@ -629,7 +638,7 @@ export = (socket: Socket, app: Electron.App) => { } catch (e) { console.warn( "setRepresentedFilename failed (likely unsupported platform):", - e + e, ); } }); @@ -644,12 +653,12 @@ export = (socket: Socket, app: Electron.App) => { } catch (e) { console.warn( "getRepresentedFilename failed (likely unsupported platform):", - e + e, ); } electronSocket.emit( "browserWindow-getRepresentedFilename-completed", - pathname + pathname, ); }); @@ -741,7 +750,7 @@ export = (socket: Socket, app: Electron.App) => { imagePath = path.join( __dirname.replace("api", ""), "bin", - originalIconPath + originalIconPath, ); } const { nativeImage } = require("electron"); @@ -758,7 +767,7 @@ export = (socket: Socket, app: Electron.App) => { const success = getWindowById(id).setThumbarButtons(thumbarButtons); electronSocket.emit("browserWindowSetThumbarButtons-completed", success); - } + }, ); socket.on("browserWindowSetThumbnailClip", (id, rectangle) => { @@ -786,7 +795,7 @@ export = (socket: Socket, app: Electron.App) => { electronSocket.emit( "browserWindow-isMenuBarAutoHide-completed", - isMenuBarAutoHide + isMenuBarAutoHide, ); }); @@ -799,7 +808,7 @@ export = (socket: Socket, app: Electron.App) => { electronSocket.emit( "browserWindow-isMenuBarVisible-completed", - isMenuBarVisible + isMenuBarVisible, ); }); @@ -813,7 +822,7 @@ export = (socket: Socket, app: Electron.App) => { electronSocket.emit( "browserWindow-isVisibleOnAllWorkspaces-completed", - isVisibleOnAllWorkspaces + isVisibleOnAllWorkspaces, ); }); @@ -845,7 +854,7 @@ export = (socket: Socket, app: Electron.App) => { electronSocket.emit( "browserWindow-getParentWindow-completed", - browserWindow.id + browserWindow.id, ); }); diff --git a/src/ElectronNET.Host/api/clipboard.ts b/src/ElectronNET.Host/api/clipboard.ts index 7f4f328..fe16209 100644 --- a/src/ElectronNET.Host/api/clipboard.ts +++ b/src/ElectronNET.Host/api/clipboard.ts @@ -1,84 +1,87 @@ -import { Socket } from 'net'; -import { clipboard, nativeImage } from 'electron'; -let electronSocket; +import type { Socket } from "net"; +import { clipboard, nativeImage } from "electron"; + +let electronSocket: Socket; export = (socket: Socket) => { - electronSocket = socket; - socket.on('clipboard-readText', (type) => { - const text = clipboard.readText(type); - electronSocket.emit('clipboard-readText-completed', text); + electronSocket = socket; + socket.on("clipboard-readText", (type) => { + const text = clipboard.readText(type); + electronSocket.emit("clipboard-readText-completed", text); + }); + + socket.on("clipboard-writeText", (text, type) => { + clipboard.writeText(text, type); + }); + + socket.on("clipboard-readHTML", (type) => { + const content = clipboard.readHTML(type); + electronSocket.emit("clipboard-readHTML-completed", content); + }); + + socket.on("clipboard-writeHTML", (markup, type) => { + clipboard.writeHTML(markup, type); + }); + + socket.on("clipboard-readRTF", (type) => { + const content = clipboard.readRTF(type); + electronSocket.emit("clipboard-readRTF-completed", content); + }); + + socket.on("clipboard-writeRTF", (text, type) => { + clipboard.writeHTML(text, type); + }); + + socket.on("clipboard-readBookmark", () => { + const bookmark = clipboard.readBookmark(); + electronSocket.emit("clipboard-readBookmark-completed", bookmark); + }); + + socket.on("clipboard-writeBookmark", (title, url, type) => { + clipboard.writeBookmark(title, url, type); + }); + + socket.on("clipboard-readFindText", () => { + const content = clipboard.readFindText(); + electronSocket.emit("clipboard-readFindText-completed", content); + }); + + socket.on("clipboard-writeFindText", (text) => { + clipboard.writeFindText(text); + }); + + socket.on("clipboard-clear", (type) => { + clipboard.clear(type); + }); + + socket.on("clipboard-availableFormats", (type) => { + const formats = clipboard.availableFormats(type); + electronSocket.emit("clipboard-availableFormats-completed", formats); + }); + + socket.on("clipboard-write", (data, type) => { + clipboard.write(data, type); + }); + + socket.on("clipboard-readImage", (type) => { + const image = clipboard.readImage(type); + electronSocket.emit("clipboard-readImage-completed", { + 1: image.toPNG().toString("base64"), }); + }); - socket.on('clipboard-writeText', (text, type) => { - clipboard.writeText(text, type); - }); + socket.on("clipboard-writeImage", (data, type) => { + const dataContent = JSON.parse(data); + const image = nativeImage.createEmpty(); - socket.on('clipboard-readHTML', (type) => { - const content = clipboard.readHTML(type); - electronSocket.emit('clipboard-readHTML-completed', content); - }); + // tslint:disable-next-line: forin + for (const key in dataContent) { + const scaleFactor = key; + const bytes = data[key]; + const buffer = Buffer.from(bytes, "base64"); + image.addRepresentation({ scaleFactor: +scaleFactor, buffer: buffer }); + } - socket.on('clipboard-writeHTML', (markup, type) => { - clipboard.writeHTML(markup, type); - }); - - socket.on('clipboard-readRTF', (type) => { - const content = clipboard.readRTF(type); - electronSocket.emit('clipboard-readRTF-completed', content); - }); - - socket.on('clipboard-writeRTF', (text, type) => { - clipboard.writeHTML(text, type); - }); - - socket.on('clipboard-readBookmark', () => { - const bookmark = clipboard.readBookmark(); - electronSocket.emit('clipboard-readBookmark-completed', bookmark); - }); - - socket.on('clipboard-writeBookmark', (title, url, type) => { - clipboard.writeBookmark(title, url, type); - }); - - socket.on('clipboard-readFindText', () => { - const content = clipboard.readFindText(); - electronSocket.emit('clipboard-readFindText-completed', content); - }); - - socket.on('clipboard-writeFindText', (text) => { - clipboard.writeFindText(text); - }); - - socket.on('clipboard-clear', (type) => { - clipboard.clear(type); - }); - - socket.on('clipboard-availableFormats', (type) => { - const formats = clipboard.availableFormats(type); - electronSocket.emit('clipboard-availableFormats-completed', formats); - }); - - socket.on('clipboard-write', (data, type) => { - clipboard.write(data, type); - }); - - socket.on('clipboard-readImage', (type) => { - const image = clipboard.readImage(type); - electronSocket.emit('clipboard-readImage-completed', { 1: image.toPNG().toString('base64') }); - }); - - socket.on('clipboard-writeImage', (data, type) => { - const dataContent = JSON.parse(data); - const image = nativeImage.createEmpty(); - - // tslint:disable-next-line: forin - for (const key in dataContent) { - const scaleFactor = key; - const bytes = data[key]; - const buffer = Buffer.from(bytes, 'base64'); - image.addRepresentation({ scaleFactor: +scaleFactor, buffer: buffer }); - } - - clipboard.writeImage(image, type); - }); + clipboard.writeImage(image, type); + }); }; diff --git a/src/ElectronNET.Host/api/commandLine.ts b/src/ElectronNET.Host/api/commandLine.ts index f206b93..f4d6c26 100644 --- a/src/ElectronNET.Host/api/commandLine.ts +++ b/src/ElectronNET.Host/api/commandLine.ts @@ -1,24 +1,28 @@ -import { Socket } from 'net'; -let electronSocket; +import type { Socket } from "net"; + +let electronSocket: Socket; export = (socket: Socket, app: Electron.App) => { - electronSocket = socket; + electronSocket = socket; - socket.on('appCommandLineAppendSwitch', (the_switch: string, value: string) => { - app.commandLine.appendSwitch(the_switch, value); - }); + socket.on( + "appCommandLineAppendSwitch", + (the_switch: string, value: string) => { + app.commandLine.appendSwitch(the_switch, value); + }, + ); - socket.on('appCommandLineAppendArgument', (value: string) => { - app.commandLine.appendArgument(value); - }); + socket.on("appCommandLineAppendArgument", (value: string) => { + app.commandLine.appendArgument(value); + }); - socket.on('appCommandLineHasSwitch', (value: string) => { - const hasSwitch = app.commandLine.hasSwitch(value); - electronSocket.emit('appCommandLineHasSwitchCompleted', hasSwitch); - }); + socket.on("appCommandLineHasSwitch", (value: string) => { + const hasSwitch = app.commandLine.hasSwitch(value); + electronSocket.emit("appCommandLineHasSwitchCompleted", hasSwitch); + }); - socket.on('appCommandLineGetSwitchValue', (the_switch: string) => { - const value = app.commandLine.getSwitchValue(the_switch); - electronSocket.emit('appCommandLineGetSwitchValueCompleted', value); - }); + socket.on("appCommandLineGetSwitchValue", (the_switch: string) => { + const value = app.commandLine.getSwitchValue(the_switch); + electronSocket.emit("appCommandLineGetSwitchValueCompleted", value); + }); }; diff --git a/src/ElectronNET.Host/api/dialog.ts b/src/ElectronNET.Host/api/dialog.ts index 7e33139..848853b 100644 --- a/src/ElectronNET.Host/api/dialog.ts +++ b/src/ElectronNET.Host/api/dialog.ts @@ -1,45 +1,64 @@ -import { Socket } from 'net'; -import { BrowserWindow, dialog } from 'electron'; +import type { Socket } from "net"; +import { BrowserWindow, dialog } from "electron"; + let electronSocket: Socket; export = (socket: Socket) => { - electronSocket = socket; - socket.on('showMessageBox', async (browserWindow, options, guid) => { - if ('id' in browserWindow) { - const window = BrowserWindow.fromId(browserWindow.id); + electronSocket = socket; + socket.on("showMessageBox", async (browserWindow, options, guid) => { + if ("id" in browserWindow) { + const window = BrowserWindow.fromId(browserWindow.id); - const messageBoxReturnValue = await dialog.showMessageBox(window, options); - electronSocket.emit('showMessageBoxComplete' + guid, [messageBoxReturnValue.response, messageBoxReturnValue.checkboxChecked]); - } else { - const id = guid || options; - const messageBoxReturnValue = await dialog.showMessageBox(browserWindow); + const messageBoxReturnValue = await dialog.showMessageBox( + window, + options, + ); + electronSocket.emit("showMessageBoxComplete" + guid, [ + messageBoxReturnValue.response, + messageBoxReturnValue.checkboxChecked, + ]); + } else { + const id = guid || options; + const messageBoxReturnValue = await dialog.showMessageBox(browserWindow); - electronSocket.emit('showMessageBoxComplete' + id, [messageBoxReturnValue.response, messageBoxReturnValue.checkboxChecked]); - } - }); + electronSocket.emit("showMessageBoxComplete" + id, [ + messageBoxReturnValue.response, + messageBoxReturnValue.checkboxChecked, + ]); + } + }); - socket.on('showOpenDialog', async (browserWindow, options, guid) => { - const window = BrowserWindow.fromId(browserWindow.id); - const openDialogReturnValue = await dialog.showOpenDialog(window, options); + socket.on("showOpenDialog", async (browserWindow, options, guid) => { + const window = BrowserWindow.fromId(browserWindow.id); + const openDialogReturnValue = await dialog.showOpenDialog(window, options); - electronSocket.emit('showOpenDialogComplete' + guid, openDialogReturnValue.filePaths || []); - }); + electronSocket.emit( + "showOpenDialogComplete" + guid, + openDialogReturnValue.filePaths || [], + ); + }); - socket.on('showSaveDialog', async (browserWindow, options, guid) => { - const window = BrowserWindow.fromId(browserWindow.id); - const saveDialogReturnValue = await dialog.showSaveDialog(window, options); + socket.on("showSaveDialog", async (browserWindow, options, guid) => { + const window = BrowserWindow.fromId(browserWindow.id); + const saveDialogReturnValue = await dialog.showSaveDialog(window, options); - electronSocket.emit('showSaveDialogComplete' + guid, saveDialogReturnValue.filePath || ''); - }); + electronSocket.emit( + "showSaveDialogComplete" + guid, + saveDialogReturnValue.filePath || "", + ); + }); - socket.on('showErrorBox', (title, content) => { - dialog.showErrorBox(title, content); - }); + socket.on("showErrorBox", (title, content) => { + dialog.showErrorBox(title, content); + }); - socket.on('showCertificateTrustDialog', async (browserWindow, options, guid) => { - const window = BrowserWindow.fromId(browserWindow.id); - await dialog.showCertificateTrustDialog(window, options); + socket.on( + "showCertificateTrustDialog", + async (browserWindow, options, guid) => { + const window = BrowserWindow.fromId(browserWindow.id); + await dialog.showCertificateTrustDialog(window, options); - electronSocket.emit('showCertificateTrustDialogComplete' + guid); - }); + electronSocket.emit("showCertificateTrustDialogComplete" + guid); + }, + ); }; diff --git a/src/ElectronNET.Host/api/dock.ts b/src/ElectronNET.Host/api/dock.ts index bf2b908..d214e4f 100644 --- a/src/ElectronNET.Host/api/dock.ts +++ b/src/ElectronNET.Host/api/dock.ts @@ -1,78 +1,81 @@ -import { Socket } from 'net'; -import { app, Menu } from 'electron'; -let electronSocket; +import type { Socket } from "net"; +import { app, Menu } from "electron"; + +let electronSocket: Socket; export = (socket: Socket) => { - electronSocket = socket; + electronSocket = socket; - socket.on('dock-bounce', (type) => { - const id = app.dock.bounce(type); - electronSocket.emit('dock-bounce-completed', id); - }); + socket.on("dock-bounce", (type) => { + const id = app.dock.bounce(type); + electronSocket.emit("dock-bounce-completed", id); + }); - socket.on('dock-cancelBounce', (id) => { - app.dock.cancelBounce(id); - }); + socket.on("dock-cancelBounce", (id) => { + app.dock.cancelBounce(id); + }); - socket.on('dock-downloadFinished', (filePath) => { - app.dock.downloadFinished(filePath); - }); + socket.on("dock-downloadFinished", (filePath) => { + app.dock.downloadFinished(filePath); + }); - socket.on('dock-setBadge', (text) => { - app.dock.setBadge(text); - }); + socket.on("dock-setBadge", (text) => { + app.dock.setBadge(text); + }); - socket.on('dock-getBadge', () => { - const text = app.dock.getBadge(); - electronSocket.emit('dock-getBadge-completed', text); - }); + socket.on("dock-getBadge", () => { + const text = app.dock.getBadge(); + electronSocket.emit("dock-getBadge-completed", text); + }); - socket.on('dock-hide', () => { - app.dock.hide(); - }); + socket.on("dock-hide", () => { + app.dock.hide(); + }); - socket.on('dock-show', () => { - app.dock.show(); - }); + socket.on("dock-show", () => { + app.dock.show(); + }); - socket.on('dock-isVisible', () => { - const isVisible = app.dock.isVisible(); - electronSocket.emit('dock-isVisible-completed', isVisible); - }); + socket.on("dock-isVisible", () => { + const isVisible = app.dock.isVisible(); + electronSocket.emit("dock-isVisible-completed", isVisible); + }); - socket.on('dock-setMenu', (menuItems) => { - let menu = null; + socket.on("dock-setMenu", (menuItems) => { + let menu = null; - if (menuItems) { - menu = Menu.buildFromTemplate(menuItems); + if (menuItems) { + menu = Menu.buildFromTemplate(menuItems); - addMenuItemClickConnector(menu.items, (id) => { - electronSocket.emit('dockMenuItemClicked', id); - }); - } - - app.dock.setMenu(menu); - }); - - // TODO: Menu (macOS) still to be implemented - socket.on('dock-getMenu', () => { - const menu = app.dock.getMenu(); - electronSocket.emit('dock-getMenu-completed', menu); - }); - - socket.on('dock-setIcon', (image) => { - app.dock.setIcon(image); - }); - - function addMenuItemClickConnector(menuItems, callback) { - menuItems.forEach((item) => { - if (item.submenu && item.submenu.items.length > 0) { - addMenuItemClickConnector(item.submenu.items, callback); - } - - if ('id' in item && item.id) { - item.click = () => { callback(item.id); }; - } - }); + addMenuItemClickConnector(menu.items, (id) => { + electronSocket.emit("dockMenuItemClicked", id); + }); } + + app.dock.setMenu(menu); + }); + + // TODO: Menu (macOS) still to be implemented + socket.on("dock-getMenu", () => { + const menu = app.dock.getMenu(); + electronSocket.emit("dock-getMenu-completed", menu); + }); + + socket.on("dock-setIcon", (image) => { + app.dock.setIcon(image); + }); + + function addMenuItemClickConnector(menuItems, callback) { + menuItems.forEach((item) => { + if (item.submenu && item.submenu.items.length > 0) { + addMenuItemClickConnector(item.submenu.items, callback); + } + + if ("id" in item && item.id) { + item.click = () => { + callback(item.id); + }; + } + }); + } }; diff --git a/src/ElectronNET.Host/api/globalShortcut.ts b/src/ElectronNET.Host/api/globalShortcut.ts index da9e765..93c7bcc 100644 --- a/src/ElectronNET.Host/api/globalShortcut.ts +++ b/src/ElectronNET.Host/api/globalShortcut.ts @@ -1,28 +1,29 @@ -import { globalShortcut } from 'electron'; -import { Socket } from 'net'; -let electronSocket; +import type { Socket } from "net"; +import { globalShortcut } from "electron"; + +let electronSocket: Socket; export = (socket: Socket) => { - electronSocket = socket; - socket.on('globalShortcut-register', (accelerator) => { - globalShortcut.register(accelerator, () => { - electronSocket.emit('globalShortcut-pressed', accelerator); - }); + electronSocket = socket; + socket.on("globalShortcut-register", (accelerator) => { + globalShortcut.register(accelerator, () => { + electronSocket.emit("globalShortcut-pressed", accelerator); }); + }); - socket.on('globalShortcut-isRegistered', (accelerator) => { - const isRegistered = globalShortcut.isRegistered(accelerator); + socket.on("globalShortcut-isRegistered", (accelerator) => { + const isRegistered = globalShortcut.isRegistered(accelerator); - electronSocket.emit('globalShortcut-isRegisteredCompleted', isRegistered); - }); + electronSocket.emit("globalShortcut-isRegisteredCompleted", isRegistered); + }); - socket.on('globalShortcut-unregister', (accelerator) => { - globalShortcut.unregister(accelerator); - }); + socket.on("globalShortcut-unregister", (accelerator) => { + globalShortcut.unregister(accelerator); + }); - socket.on('globalShortcut-unregisterAll', () => { - try { - globalShortcut.unregisterAll(); - } catch (error) { } - }); + socket.on("globalShortcut-unregisterAll", () => { + try { + globalShortcut.unregisterAll(); + } catch (error) {} + }); }; diff --git a/src/ElectronNET.Host/api/ipc.ts b/src/ElectronNET.Host/api/ipc.ts index cce3675..6749fbe 100644 --- a/src/ElectronNET.Host/api/ipc.ts +++ b/src/ElectronNET.Host/api/ipc.ts @@ -1,109 +1,118 @@ -import { ipcMain, BrowserWindow, BrowserView, Menu } from 'electron'; -import { Socket } from 'net'; -let electronSocket; +import type { Socket } from "net"; +import { ipcMain, BrowserWindow, BrowserView, Menu } from "electron"; + +let electronSocket: Socket; export = (socket: Socket) => { - electronSocket = socket; - socket.on('registerIpcMainChannel', (channel) => { - ipcMain.on(channel, (event, args) => { - electronSocket.emit(channel, [event.preventDefault(), args]); + electronSocket = socket; + socket.on("registerIpcMainChannel", (channel) => { + ipcMain.on(channel, (event, args) => { + electronSocket.emit(channel, [event.preventDefault(), args]); + }); + }); + + socket.on("registerSyncIpcMainChannel", (channel) => { + ipcMain.on(channel, (event, args) => { + const x = socket; + x.removeAllListeners(channel + "Sync"); + socket.on(channel + "Sync", (result) => { + event.returnValue = result; + }); + + electronSocket.emit(channel, [event.preventDefault(), args]); + }); + }); + + socket.on("registerOnceIpcMainChannel", (channel) => { + ipcMain.once(channel, (event, args) => { + electronSocket.emit(channel, [event.preventDefault(), args]); + }); + }); + + socket.on("removeAllListenersIpcMainChannel", (channel) => { + ipcMain.removeAllListeners(channel); + }); + + socket.on("sendToIpcRenderer", (browserWindow, channel, data) => { + const window = BrowserWindow.fromId(browserWindow.id); + + if (window) { + window.webContents.send(channel, ...data); + } + }); + + socket.on("sendToIpcRendererBrowserView", (id, channel, data) => { + const browserViews: BrowserView[] = (global["browserViews"] = + global["browserViews"] || []) as BrowserView[]; + let view: BrowserView = null; + for (let i = 0; i < browserViews.length; i++) { + if (browserViews[i]["id"] === id) { + view = browserViews[i]; + break; + } + } + + if (view) { + view.webContents.send(channel, ...data); + } + }); + + socket.on("registerHandleIpcMainChannel", (channel) => { + ipcMain.handle(channel, (event, args) => { + return new Promise((resolve, _reject) => { + socket.removeAllListeners(channel + "Handle"); + socket.on(channel + "Handle", (result) => { + resolve(result); }); + electronSocket.emit(channel, [event.preventDefault(), args]); + }); }); + }); - socket.on('registerSyncIpcMainChannel', (channel) => { - ipcMain.on(channel, (event, args) => { - const x = socket; - x.removeAllListeners(channel + 'Sync'); - socket.on(channel + 'Sync', (result) => { - event.returnValue = result; - }); - - electronSocket.emit(channel, [event.preventDefault(), args]); + socket.on("registerHandleOnceIpcMainChannel", (channel) => { + ipcMain.handleOnce(channel, (event, args) => { + return new Promise((resolve, _reject) => { + socket.removeAllListeners(channel + "HandleOnce"); + socket.once(channel + "HandleOnce", (result) => { + resolve(result); }); + electronSocket.emit(channel, [event.preventDefault(), args]); + }); }); + }); - socket.on('registerOnceIpcMainChannel', (channel) => { - ipcMain.once(channel, (event, args) => { - electronSocket.emit(channel, [event.preventDefault(), args]); - }); - }); + socket.on("removeHandlerIpcMainChannel", (channel) => { + ipcMain.removeHandler(channel); + }); - socket.on('removeAllListenersIpcMainChannel', (channel) => { - ipcMain.removeAllListeners(channel); - }); + // Integration helpers: programmatically click menu items from renderer tests + ipcMain.on("integration-click-application-menu", (event, id: string) => { + try { + const menu = Menu.getApplicationMenu(); + const mi = menu ? menu.getMenuItemById(id) : null; + if (mi && typeof (mi as any).click === "function") { + const bw = BrowserWindow.fromWebContents(event.sender); + (mi as any).click(undefined, bw, undefined); + } + } catch { + /* ignore */ + } + }); - socket.on('sendToIpcRenderer', (browserWindow, channel, data) => { - const window = BrowserWindow.fromId(browserWindow.id); - - if (window) { - window.webContents.send(channel, ...data); + ipcMain.on( + "integration-click-context-menu", + (event, windowId: number, id: string) => { + try { + const entries = (global as any)["contextMenuItems"] || []; + const entry = entries.find((x: any) => x.browserWindowId === windowId); + const mi = entry?.menu?.items?.find((i: any) => i.id === id); + if (mi && typeof (mi as any).click === "function") { + const bw = BrowserWindow.fromId(windowId); + (mi as any).click(undefined, bw, undefined); } - }); - - socket.on('sendToIpcRendererBrowserView', (id, channel, data) => { - const browserViews: BrowserView[] = (global['browserViews'] = global['browserViews'] || []) as BrowserView[]; - let view: BrowserView = null; - for (let i = 0; i < browserViews.length; i++) { - if (browserViews[i]['id'] === id) { - view = browserViews[i]; - break; - } - } - - if (view) { - view.webContents.send(channel, ...data); - } - }); - - socket.on('registerHandleIpcMainChannel', (channel) => { - ipcMain.handle(channel, (event, args) => { - return new Promise((resolve, _reject) => { - socket.removeAllListeners(channel + 'Handle'); - socket.on(channel + 'Handle', (result) => { - resolve(result); - }); - electronSocket.emit(channel, [event.preventDefault(), args]); - }); - }); - }); - - socket.on('registerHandleOnceIpcMainChannel', (channel) => { - ipcMain.handleOnce(channel, (event, args) => { - return new Promise((resolve, _reject) => { - socket.removeAllListeners(channel + 'HandleOnce'); - socket.once(channel + 'HandleOnce', (result) => { - resolve(result); - }); - electronSocket.emit(channel, [event.preventDefault(), args]); - }); - }); - }); - - socket.on('removeHandlerIpcMainChannel', (channel) => { - ipcMain.removeHandler(channel); - }); - - // Integration helpers: programmatically click menu items from renderer tests - ipcMain.on('integration-click-application-menu', (event, id: string) => { - try { - const menu = Menu.getApplicationMenu(); - const mi = menu ? menu.getMenuItemById(id) : null; - if (mi && typeof (mi as any).click === 'function') { - const bw = BrowserWindow.fromWebContents(event.sender); - (mi as any).click(undefined, bw, undefined); - } - } catch { /* ignore */ } - }); - - ipcMain.on('integration-click-context-menu', (event, windowId: number, id: string) => { - try { - const entries = (global as any)['contextMenuItems'] || []; - const entry = entries.find((x: any) => x.browserWindowId === windowId); - const mi = entry?.menu?.items?.find((i: any) => i.id === id); - if (mi && typeof (mi as any).click === 'function') { - const bw = BrowserWindow.fromId(windowId); - (mi as any).click(undefined, bw, undefined); - } - } catch { /* ignore */ } - }); + } catch { + /* ignore */ + } + }, + ); }; diff --git a/src/ElectronNET.Host/api/menu.ts b/src/ElectronNET.Host/api/menu.ts index efadf31..1880181 100644 --- a/src/ElectronNET.Host/api/menu.ts +++ b/src/ElectronNET.Host/api/menu.ts @@ -1,71 +1,92 @@ -import { Socket } from 'net'; -import { Menu, BrowserWindow } from 'electron'; -const contextMenuItems = (global['contextMenuItems'] = global['contextMenuItems'] || []); -let electronSocket; +import type { Socket } from "net"; +import { Menu, BrowserWindow } from "electron"; + +const contextMenuItems = (global["contextMenuItems"] = + global["contextMenuItems"] || []); + +let electronSocket: Socket; export = (socket: Socket) => { - electronSocket = socket; - socket.on('menu-setContextMenu', (browserWindowId, menuItems) => { - const menu = Menu.buildFromTemplate(menuItems); + electronSocket = socket; + socket.on("menu-setContextMenu", (browserWindowId, menuItems) => { + const menu = Menu.buildFromTemplate(menuItems); - addContextMenuItemClickConnector(menu.items, browserWindowId, (id, windowId) => { - electronSocket.emit('contextMenuItemClicked', [id, windowId]); - }); + addContextMenuItemClickConnector( + menu.items, + browserWindowId, + (id, windowId) => { + electronSocket.emit("contextMenuItemClicked", [id, windowId]); + }, + ); - const index = contextMenuItems.findIndex(contextMenu => contextMenu.browserWindowId === browserWindowId); + const index = contextMenuItems.findIndex( + (contextMenu) => contextMenu.browserWindowId === browserWindowId, + ); - const contextMenuItem = { - menu: menu, - browserWindowId: browserWindowId + const contextMenuItem = { + menu: menu, + browserWindowId: browserWindowId, + }; + + if (index === -1) { + contextMenuItems.push(contextMenuItem); + } else { + contextMenuItems[index] = contextMenuItem; + } + }); + + function addContextMenuItemClickConnector( + menuItems, + browserWindowId, + callback, + ) { + menuItems.forEach((item) => { + if (item.submenu && item.submenu.items.length > 0) { + addContextMenuItemClickConnector( + item.submenu.items, + browserWindowId, + callback, + ); + } + + if ("id" in item && item.id) { + item.click = () => { + callback(item.id, browserWindowId); }; + } + }); + } - if (index === -1) { - contextMenuItems.push(contextMenuItem); - } else { - contextMenuItems[index] = contextMenuItem; - } + socket.on("menu-contextMenuPopup", (browserWindowId) => { + contextMenuItems.forEach((x) => { + if (x.browserWindowId === browserWindowId) { + const browserWindow = BrowserWindow.fromId(browserWindowId); + x.menu.popup(browserWindow); + } + }); + }); + + socket.on("menu-setApplicationMenu", (menuItems) => { + const menu = Menu.buildFromTemplate(menuItems); + + addMenuItemClickConnector(menu.items, (id) => { + electronSocket.emit("menuItemClicked", id); }); - function addContextMenuItemClickConnector(menuItems, browserWindowId, callback) { - menuItems.forEach((item) => { - if (item.submenu && item.submenu.items.length > 0) { - addContextMenuItemClickConnector(item.submenu.items, browserWindowId, callback); - } + Menu.setApplicationMenu(menu); + }); - if ('id' in item && item.id) { - item.click = () => { callback(item.id, browserWindowId); }; - } - }); - } + function addMenuItemClickConnector(menuItems, callback) { + menuItems.forEach((item) => { + if (item.submenu && item.submenu.items.length > 0) { + addMenuItemClickConnector(item.submenu.items, callback); + } - socket.on('menu-contextMenuPopup', (browserWindowId) => { - contextMenuItems.forEach(x => { - if (x.browserWindowId === browserWindowId) { - const browserWindow = BrowserWindow.fromId(browserWindowId); - x.menu.popup(browserWindow); - } - }); + if ("id" in item && item.id) { + item.click = () => { + callback(item.id); + }; + } }); - - socket.on('menu-setApplicationMenu', (menuItems) => { - const menu = Menu.buildFromTemplate(menuItems); - - addMenuItemClickConnector(menu.items, (id) => { - electronSocket.emit('menuItemClicked', id); - }); - - Menu.setApplicationMenu(menu); - }); - - function addMenuItemClickConnector(menuItems, callback) { - menuItems.forEach((item) => { - if (item.submenu && item.submenu.items.length > 0) { - addMenuItemClickConnector(item.submenu.items, callback); - } - - if ('id' in item && item.id) { - item.click = () => { callback(item.id); }; - } - }); - } + } }; diff --git a/src/ElectronNET.Host/api/nativeTheme.ts b/src/ElectronNET.Host/api/nativeTheme.ts index c0dda77..08d26c2 100644 --- a/src/ElectronNET.Host/api/nativeTheme.ts +++ b/src/ElectronNET.Host/api/nativeTheme.ts @@ -1,41 +1,52 @@ -import { Socket } from 'net'; -import { nativeTheme } from 'electron'; -let electronSocket; +import type { Socket } from "net"; +import { nativeTheme } from "electron"; + +let electronSocket: Socket; export = (socket: Socket) => { - electronSocket = socket; + electronSocket = socket; - socket.on('nativeTheme-shouldUseDarkColors', () => { - const shouldUseDarkColors = nativeTheme.shouldUseDarkColors; + socket.on("nativeTheme-shouldUseDarkColors", () => { + const shouldUseDarkColors = nativeTheme.shouldUseDarkColors; - electronSocket.emit('nativeTheme-shouldUseDarkColors-completed', shouldUseDarkColors); - }); - - socket.on('nativeTheme-shouldUseHighContrastColors', () => { - const shouldUseHighContrastColors = nativeTheme.shouldUseHighContrastColors; - - electronSocket.emit('nativeTheme-shouldUseHighContrastColors-completed', shouldUseHighContrastColors); - }); - - socket.on('nativeTheme-shouldUseInvertedColorScheme', () => { - const shouldUseInvertedColorScheme = nativeTheme.shouldUseInvertedColorScheme; - - electronSocket.emit('nativeTheme-shouldUseInvertedColorScheme-completed', shouldUseInvertedColorScheme); - }); - - socket.on('nativeTheme-getThemeSource', () => { - const themeSource = nativeTheme.themeSource; - - electronSocket.emit('nativeTheme-getThemeSource-completed', themeSource); - }); - - socket.on('nativeTheme-themeSource', (themeSource) => { - nativeTheme.themeSource = themeSource; - }); - - socket.on('register-nativeTheme-updated', (id) => { - nativeTheme.on('updated', () => { - electronSocket.emit('nativeTheme-updated' + id); - }); + electronSocket.emit( + "nativeTheme-shouldUseDarkColors-completed", + shouldUseDarkColors, + ); + }); + + socket.on("nativeTheme-shouldUseHighContrastColors", () => { + const shouldUseHighContrastColors = nativeTheme.shouldUseHighContrastColors; + + electronSocket.emit( + "nativeTheme-shouldUseHighContrastColors-completed", + shouldUseHighContrastColors, + ); + }); + + socket.on("nativeTheme-shouldUseInvertedColorScheme", () => { + const shouldUseInvertedColorScheme = + nativeTheme.shouldUseInvertedColorScheme; + + electronSocket.emit( + "nativeTheme-shouldUseInvertedColorScheme-completed", + shouldUseInvertedColorScheme, + ); + }); + + socket.on("nativeTheme-getThemeSource", () => { + const themeSource = nativeTheme.themeSource; + + electronSocket.emit("nativeTheme-getThemeSource-completed", themeSource); + }); + + socket.on("nativeTheme-themeSource", (themeSource) => { + nativeTheme.themeSource = themeSource; + }); + + socket.on("register-nativeTheme-updated", (id) => { + nativeTheme.on("updated", () => { + electronSocket.emit("nativeTheme-updated" + id); }); + }); }; diff --git a/src/ElectronNET.Host/api/notification.ts b/src/ElectronNET.Host/api/notification.ts index 45bc3af..e5a7a3e 100644 --- a/src/ElectronNET.Host/api/notification.ts +++ b/src/ElectronNET.Host/api/notification.ts @@ -1,58 +1,64 @@ -import { Socket } from 'net'; -import { Notification } from 'electron'; -const notifications: Electron.Notification[] = (global['notifications'] = global['notifications'] || []) as Electron.Notification[]; -let electronSocket; +import type { Socket } from "net"; +import { Notification } from "electron"; + +const notifications: Electron.Notification[] = (global["notifications"] = + global["notifications"] || []) as Electron.Notification[]; + +let electronSocket: Socket; export = (socket: Socket) => { - electronSocket = socket; - socket.on('createNotification', (options) => { - const notification = new Notification(options); - let haveEvent = false; + electronSocket = socket; + socket.on("createNotification", (options) => { + const notification = new Notification(options); + let haveEvent = false; - if (options.showID) { - haveEvent = true; - notification.on('show', () => { - electronSocket.emit('NotificationEventShow', options.showID); - }); - } + if (options.showID) { + haveEvent = true; + notification.on("show", () => { + electronSocket.emit("NotificationEventShow", options.showID); + }); + } - if (options.clickID) { - haveEvent = true; - notification.on('click', () => { - electronSocket.emit('NotificationEventClick', options.clickID); - }); - } + if (options.clickID) { + haveEvent = true; + notification.on("click", () => { + electronSocket.emit("NotificationEventClick", options.clickID); + }); + } - if (options.closeID) { - haveEvent = true; - notification.on('close', () => { - electronSocket.emit('NotificationEventClose', options.closeID); - }); - } + if (options.closeID) { + haveEvent = true; + notification.on("close", () => { + electronSocket.emit("NotificationEventClose", options.closeID); + }); + } - if (options.replyID) { - haveEvent = true; - notification.on('reply', (event, value) => { - electronSocket.emit('NotificationEventReply', [options.replyID, value]); - }); - } + if (options.replyID) { + haveEvent = true; + notification.on("reply", (event, value) => { + electronSocket.emit("NotificationEventReply", [options.replyID, value]); + }); + } - if (options.actionID) { - haveEvent = true; - notification.on('action', (event, value) => { - electronSocket.emit('NotificationEventAction', [options.actionID, value]); - }); - } + if (options.actionID) { + haveEvent = true; + notification.on("action", (event, value) => { + electronSocket.emit("NotificationEventAction", [ + options.actionID, + value, + ]); + }); + } - if (haveEvent) { - notifications.push(notification); - } + if (haveEvent) { + notifications.push(notification); + } - notification.show(); - }); + notification.show(); + }); - socket.on('notificationIsSupported', () => { - const isSupported = Notification.isSupported(); - electronSocket.emit('notificationIsSupportedCompleted', isSupported); - }); + socket.on("notificationIsSupported", () => { + const isSupported = Notification.isSupported(); + electronSocket.emit("notificationIsSupportedCompleted", isSupported); + }); }; diff --git a/src/ElectronNET.Host/api/powerMonitor.ts b/src/ElectronNET.Host/api/powerMonitor.ts index 227ef0d..b294b31 100644 --- a/src/ElectronNET.Host/api/powerMonitor.ts +++ b/src/ElectronNET.Host/api/powerMonitor.ts @@ -1,42 +1,43 @@ -import { Socket } from 'net'; -import { powerMonitor } from 'electron'; -let electronSocket; +import type { Socket } from "net"; +import { powerMonitor } from "electron"; + +let electronSocket: Socket; export = (socket: Socket) => { - electronSocket = socket; - socket.on('register-powerMonitor-lock-screen', () => { - powerMonitor.on('lock-screen', () => { - electronSocket.emit('powerMonitor-lock-screen'); - }); + electronSocket = socket; + socket.on("register-powerMonitor-lock-screen", () => { + powerMonitor.on("lock-screen", () => { + electronSocket.emit("powerMonitor-lock-screen"); }); - socket.on('register-powerMonitor-unlock-screen', () => { - powerMonitor.on('unlock-screen', () => { - electronSocket.emit('powerMonitor-unlock-screen'); - }); + }); + socket.on("register-powerMonitor-unlock-screen", () => { + powerMonitor.on("unlock-screen", () => { + electronSocket.emit("powerMonitor-unlock-screen"); }); - socket.on('register-powerMonitor-suspend', () => { - powerMonitor.on('suspend', () => { - electronSocket.emit('powerMonitor-suspend'); - }); + }); + socket.on("register-powerMonitor-suspend", () => { + powerMonitor.on("suspend", () => { + electronSocket.emit("powerMonitor-suspend"); }); - socket.on('register-powerMonitor-resume', () => { - powerMonitor.on('resume', () => { - electronSocket.emit('powerMonitor-resume'); - }); + }); + socket.on("register-powerMonitor-resume", () => { + powerMonitor.on("resume", () => { + electronSocket.emit("powerMonitor-resume"); }); - socket.on('register-powerMonitor-ac', () => { - powerMonitor.on('on-ac', () => { - electronSocket.emit('powerMonitor-ac'); - }); + }); + socket.on("register-powerMonitor-ac", () => { + powerMonitor.on("on-ac", () => { + electronSocket.emit("powerMonitor-ac"); }); - socket.on('register-powerMonitor-battery', () => { - powerMonitor.on('on-battery', () => { - electronSocket.emit('powerMonitor-battery'); - }); + }); + socket.on("register-powerMonitor-battery", () => { + powerMonitor.on("on-battery", () => { + electronSocket.emit("powerMonitor-battery"); }); - socket.on('register-powerMonitor-shutdown', () => { - powerMonitor.on('shutdown', () => { - electronSocket.emit('powerMonitor-shutdown'); - }); + }); + socket.on("register-powerMonitor-shutdown", () => { + powerMonitor.on("shutdown", () => { + electronSocket.emit("powerMonitor-shutdown"); }); + }); }; diff --git a/src/ElectronNET.Host/api/process.ts b/src/ElectronNET.Host/api/process.ts index 6d3afd0..8578e50 100644 --- a/src/ElectronNET.Host/api/process.ts +++ b/src/ElectronNET.Host/api/process.ts @@ -1,73 +1,74 @@ -import { Socket } from 'net'; -let electronSocket; +import type { Socket } from "net"; + +let electronSocket: Socket; export = (socket: Socket) => { - electronSocket = socket; + electronSocket = socket; - socket.on('process-execPath', () => { - const value = process.execPath; - electronSocket.emit('process-execPath-completed', value); - }); + socket.on("process-execPath", () => { + const value = process.execPath; + electronSocket.emit("process-execPath-completed", value); + }); - socket.on('process-argv', () => { - const value = process.argv; - electronSocket.emit('process-argv-completed', value); - }); + socket.on("process-argv", () => { + const value = process.argv; + electronSocket.emit("process-argv-completed", value); + }); - socket.on('process-type', () => { - const value = process.type; - electronSocket.emit('process-type-completed', value); - }); + socket.on("process-type", () => { + const value = process.type; + electronSocket.emit("process-type-completed", value); + }); - socket.on('process-versions', () => { - const value = process.versions; - electronSocket.emit('process-versions-completed', value); - }); + socket.on("process-versions", () => { + const value = process.versions; + electronSocket.emit("process-versions-completed", value); + }); - socket.on('process-defaultApp', () => { - if (process.defaultApp === undefined) { - electronSocket.emit('process-defaultApp-completed', false); - return; - } - electronSocket.emit('process-defaultApp-completed', process.defaultApp); - }); + socket.on("process-defaultApp", () => { + if (process.defaultApp === undefined) { + electronSocket.emit("process-defaultApp-completed", false); + return; + } + electronSocket.emit("process-defaultApp-completed", process.defaultApp); + }); - socket.on('process-isMainFrame', () => { - if (process.isMainFrame === undefined) { - electronSocket.emit('process-isMainFrame-completed', false); - return; - } - electronSocket.emit('process-isMainFrame-completed', process.isMainFrame); - }); + socket.on("process-isMainFrame", () => { + if (process.isMainFrame === undefined) { + electronSocket.emit("process-isMainFrame-completed", false); + return; + } + electronSocket.emit("process-isMainFrame-completed", process.isMainFrame); + }); - socket.on('process-resourcesPath', () => { - const value = process.resourcesPath; - electronSocket.emit('process-resourcesPath-completed', value); - }); + socket.on("process-resourcesPath", () => { + const value = process.resourcesPath; + electronSocket.emit("process-resourcesPath-completed", value); + }); - socket.on('process-upTime', () => { - let value = process.uptime(); - if (value === undefined) { - value = -1; - } - electronSocket.emit('process-upTime-completed', value); - }); + socket.on("process-upTime", () => { + let value = process.uptime(); + if (value === undefined) { + value = -1; + } + electronSocket.emit("process-upTime-completed", value); + }); - socket.on('process-pid', () => { - if (process.pid === undefined) { - electronSocket.emit('process-pid-completed', -1); - return; - } - electronSocket.emit('process-pid-completed', process.pid); - }); + socket.on("process-pid", () => { + if (process.pid === undefined) { + electronSocket.emit("process-pid-completed", -1); + return; + } + electronSocket.emit("process-pid-completed", process.pid); + }); - socket.on('process-arch', () => { - const value = process.arch; - electronSocket.emit('process-arch-completed', value); - }); + socket.on("process-arch", () => { + const value = process.arch; + electronSocket.emit("process-arch-completed", value); + }); - socket.on('process-platform', () => { - const value = process.platform; - electronSocket.emit('process-platform-completed', value); - }) + socket.on("process-platform", () => { + const value = process.platform; + electronSocket.emit("process-platform-completed", value); + }); }; diff --git a/src/ElectronNET.Host/api/screen.ts b/src/ElectronNET.Host/api/screen.ts index 61289cf..73f2ca1 100644 --- a/src/ElectronNET.Host/api/screen.ts +++ b/src/ElectronNET.Host/api/screen.ts @@ -1,55 +1,59 @@ -import { Socket } from 'net'; -import { screen } from 'electron'; -let electronSocket; +import type { Socket } from "net"; +import { screen } from "electron"; + +let electronSocket: Socket; export = (socket: Socket) => { - electronSocket = socket; + electronSocket = socket; - socket.on('register-screen-display-added', (id) => { - screen.on('display-added', (event, display) => { - electronSocket.emit('screen-display-added' + id, display); - }); + socket.on("register-screen-display-added", (id) => { + screen.on("display-added", (event, display) => { + electronSocket.emit("screen-display-added" + id, display); }); + }); - socket.on('register-screen-display-removed', (id) => { - screen.on('display-removed', (event, display) => { - electronSocket.emit('screen-display-removed' + id, display); - }); + socket.on("register-screen-display-removed", (id) => { + screen.on("display-removed", (event, display) => { + electronSocket.emit("screen-display-removed" + id, display); }); + }); - socket.on('register-screen-display-metrics-changed', (id) => { - screen.on('display-metrics-changed', (event, display, changedMetrics) => { - electronSocket.emit('screen-display-metrics-changed' + id, [display, changedMetrics]); - }); + socket.on("register-screen-display-metrics-changed", (id) => { + screen.on("display-metrics-changed", (event, display, changedMetrics) => { + electronSocket.emit("screen-display-metrics-changed" + id, [ + display, + changedMetrics, + ]); }); + }); - socket.on('screen-getCursorScreenPoint', () => { - const point = screen.getCursorScreenPoint(); - electronSocket.emit('screen-getCursorScreenPoint-completed', point); - }); + socket.on("screen-getCursorScreenPoint", () => { + const point = screen.getCursorScreenPoint(); + electronSocket.emit("screen-getCursorScreenPoint-completed", point); + }); - socket.on('screen-getMenuBarWorkArea', () => { - const height = screen.getPrimaryDisplay().workArea; - electronSocket.emit('screen-getMenuBarWorkArea-completed', height); - }); + socket.on("screen-getMenuBarWorkArea", () => { + const height = screen.getPrimaryDisplay().workArea; + electronSocket.emit("screen-getMenuBarWorkArea-completed", height); + }); - socket.on('screen-getPrimaryDisplay', () => { - const display = screen.getPrimaryDisplay(); - electronSocket.emit('screen-getPrimaryDisplay-completed', display); - }); + socket.on("screen-getPrimaryDisplay", () => { + const display = screen.getPrimaryDisplay(); + electronSocket.emit("screen-getPrimaryDisplay-completed", display); + }); - socket.on('screen-getAllDisplays', () => { - const display = screen.getAllDisplays(); - electronSocket.emit('screen-getAllDisplays-completed', display); - }); + socket.on("screen-getAllDisplays", () => { + const display = screen.getAllDisplays(); + electronSocket.emit("screen-getAllDisplays-completed", display); + }); - socket.on('screen-getDisplayNearestPoint', (point) => { - const display = screen.getDisplayNearestPoint(point); - electronSocket.emit('screen-getDisplayNearestPoint-completed', display); - }); + socket.on("screen-getDisplayNearestPoint", (point) => { + const display = screen.getDisplayNearestPoint(point); + electronSocket.emit("screen-getDisplayNearestPoint-completed", display); + }); - socket.on('screen-getDisplayMatching', (rectangle) => { - const display = screen.getDisplayMatching(rectangle); - electronSocket.emit('screen-getDisplayMatching-completed', display); - }); + socket.on("screen-getDisplayMatching", (rectangle) => { + const display = screen.getDisplayMatching(rectangle); + electronSocket.emit("screen-getDisplayMatching-completed", display); + }); }; diff --git a/src/ElectronNET.Host/api/shell.ts b/src/ElectronNET.Host/api/shell.ts index eac4dc4..35f340a 100644 --- a/src/ElectronNET.Host/api/shell.ts +++ b/src/ElectronNET.Host/api/shell.ts @@ -1,63 +1,64 @@ -import { Socket } from 'net'; -import { shell } from 'electron'; -let electronSocket; +import type { Socket } from "net"; +import { shell } from "electron"; + +let electronSocket: Socket; export = (socket: Socket) => { - electronSocket = socket; - socket.on('shell-showItemInFolder', (fullPath) => { - shell.showItemInFolder(fullPath); + electronSocket = socket; + socket.on("shell-showItemInFolder", (fullPath) => { + shell.showItemInFolder(fullPath); - electronSocket.emit('shell-showItemInFolderCompleted'); - }); + electronSocket.emit("shell-showItemInFolderCompleted"); + }); - socket.on('shell-openPath', async (path) => { - const errorMessage = await shell.openPath(path); + socket.on("shell-openPath", async (path) => { + const errorMessage = await shell.openPath(path); - electronSocket.emit('shell-openPathCompleted', errorMessage); - }); + electronSocket.emit("shell-openPathCompleted", errorMessage); + }); - socket.on('shell-openExternal', async (url, options) => { - let result = ''; + socket.on("shell-openExternal", async (url, options) => { + let result = ""; - if (options) { - await shell.openExternal(url, options).catch(e => { - result = e.message; - }); - } else { - await shell.openExternal(url).catch((e) => { - result = e.message; - }); - } + if (options) { + await shell.openExternal(url, options).catch((e) => { + result = e.message; + }); + } else { + await shell.openExternal(url).catch((e) => { + result = e.message; + }); + } - electronSocket.emit('shell-openExternalCompleted', result); - }); + electronSocket.emit("shell-openExternalCompleted", result); + }); - socket.on('shell-trashItem', async (fullPath, deleteOnFail) => { - let success = false; + socket.on("shell-trashItem", async (fullPath, deleteOnFail) => { + let success = false; - try { - await shell.trashItem(fullPath); - success = true; - } catch (error) { - success = false; - } + try { + await shell.trashItem(fullPath); + success = true; + } catch (error) { + success = false; + } - electronSocket.emit('shell-trashItem-completed', success); - }); + electronSocket.emit("shell-trashItem-completed", success); + }); - socket.on('shell-beep', () => { - shell.beep(); - }); + socket.on("shell-beep", () => { + shell.beep(); + }); - socket.on('shell-writeShortcutLink', (shortcutPath, operation, options) => { - const success = shell.writeShortcutLink(shortcutPath, operation, options); + socket.on("shell-writeShortcutLink", (shortcutPath, operation, options) => { + const success = shell.writeShortcutLink(shortcutPath, operation, options); - electronSocket.emit('shell-writeShortcutLinkCompleted', success); - }); + electronSocket.emit("shell-writeShortcutLinkCompleted", success); + }); - socket.on('shell-readShortcutLink', (shortcutPath) => { - const shortcutDetails = shell.readShortcutLink(shortcutPath); + socket.on("shell-readShortcutLink", (shortcutPath) => { + const shortcutDetails = shell.readShortcutLink(shortcutPath); - electronSocket.emit('shell-readShortcutLinkCompleted', shortcutDetails); - }); + electronSocket.emit("shell-readShortcutLinkCompleted", shortcutDetails); + }); }; diff --git a/src/ElectronNET.Host/api/tray.ts b/src/ElectronNET.Host/api/tray.ts index 9c10102..99a8acd 100644 --- a/src/ElectronNET.Host/api/tray.ts +++ b/src/ElectronNET.Host/api/tray.ts @@ -1,159 +1,174 @@ -import { Socket } from 'net'; -import { Menu, Tray, nativeImage } from 'electron'; -let tray: { value: Electron.Tray } = (global['$tray'] = global['tray'] || { value: null }); -let electronSocket; +import type { Socket } from "net"; +import { Menu, Tray, nativeImage } from "electron"; + +let tray: { value: Electron.Tray } = (global["$tray"] = global["tray"] || { + value: null, +}); + +let electronSocket: Socket; export = (socket: Socket) => { - electronSocket = socket; - socket.on('register-tray-click', (id) => { - if (tray.value) { - tray.value.on('click', (event, bounds) => { - electronSocket.emit('tray-click' + id, [(event).__proto__, bounds]); - }); - } - }); - - socket.on('register-tray-right-click', (id) => { - if (tray.value) { - tray.value.on('right-click', (event, bounds) => { - electronSocket.emit('tray-right-click' + id, [(event).__proto__, bounds]); - }); - } - }); - - socket.on('register-tray-double-click', (id) => { - if (tray.value) { - tray.value.on('double-click', (event, bounds) => { - electronSocket.emit('tray-double-click' + id, [(event).__proto__, bounds]); - }); - } - }); - - socket.on('register-tray-balloon-show', (id) => { - if (tray.value) { - tray.value.on('balloon-show', () => { - electronSocket.emit('tray-balloon-show' + id); - }); - } - }); - - socket.on('register-tray-balloon-click', (id) => { - if (tray.value) { - tray.value.on('balloon-click', () => { - electronSocket.emit('tray-balloon-click' + id); - }); - } - }); - - socket.on('register-tray-balloon-closed', (id) => { - if (tray.value) { - tray.value.on('balloon-closed', () => { - electronSocket.emit('tray-balloon-closed' + id); - }); - } - }); - - socket.on('create-tray', (image, menuItems) => { - const trayIcon = nativeImage.createFromPath(image); - - tray.value = new Tray(trayIcon); - - if (menuItems) { - applyContextMenu(menuItems); - } - }); - - socket.on('tray-destroy', () => { - if (tray.value) { - tray.value.destroy(); - } - }); - - socket.on('set-contextMenu', (menuItems) => { - if (menuItems && tray.value) { - applyContextMenu(menuItems); - } - }); - - socket.on('tray-setImage', (image) => { - if (tray.value) { - tray.value.setImage(image); - } - }); - - socket.on('tray-setPressedImage', (image) => { - if (tray.value) { - const img = nativeImage.createFromPath(image); - tray.value.setPressedImage(img); - } - }); - - socket.on('tray-setToolTip', (toolTip) => { - if (tray.value) { - tray.value.setToolTip(toolTip); - } - }); - - socket.on('tray-setTitle', (title) => { - if (tray.value) { - tray.value.setTitle(title); - } - }); - - socket.on('tray-displayBalloon', (options) => { - if (tray.value) { - tray.value.displayBalloon(options); - } - }); - - socket.on('tray-isDestroyed', () => { - if (tray.value) { - const isDestroyed = tray.value.isDestroyed(); - electronSocket.emit('tray-isDestroyedCompleted', isDestroyed); - } - }); - - socket.on('register-tray-on-event', (eventName, listenerName) => { - if (tray.value){ - tray.value.on(eventName, (...args: any[]) => { - if (args.length > 1) { - electronSocket.emit(listenerName, args[1]); - } else { - electronSocket.emit(listenerName); - } - }); - } - }); - - socket.on('register-tray-once-event', (eventName, listenerName) => { - if (tray.value){ - tray.value.once(eventName, (...args: any[]) => { - if (args.length > 1) { - electronSocket.emit(listenerName, args[1]); - } else { - electronSocket.emit(listenerName); - } - }); - } - }); - - function applyContextMenu(menuItems) { - const menu = Menu.buildFromTemplate(menuItems); - addMenuItemClickConnector(menu.items, (id) => { - electronSocket.emit('trayMenuItemClicked', id); - }); - tray.value.setContextMenu(menu); + electronSocket = socket; + socket.on("register-tray-click", (id) => { + if (tray.value) { + tray.value.on("click", (event, bounds) => { + electronSocket.emit("tray-click" + id, [ + (event).__proto__, + bounds, + ]); + }); } + }); - function addMenuItemClickConnector(menuItems, callback) { - menuItems.forEach((item) => { - if (item.submenu && item.submenu.items.length > 0) { - addMenuItemClickConnector(item.submenu.items, callback); - } - - if ('id' in item && item.id) { - item.click = () => { callback(item.id); }; - } - }); + socket.on("register-tray-right-click", (id) => { + if (tray.value) { + tray.value.on("right-click", (event, bounds) => { + electronSocket.emit("tray-right-click" + id, [ + (event).__proto__, + bounds, + ]); + }); } + }); + + socket.on("register-tray-double-click", (id) => { + if (tray.value) { + tray.value.on("double-click", (event, bounds) => { + electronSocket.emit("tray-double-click" + id, [ + (event).__proto__, + bounds, + ]); + }); + } + }); + + socket.on("register-tray-balloon-show", (id) => { + if (tray.value) { + tray.value.on("balloon-show", () => { + electronSocket.emit("tray-balloon-show" + id); + }); + } + }); + + socket.on("register-tray-balloon-click", (id) => { + if (tray.value) { + tray.value.on("balloon-click", () => { + electronSocket.emit("tray-balloon-click" + id); + }); + } + }); + + socket.on("register-tray-balloon-closed", (id) => { + if (tray.value) { + tray.value.on("balloon-closed", () => { + electronSocket.emit("tray-balloon-closed" + id); + }); + } + }); + + socket.on("create-tray", (image, menuItems) => { + const trayIcon = nativeImage.createFromPath(image); + + tray.value = new Tray(trayIcon); + + if (menuItems) { + applyContextMenu(menuItems); + } + }); + + socket.on("tray-destroy", () => { + if (tray.value) { + tray.value.destroy(); + } + }); + + socket.on("set-contextMenu", (menuItems) => { + if (menuItems && tray.value) { + applyContextMenu(menuItems); + } + }); + + socket.on("tray-setImage", (image) => { + if (tray.value) { + tray.value.setImage(image); + } + }); + + socket.on("tray-setPressedImage", (image) => { + if (tray.value) { + const img = nativeImage.createFromPath(image); + tray.value.setPressedImage(img); + } + }); + + socket.on("tray-setToolTip", (toolTip) => { + if (tray.value) { + tray.value.setToolTip(toolTip); + } + }); + + socket.on("tray-setTitle", (title) => { + if (tray.value) { + tray.value.setTitle(title); + } + }); + + socket.on("tray-displayBalloon", (options) => { + if (tray.value) { + tray.value.displayBalloon(options); + } + }); + + socket.on("tray-isDestroyed", () => { + if (tray.value) { + const isDestroyed = tray.value.isDestroyed(); + electronSocket.emit("tray-isDestroyedCompleted", isDestroyed); + } + }); + + socket.on("register-tray-on-event", (eventName, listenerName) => { + if (tray.value) { + tray.value.on(eventName, (...args: any[]) => { + if (args.length > 1) { + electronSocket.emit(listenerName, args[1]); + } else { + electronSocket.emit(listenerName); + } + }); + } + }); + + socket.on("register-tray-once-event", (eventName, listenerName) => { + if (tray.value) { + tray.value.once(eventName, (...args: any[]) => { + if (args.length > 1) { + electronSocket.emit(listenerName, args[1]); + } else { + electronSocket.emit(listenerName); + } + }); + } + }); + + function applyContextMenu(menuItems) { + const menu = Menu.buildFromTemplate(menuItems); + addMenuItemClickConnector(menu.items, (id) => { + electronSocket.emit("trayMenuItemClicked", id); + }); + tray.value.setContextMenu(menu); + } + + function addMenuItemClickConnector(menuItems, callback) { + menuItems.forEach((item) => { + if (item.submenu && item.submenu.items.length > 0) { + addMenuItemClickConnector(item.submenu.items, callback); + } + + if ("id" in item && item.id) { + item.click = () => { + callback(item.id); + }; + } + }); + } }; diff --git a/src/ElectronNET.Host/api/webContents.ts b/src/ElectronNET.Host/api/webContents.ts index fe54a52..4246652 100644 --- a/src/ElectronNET.Host/api/webContents.ts +++ b/src/ElectronNET.Host/api/webContents.ts @@ -1,8 +1,10 @@ -import { Socket } from "net"; -import {BrowserWindow, BrowserView} from "electron"; +import * as fs from "fs"; +import type { Socket } from "net"; +import { BrowserWindow, BrowserView } from "electron"; + import { browserViewMediateService } from "./browserView"; -const fs = require("fs"); -let electronSocket; + +let electronSocket: Socket; export = (socket: Socket) => { electronSocket = socket; @@ -68,7 +70,7 @@ export = (socket: Socket) => { errorCode, validatedUrl, }); - } + }, ); }); @@ -136,17 +138,17 @@ export = (socket: Socket) => { async (id, code, userGesture = false) => { const result = await getWindowById(id).webContents.executeJavaScript( code, - userGesture + userGesture, ); electronSocket.emit("webContents-executeJavaScript-completed", result); - } + }, ); socket.on("webContents-getUrl", function (id) { const browserWindow = getWindowById(id); electronSocket.emit( "webContents-getUrl" + id, - browserWindow.webContents.getURL() + browserWindow.webContents.getURL(), ); }); @@ -155,7 +157,7 @@ export = (socket: Socket) => { (id, domains) => { const browserWindow = getWindowById(id); browserWindow.webContents.session.allowNTLMCredentialsForDomains(domains); - } + }, ); socket.on("webContents-session-clearAuthCache", async (...args) => { @@ -194,7 +196,7 @@ export = (socket: Socket) => { await browserWindow.webContents.session.clearHostResolverCache(); electronSocket.emit( - "webContents-session-clearHostResolverCache-completed" + guid + "webContents-session-clearHostResolverCache-completed" + guid, ); }); @@ -203,7 +205,7 @@ export = (socket: Socket) => { await browserWindow.webContents.session.clearStorageData({}); electronSocket.emit( - "webContents-session-clearStorageData-completed" + guid + "webContents-session-clearStorageData-completed" + guid, ); }); @@ -214,9 +216,9 @@ export = (socket: Socket) => { await browserWindow.webContents.session.clearStorageData(options); electronSocket.emit( - "webContents-session-clearStorageData-options-completed" + guid + "webContents-session-clearStorageData-options-completed" + guid, ); - } + }, ); socket.on("webContents-session-createInterruptedDownload", (id, options) => { @@ -241,13 +243,12 @@ export = (socket: Socket) => { socket.on("webContents-session-getBlobData", async (id, identifier, guid) => { const browserWindow = getWindowById(id); - const buffer = await browserWindow.webContents.session.getBlobData( - identifier - ); + const buffer = + await browserWindow.webContents.session.getBlobData(identifier); electronSocket.emit( "webContents-session-getBlobData-completed" + guid, - buffer.buffer + buffer.buffer, ); }); @@ -257,7 +258,7 @@ export = (socket: Socket) => { electronSocket.emit( "webContents-session-getCacheSize-completed" + guid, - size + size, ); }); @@ -267,7 +268,7 @@ export = (socket: Socket) => { electronSocket.emit( "webContents-session-getPreloads-completed" + guid, - preloads + preloads, ); }); @@ -277,7 +278,7 @@ export = (socket: Socket) => { electronSocket.emit( "webContents-session-getUserAgent-completed" + guid, - userAgent + userAgent, ); }); @@ -287,7 +288,7 @@ export = (socket: Socket) => { electronSocket.emit( "webContents-session-resolveProxy-completed" + guid, - proxy + proxy, ); }); @@ -314,9 +315,9 @@ export = (socket: Socket) => { const browserWindow = getWindowById(id); browserWindow.webContents.session.setUserAgent( userAgent, - acceptLanguages + acceptLanguages, ); - } + }, ); socket.on( @@ -328,17 +329,17 @@ export = (socket: Socket) => { session.webRequest.onBeforeRequest(filter, (details, callback) => { socket.emit( `webContents-session-webRequest-onBeforeRequest${id}`, - details + details, ); // Listen for a response from C# to continue the request electronSocket.once( `webContents-session-webRequest-onBeforeRequest-response${id}`, (response) => { callback(response); - } + }, ); }); - } + }, ); socket.on("register-webContents-session-cookies-changed", (id) => { @@ -353,7 +354,7 @@ export = (socket: Socket) => { cause, removed, ]); - } + }, ); }); @@ -363,7 +364,7 @@ export = (socket: Socket) => { electronSocket.emit( "webContents-session-cookies-get-completed" + guid, - cookies + cookies, ); }); @@ -381,9 +382,9 @@ export = (socket: Socket) => { await browserWindow.webContents.session.cookies.remove(url, name); electronSocket.emit( - "webContents-session-cookies-remove-completed" + guid + "webContents-session-cookies-remove-completed" + guid, ); - } + }, ); socket.on("webContents-session-cookies-flushStore", async (id, guid) => { @@ -391,7 +392,7 @@ export = (socket: Socket) => { await browserWindow.webContents.session.cookies.flushStore(); electronSocket.emit( - "webContents-session-cookies-flushStore-completed" + guid + "webContents-session-cookies-flushStore-completed" + guid, ); }); @@ -441,7 +442,7 @@ export = (socket: Socket) => { electronSocket.emit( "webContents-session-getAllExtensions-completed", - chromeExtensionInfo + chromeExtensionInfo, ); }); @@ -456,87 +457,108 @@ export = (socket: Socket) => { const browserWindow = getWindowById(id); const extension = await browserWindow.webContents.session.loadExtension( path, - { allowFileAccess: allowFileAccess } + { allowFileAccess: allowFileAccess }, ); electronSocket.emit( "webContents-session-loadExtension-completed", - extension + extension, ); - } + }, ); - socket.on('webContents-getZoomFactor', (id) => { - const browserWindow = getWindowById(id); - const text = browserWindow.webContents.getZoomFactor(); - electronSocket.emit('webContents-getZoomFactor-completed', text); - }); + socket.on("webContents-getZoomFactor", (id) => { + const browserWindow = getWindowById(id); + const text = browserWindow.webContents.getZoomFactor(); + electronSocket.emit("webContents-getZoomFactor-completed", text); + }); - socket.on('webContents-setZoomFactor', (id, factor) => { - const browserWindow = getWindowById(id); - browserWindow.webContents.setZoomFactor(factor); - }); + socket.on("webContents-setZoomFactor", (id, factor) => { + const browserWindow = getWindowById(id); + browserWindow.webContents.setZoomFactor(factor); + }); - socket.on('webContents-getZoomLevel', (id) => { - const browserWindow = getWindowById(id); - const content = browserWindow.webContents.getZoomLevel(); - electronSocket.emit('webContents-getZoomLevel-completed', content); - }); + socket.on("webContents-getZoomLevel", (id) => { + const browserWindow = getWindowById(id); + const content = browserWindow.webContents.getZoomLevel(); + electronSocket.emit("webContents-getZoomLevel-completed", content); + }); - socket.on('webContents-setZoomLevel', (id, level) => { - const browserWindow = getWindowById(id); - browserWindow.webContents.setZoomLevel(level); - }); + socket.on("webContents-setZoomLevel", (id, level) => { + const browserWindow = getWindowById(id); + browserWindow.webContents.setZoomLevel(level); + }); - socket.on('webContents-setVisualZoomLevelLimits', async (id, minimumLevel, maximumLevel) => { - const browserWindow = getWindowById(id); - await browserWindow.webContents.setVisualZoomLevelLimits(minimumLevel, maximumLevel); - electronSocket.emit('webContents-setVisualZoomLevelLimits-completed'); - }); + socket.on( + "webContents-setVisualZoomLevelLimits", + async (id, minimumLevel, maximumLevel) => { + const browserWindow = getWindowById(id); + await browserWindow.webContents.setVisualZoomLevelLimits( + minimumLevel, + maximumLevel, + ); + electronSocket.emit("webContents-setVisualZoomLevelLimits-completed"); + }, + ); - socket.on("webContents-toggleDevTools", (id) => { - getWindowById(id).webContents.toggleDevTools(); - }); + socket.on("webContents-toggleDevTools", (id) => { + getWindowById(id).webContents.toggleDevTools(); + }); - socket.on("webContents-closeDevTools", (id) => { - getWindowById(id).webContents.closeDevTools(); - }); + socket.on("webContents-closeDevTools", (id) => { + getWindowById(id).webContents.closeDevTools(); + }); - socket.on("webContents-isDevToolsOpened", function (id) { - const browserWindow = getWindowById(id); - electronSocket.emit('webContents-isDevToolsOpened-completed', browserWindow.webContents.isDevToolsOpened()); - }); + socket.on("webContents-isDevToolsOpened", function (id) { + const browserWindow = getWindowById(id); + electronSocket.emit( + "webContents-isDevToolsOpened-completed", + browserWindow.webContents.isDevToolsOpened(), + ); + }); - socket.on("webContents-isDevToolsFocused", function (id) { - const browserWindow = getWindowById(id); - electronSocket.emit('webContents-isDevToolsFocused-completed', browserWindow.webContents.isDevToolsFocused()); - }); + socket.on("webContents-isDevToolsFocused", function (id) { + const browserWindow = getWindowById(id); + electronSocket.emit( + "webContents-isDevToolsFocused-completed", + browserWindow.webContents.isDevToolsFocused(), + ); + }); - socket.on("webContents-setAudioMuted", (id, muted) => { - getWindowById(id).webContents.setAudioMuted(muted); - }); + socket.on("webContents-setAudioMuted", (id, muted) => { + getWindowById(id).webContents.setAudioMuted(muted); + }); - socket.on("webContents-isAudioMuted", function (id) { - const browserWindow = getWindowById(id); - electronSocket.emit('webContents-isAudioMuted-completed', browserWindow.webContents.isAudioMuted()); - }); + socket.on("webContents-isAudioMuted", function (id) { + const browserWindow = getWindowById(id); + electronSocket.emit( + "webContents-isAudioMuted-completed", + browserWindow.webContents.isAudioMuted(), + ); + }); - socket.on("webContents-isCurrentlyAudible", function (id) { - const browserWindow = getWindowById(id); - electronSocket.emit('webContents-isCurrentlyAudible-completed', browserWindow.webContents.isCurrentlyAudible()); - }); + socket.on("webContents-isCurrentlyAudible", function (id) { + const browserWindow = getWindowById(id); + electronSocket.emit( + "webContents-isCurrentlyAudible-completed", + browserWindow.webContents.isCurrentlyAudible(), + ); + }); - socket.on("webContents-getUserAgent", function (id) { - const browserWindow = getWindowById(id); - electronSocket.emit('webContents-getUserAgent-completed', browserWindow.webContents.getUserAgent()); - }); + socket.on("webContents-getUserAgent", function (id) { + const browserWindow = getWindowById(id); + electronSocket.emit( + "webContents-getUserAgent-completed", + browserWindow.webContents.getUserAgent(), + ); + }); - socket.on("webContents-setUserAgent", (id, userAgent) => { - getWindowById(id).webContents.setUserAgent(userAgent); - }); + socket.on("webContents-setUserAgent", (id, userAgent) => { + getWindowById(id).webContents.setUserAgent(userAgent); + }); - function getWindowById( - id: number + function getWindowById( + id: number, ): Electron.BrowserWindow | Electron.BrowserView { if (id >= 1000) { return browserViewMediateService(id - 1000);