From 0a73290714a0ae41fafb42bd667a3881ef7fe689 Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Fri, 2 Dec 2022 12:45:09 +0100 Subject: [PATCH] [SM-329] Merge libs/electron into desktop (#3989) --- .eslintrc.json | 12 +- .github/whitelist-capital-letters.txt | 10 - .../accessibility-cookie.component.ts | 3 +- .../src/app/accounts/settings.component.ts | 2 +- apps/desktop/src/app/main.ts | 2 +- apps/desktop/src/app/send/send.component.ts | 2 +- .../src/app/services/services.module.ts | 12 +- apps/desktop/src/app/vault/vault.component.ts | 2 +- apps/desktop/src/main.ts | 22 +- .../main/biometric/biometric.windows.main.ts | 3 +- apps/desktop/src/main/menu/menu.about.ts | 5 +- apps/desktop/src/main/menu/menu.account.ts | 3 +- apps/desktop/src/main/menu/menu.bitwarden.ts | 5 +- apps/desktop/src/main/menu/menu.file.ts | 5 +- apps/desktop/src/main/menu/menu.first.ts | 5 +- apps/desktop/src/main/menu/menu.help.ts | 3 +- apps/desktop/src/main/menu/menu.main.ts | 91 ++++++- apps/desktop/src/main/menu/menu.window.ts | 5 +- apps/desktop/src/main/menu/menubar.ts | 7 +- .../desktop/src/main/native-messaging.main.ts | 3 +- apps/desktop/src/main/power-monitor.main.ts | 3 +- .../desktop/src/main}/tray.main.ts | 0 .../desktop/src/main}/updater.main.ts | 23 +- .../desktop/src/main}/window.main.ts | 2 +- .../src/services/electron-crypto.service.ts | 0 .../src/services/electron-log.service.spec.ts | 2 +- .../src/services/electron-log.service.ts | 0 .../electron-main-messaging.service.ts | 2 +- .../electron-platform-utils.service.ts | 0 .../electron-renderer-messaging.service.ts | 0 ...lectron-renderer-secure-storage.service.ts | 0 .../electron-renderer-storage.service.ts | 0 .../src/services/electron-storage.service.ts | 0 .../spec => apps/desktop/src}/utils.spec.ts | 2 +- {libs/electron => apps/desktop}/src/utils.ts | 0 apps/desktop/tsconfig.json | 3 +- jest.config.js | 1 - libs/electron/jest.config.js | 14 -- libs/electron/package.json | 23 -- libs/electron/src/baseMenu.ts | 225 ------------------ libs/electron/src/globals.d.ts | 0 libs/electron/tsconfig.json | 5 - libs/electron/tsconfig.spec.json | 3 - libs/shared/tsconfig.libs.json | 1 - package-lock.json | 18 -- tsconfig.eslint.json | 1 - tsconfig.json | 1 - 47 files changed, 146 insertions(+), 385 deletions(-) rename {libs/electron/src => apps/desktop/src/main}/tray.main.ts (100%) rename {libs/electron/src => apps/desktop/src/main}/updater.main.ts (86%) rename {libs/electron/src => apps/desktop/src/main}/window.main.ts (99%) rename libs/electron/src/services/electronCrypto.service.ts => apps/desktop/src/services/electron-crypto.service.ts (100%) rename libs/electron/spec/services/electronLog.service.spec.ts => apps/desktop/src/services/electron-log.service.spec.ts (75%) rename libs/electron/src/services/electronLog.service.ts => apps/desktop/src/services/electron-log.service.ts (100%) rename libs/electron/src/services/electronMainMessaging.service.ts => apps/desktop/src/services/electron-main-messaging.service.ts (97%) rename libs/electron/src/services/electronPlatformUtils.service.ts => apps/desktop/src/services/electron-platform-utils.service.ts (100%) rename libs/electron/src/services/electronRendererMessaging.service.ts => apps/desktop/src/services/electron-renderer-messaging.service.ts (100%) rename libs/electron/src/services/electronRendererSecureStorage.service.ts => apps/desktop/src/services/electron-renderer-secure-storage.service.ts (100%) rename libs/electron/src/services/electronRendererStorage.service.ts => apps/desktop/src/services/electron-renderer-storage.service.ts (100%) rename libs/electron/src/services/electronStorage.service.ts => apps/desktop/src/services/electron-storage.service.ts (100%) rename {libs/electron/spec => apps/desktop/src}/utils.spec.ts (96%) rename {libs/electron => apps/desktop}/src/utils.ts (100%) delete mode 100644 libs/electron/jest.config.js delete mode 100644 libs/electron/package.json delete mode 100644 libs/electron/src/baseMenu.ts delete mode 100644 libs/electron/src/globals.d.ts delete mode 100644 libs/electron/tsconfig.json delete mode 100644 libs/electron/tsconfig.spec.json diff --git a/.eslintrc.json b/.eslintrc.json index 6a5fc5b83f..6bcea9dd04 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -86,7 +86,7 @@ "error", { "zones": [ - // Do not allow angular/node/electron code to be imported into common + // Do not allow angular/node code to be imported into common { "target": "./libs/common/**/*", "from": "./libs/angular/**/*" @@ -94,10 +94,6 @@ { "target": "./libs/common/**/*", "from": "./libs/node/**/*" - }, - { - "target": "./libs/common/**/*", - "from": "./libs/electron/**/*" } ] } @@ -131,12 +127,6 @@ "rules": { "no-restricted-imports": ["error", { "patterns": ["@bitwarden/node/*", "src/**/*"] }] } - }, - { - "files": ["libs/electron/src/**/*.ts"], - "rules": { - "no-restricted-imports": ["error", { "patterns": ["@bitwarden/electron/*", "src/**/*"] }] - } } ] } diff --git a/.github/whitelist-capital-letters.txt b/.github/whitelist-capital-letters.txt index 613e70ee2c..af82f6b811 100644 --- a/.github/whitelist-capital-letters.txt +++ b/.github/whitelist-capital-letters.txt @@ -152,16 +152,6 @@ ./libs/common/src/services/bitwardenFileUpload.service.ts ./libs/common/src/services/webCryptoFunction.service.ts ./libs/common/src/interfaces/IEncrypted.ts -./libs/electron/spec/services/electronLog.service.spec.ts -./libs/electron/src/baseMenu.ts -./libs/electron/src/services/electronLog.service.ts -./libs/electron/src/services/electronStorage.service.ts -./libs/electron/src/services/electronRendererMessaging.service.ts -./libs/electron/src/services/electronMainMessaging.service.ts -./libs/electron/src/services/electronPlatformUtils.service.ts -./libs/electron/src/services/electronRendererStorage.service.ts -./libs/electron/src/services/electronCrypto.service.ts -./libs/electron/src/services/electronRendererSecureStorage.service.ts ./README.md ./LICENSE_BITWARDEN.txt ./CONTRIBUTING.md diff --git a/apps/desktop/src/app/accounts/accessibility-cookie.component.ts b/apps/desktop/src/app/accounts/accessibility-cookie.component.ts index 33c8243748..a8173400ed 100644 --- a/apps/desktop/src/app/accounts/accessibility-cookie.component.ts +++ b/apps/desktop/src/app/accounts/accessibility-cookie.component.ts @@ -7,7 +7,8 @@ import { EnvironmentService } from "@bitwarden/common/abstractions/environment.s import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service"; import { Utils } from "@bitwarden/common/misc/utils"; -import { getCookie } from "@bitwarden/electron/utils"; + +import { getCookie } from "../../utils"; const BroadcasterSubscriptionId = "AccessibilityCookieComponent"; diff --git a/apps/desktop/src/app/accounts/settings.component.ts b/apps/desktop/src/app/accounts/settings.component.ts index c0be20dc77..b07a049f18 100644 --- a/apps/desktop/src/app/accounts/settings.component.ts +++ b/apps/desktop/src/app/accounts/settings.component.ts @@ -14,9 +14,9 @@ import { DeviceType } from "@bitwarden/common/enums/deviceType"; import { StorageLocation } from "@bitwarden/common/enums/storageLocation"; import { ThemeType } from "@bitwarden/common/enums/themeType"; import { Utils } from "@bitwarden/common/misc/utils"; -import { isWindowsStore } from "@bitwarden/electron/utils"; import { flagEnabled } from "../../flags"; +import { isWindowsStore } from "../../utils"; import { SetPinComponent } from "../components/set-pin.component"; @Component({ diff --git a/apps/desktop/src/app/main.ts b/apps/desktop/src/app/main.ts index 4db6a9419b..9385f859b1 100644 --- a/apps/desktop/src/app/main.ts +++ b/apps/desktop/src/app/main.ts @@ -1,7 +1,7 @@ import { enableProdMode } from "@angular/core"; import { platformBrowserDynamic } from "@angular/platform-browser-dynamic"; -import { isDev } from "@bitwarden/electron/utils"; +import { isDev } from "../utils"; // tslint:disable-next-line require("../scss/styles.scss"); diff --git a/apps/desktop/src/app/send/send.component.ts b/apps/desktop/src/app/send/send.component.ts index 95dfb83f36..4c96a93ae4 100644 --- a/apps/desktop/src/app/send/send.component.ts +++ b/apps/desktop/src/app/send/send.component.ts @@ -10,8 +10,8 @@ import { PolicyService } from "@bitwarden/common/abstractions/policy/policy.serv import { SearchService } from "@bitwarden/common/abstractions/search.service"; import { SendService } from "@bitwarden/common/abstractions/send.service"; import { SendView } from "@bitwarden/common/models/view/send.view"; -import { invokeMenu, RendererMenuItem } from "@bitwarden/electron/utils"; +import { invokeMenu, RendererMenuItem } from "../../utils"; import { SearchBarService } from "../layout/search/search-bar.service"; import { AddEditComponent } from "./add-edit.component"; diff --git a/apps/desktop/src/app/services/services.module.ts b/apps/desktop/src/app/services/services.module.ts index cd07ce93d4..8696bd0b39 100644 --- a/apps/desktop/src/app/services/services.module.ts +++ b/apps/desktop/src/app/services/services.module.ts @@ -39,14 +39,14 @@ import { GlobalState } from "@bitwarden/common/models/domain/global-state"; import { LoginService } from "@bitwarden/common/services/login.service"; import { MemoryStorageService } from "@bitwarden/common/services/memoryStorage.service"; import { SystemService } from "@bitwarden/common/services/system.service"; -import { ElectronCryptoService } from "@bitwarden/electron/services/electronCrypto.service"; -import { ElectronLogService } from "@bitwarden/electron/services/electronLog.service"; -import { ElectronPlatformUtilsService } from "@bitwarden/electron/services/electronPlatformUtils.service"; -import { ElectronRendererMessagingService } from "@bitwarden/electron/services/electronRendererMessaging.service"; -import { ElectronRendererSecureStorageService } from "@bitwarden/electron/services/electronRendererSecureStorage.service"; -import { ElectronRendererStorageService } from "@bitwarden/electron/services/electronRendererStorage.service"; import { Account } from "../../models/account"; +import { ElectronCryptoService } from "../../services/electron-crypto.service"; +import { ElectronLogService } from "../../services/electron-log.service"; +import { ElectronPlatformUtilsService } from "../../services/electron-platform-utils.service"; +import { ElectronRendererMessagingService } from "../../services/electron-renderer-messaging.service"; +import { ElectronRendererSecureStorageService } from "../../services/electron-renderer-secure-storage.service"; +import { ElectronRendererStorageService } from "../../services/electron-renderer-storage.service"; import { EncryptedMessageHandlerService } from "../../services/encrypted-message-handler.service"; import { I18nService } from "../../services/i18n.service"; import { NativeMessageHandlerService } from "../../services/native-message-handler.service"; diff --git a/apps/desktop/src/app/vault/vault.component.ts b/apps/desktop/src/app/vault/vault.component.ts index 8c3e2103cd..5681535e24 100644 --- a/apps/desktop/src/app/vault/vault.component.ts +++ b/apps/desktop/src/app/vault/vault.component.ts @@ -27,8 +27,8 @@ import { CipherType } from "@bitwarden/common/enums/cipherType"; import { EventType } from "@bitwarden/common/enums/eventType"; import { CipherView } from "@bitwarden/common/models/view/cipher.view"; import { FolderView } from "@bitwarden/common/models/view/folder.view"; -import { invokeMenu, RendererMenuItem } from "@bitwarden/electron/utils"; +import { invokeMenu, RendererMenuItem } from "../../utils"; import { SearchBarService } from "../layout/search/search-bar.service"; import { AddEditComponent } from "./add-edit.component"; diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts index 8c99b81911..f5a078cdcc 100644 --- a/apps/desktop/src/main.ts +++ b/apps/desktop/src/main.ts @@ -6,12 +6,6 @@ import { StateFactory } from "@bitwarden/common/factories/stateFactory"; import { GlobalState } from "@bitwarden/common/models/domain/global-state"; import { MemoryStorageService } from "@bitwarden/common/services/memoryStorage.service"; import { StateService } from "@bitwarden/common/services/state.service"; -import { ElectronLogService } from "@bitwarden/electron/services/electronLog.service"; -import { ElectronMainMessagingService } from "@bitwarden/electron/services/electronMainMessaging.service"; -import { ElectronStorageService } from "@bitwarden/electron/services/electronStorage.service"; -import { TrayMain } from "@bitwarden/electron/tray.main"; -import { UpdaterMain } from "@bitwarden/electron/updater.main"; -import { WindowMain } from "@bitwarden/electron/window.main"; import { BiometricMain } from "./main/biometric/biometric.main"; import { DesktopCredentialStorageListener } from "./main/desktop-credential-storage-listener"; @@ -19,7 +13,13 @@ import { MenuMain } from "./main/menu/menu.main"; import { MessagingMain } from "./main/messaging.main"; import { NativeMessagingMain } from "./main/native-messaging.main"; import { PowerMonitorMain } from "./main/power-monitor.main"; +import { TrayMain } from "./main/tray.main"; +import { UpdaterMain } from "./main/updater.main"; +import { WindowMain } from "./main/window.main"; import { Account } from "./models/account"; +import { ElectronLogService } from "./services/electron-log.service"; +import { ElectronMainMessagingService } from "./services/electron-main-messaging.service"; +import { ElectronStorageService } from "./services/electron-storage.service"; import { I18nService } from "./services/i18n.service"; export class Main { @@ -105,15 +105,7 @@ export class Main { (win) => this.trayMain.setupWindowListeners(win) ); this.messagingMain = new MessagingMain(this, this.stateService); - this.updaterMain = new UpdaterMain( - this.i18nService, - this.windowMain, - "clients", - null, - null, - null, - "bitwarden" - ); + this.updaterMain = new UpdaterMain(this.i18nService, this.windowMain, "bitwarden"); this.menuMain = new MenuMain(this); this.powerMonitorMain = new PowerMonitorMain(this); this.trayMain = new TrayMain(this.windowMain, this.i18nService, this.stateService); diff --git a/apps/desktop/src/main/biometric/biometric.windows.main.ts b/apps/desktop/src/main/biometric/biometric.windows.main.ts index 01e3b563f2..207e6c38b5 100644 --- a/apps/desktop/src/main/biometric/biometric.windows.main.ts +++ b/apps/desktop/src/main/biometric/biometric.windows.main.ts @@ -4,7 +4,8 @@ import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/abstractions/log.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; import { biometrics } from "@bitwarden/desktop-native"; -import { WindowMain } from "@bitwarden/electron/window.main"; + +import { WindowMain } from "../window.main"; import { BiometricMain } from "./biometric.main"; diff --git a/apps/desktop/src/main/menu/menu.about.ts b/apps/desktop/src/main/menu/menu.about.ts index 64f1adad0c..33d4f12ea5 100644 --- a/apps/desktop/src/main/menu/menu.about.ts +++ b/apps/desktop/src/main/menu/menu.about.ts @@ -1,8 +1,9 @@ import { BrowserWindow, clipboard, dialog, MenuItemConstructorOptions } from "electron"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; -import { UpdaterMain } from "@bitwarden/electron/updater.main"; -import { isMacAppStore, isSnapStore, isWindowsStore } from "@bitwarden/electron/utils"; + +import { isMacAppStore, isSnapStore, isWindowsStore } from "../../utils"; +import { UpdaterMain } from "../updater.main"; import { IMenubarMenu } from "./menubar"; diff --git a/apps/desktop/src/main/menu/menu.account.ts b/apps/desktop/src/main/menu/menu.account.ts index b7c4b1f693..31e0797ebb 100644 --- a/apps/desktop/src/main/menu/menu.account.ts +++ b/apps/desktop/src/main/menu/menu.account.ts @@ -2,7 +2,8 @@ import { BrowserWindow, dialog, MenuItemConstructorOptions, shell } from "electr import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; -import { isMacAppStore, isWindowsStore } from "@bitwarden/electron/utils"; + +import { isMacAppStore, isWindowsStore } from "../../utils"; import { IMenubarMenu } from "./menubar"; diff --git a/apps/desktop/src/main/menu/menu.bitwarden.ts b/apps/desktop/src/main/menu/menu.bitwarden.ts index d25454d9a4..7a20b381f5 100644 --- a/apps/desktop/src/main/menu/menu.bitwarden.ts +++ b/apps/desktop/src/main/menu/menu.bitwarden.ts @@ -2,8 +2,9 @@ import { BrowserWindow, MenuItemConstructorOptions } from "electron"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; -import { UpdaterMain } from "@bitwarden/electron/updater.main"; -import { isMac } from "@bitwarden/electron/utils"; + +import { isMac } from "../../utils"; +import { UpdaterMain } from "../updater.main"; import { FirstMenu } from "./menu.first"; import { MenuAccount } from "./menu.updater"; diff --git a/apps/desktop/src/main/menu/menu.file.ts b/apps/desktop/src/main/menu/menu.file.ts index 71b4a23692..6a7c3ba16d 100644 --- a/apps/desktop/src/main/menu/menu.file.ts +++ b/apps/desktop/src/main/menu/menu.file.ts @@ -2,8 +2,9 @@ import { BrowserWindow, MenuItemConstructorOptions } from "electron"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; -import { UpdaterMain } from "@bitwarden/electron/updater.main"; -import { isMac, isMacAppStore } from "@bitwarden/electron/utils"; + +import { isMac, isMacAppStore } from "../../utils"; +import { UpdaterMain } from "../updater.main"; import { FirstMenu } from "./menu.first"; import { MenuAccount } from "./menu.updater"; diff --git a/apps/desktop/src/main/menu/menu.first.ts b/apps/desktop/src/main/menu/menu.first.ts index 5786b4e68c..06f24b0570 100644 --- a/apps/desktop/src/main/menu/menu.first.ts +++ b/apps/desktop/src/main/menu/menu.first.ts @@ -2,8 +2,9 @@ import { BrowserWindow, dialog, MenuItem, MenuItemConstructorOptions } from "ele import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; -import { UpdaterMain } from "@bitwarden/electron/updater.main"; -import { isMacAppStore, isSnapStore, isWindowsStore } from "@bitwarden/electron/utils"; + +import { isMacAppStore, isSnapStore, isWindowsStore } from "../../utils"; +import { UpdaterMain } from "../updater.main"; import { MenuAccount } from "./menu.updater"; diff --git a/apps/desktop/src/main/menu/menu.help.ts b/apps/desktop/src/main/menu/menu.help.ts index 60fce1ce49..fde742b373 100644 --- a/apps/desktop/src/main/menu/menu.help.ts +++ b/apps/desktop/src/main/menu/menu.help.ts @@ -1,7 +1,8 @@ import { shell, MenuItemConstructorOptions } from "electron"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; -import { isMacAppStore, isWindowsStore } from "@bitwarden/electron/utils"; + +import { isMacAppStore, isWindowsStore } from "../../utils"; import { AboutMenu } from "./menu.about"; import { IMenubarMenu } from "./menubar"; diff --git a/apps/desktop/src/main/menu/menu.main.ts b/apps/desktop/src/main/menu/menu.main.ts index 66670e196c..6a2bd3531b 100644 --- a/apps/desktop/src/main/menu/menu.main.ts +++ b/apps/desktop/src/main/menu/menu.main.ts @@ -1,17 +1,22 @@ import { app, Menu } from "electron"; -import { BaseMenu } from "@bitwarden/electron/baseMenu"; +import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { Main } from "../../main"; +import { WindowMain } from "../window.main"; import { MenuUpdateRequest } from "./menu.updater"; import { Menubar } from "./menubar"; const cloudWebVaultUrl = "https://vault.bitwarden.com"; -export class MenuMain extends BaseMenu { +export class MenuMain { + private i18nService: I18nService; + private windowMain: WindowMain; + constructor(private main: Main) { - super(main.i18nService, main.windowMain); + this.i18nService = main.i18nService; + this.windowMain = main.windowMain; } async init() { @@ -49,4 +54,84 @@ export class MenuMain extends BaseMenu { } return webVaultUrl; } + + private initContextMenu() { + if (this.windowMain.win == null) { + return; + } + + const selectionMenu = Menu.buildFromTemplate([ + { + label: this.i18nService.t("copy"), + role: "copy", + }, + { type: "separator" }, + { + label: this.i18nService.t("selectAll"), + role: "selectAll", + }, + ]); + + const inputMenu = Menu.buildFromTemplate([ + { + label: this.i18nService.t("undo"), + role: "undo", + }, + { + label: this.i18nService.t("redo"), + role: "redo", + }, + { type: "separator" }, + { + label: this.i18nService.t("cut"), + role: "cut", + enabled: false, + }, + { + label: this.i18nService.t("copy"), + role: "copy", + enabled: false, + }, + { + label: this.i18nService.t("paste"), + role: "paste", + }, + { type: "separator" }, + { + label: this.i18nService.t("selectAll"), + role: "selectAll", + }, + ]); + + const inputSelectionMenu = Menu.buildFromTemplate([ + { + label: this.i18nService.t("cut"), + role: "cut", + }, + { + label: this.i18nService.t("copy"), + role: "copy", + }, + { + label: this.i18nService.t("paste"), + role: "paste", + }, + { type: "separator" }, + { + label: this.i18nService.t("selectAll"), + role: "selectAll", + }, + ]); + + this.windowMain.win.webContents.on("context-menu", (e, props) => { + const selected = props.selectionText && props.selectionText.trim() !== ""; + if (props.isEditable && selected) { + inputSelectionMenu.popup({ window: this.windowMain.win }); + } else if (props.isEditable) { + inputMenu.popup({ window: this.windowMain.win }); + } else if (selected) { + selectionMenu.popup({ window: this.windowMain.win }); + } + }); + } } diff --git a/apps/desktop/src/main/menu/menu.window.ts b/apps/desktop/src/main/menu/menu.window.ts index 3746e22b72..8f588781a5 100644 --- a/apps/desktop/src/main/menu/menu.window.ts +++ b/apps/desktop/src/main/menu/menu.window.ts @@ -2,8 +2,9 @@ import { MenuItemConstructorOptions } from "electron"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; -import { isMac } from "@bitwarden/electron/utils"; -import { WindowMain } from "@bitwarden/electron/window.main"; + +import { isMac } from "../../utils"; +import { WindowMain } from "../window.main"; import { IMenubarMenu } from "./menubar"; diff --git a/apps/desktop/src/main/menu/menubar.ts b/apps/desktop/src/main/menu/menubar.ts index 441b9ac655..5048c60dc0 100644 --- a/apps/desktop/src/main/menu/menubar.ts +++ b/apps/desktop/src/main/menu/menubar.ts @@ -2,9 +2,10 @@ import { Menu, MenuItemConstructorOptions } from "electron"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; -import { UpdaterMain } from "@bitwarden/electron/updater.main"; -import { isMac } from "@bitwarden/electron/utils"; -import { WindowMain } from "@bitwarden/electron/window.main"; + +import { isMac } from "../../utils"; +import { UpdaterMain } from "../updater.main"; +import { WindowMain } from "../window.main"; import { AboutMenu } from "./menu.about"; import { AccountMenu } from "./menu.account"; diff --git a/apps/desktop/src/main/native-messaging.main.ts b/apps/desktop/src/main/native-messaging.main.ts index 0559d2ce96..ae549ace38 100644 --- a/apps/desktop/src/main/native-messaging.main.ts +++ b/apps/desktop/src/main/native-messaging.main.ts @@ -8,7 +8,8 @@ import { ipcMain } from "electron"; import * as ipc from "node-ipc"; import { LogService } from "@bitwarden/common/abstractions/log.service"; -import { WindowMain } from "@bitwarden/electron/window.main"; + +import { WindowMain } from "./window.main"; export class NativeMessagingMain { private connected: Socket[] = []; diff --git a/apps/desktop/src/main/power-monitor.main.ts b/apps/desktop/src/main/power-monitor.main.ts index 438a0e6f9e..56e6139ccf 100644 --- a/apps/desktop/src/main/power-monitor.main.ts +++ b/apps/desktop/src/main/power-monitor.main.ts @@ -1,8 +1,7 @@ import { powerMonitor } from "electron"; -import { isSnapStore } from "@bitwarden/electron/utils"; - import { Main } from "../main"; +import { isSnapStore } from "../utils"; // tslint:disable-next-line const IdleLockSeconds = 5 * 60; // 5 minutes diff --git a/libs/electron/src/tray.main.ts b/apps/desktop/src/main/tray.main.ts similarity index 100% rename from libs/electron/src/tray.main.ts rename to apps/desktop/src/main/tray.main.ts diff --git a/libs/electron/src/updater.main.ts b/apps/desktop/src/main/updater.main.ts similarity index 86% rename from libs/electron/src/updater.main.ts rename to apps/desktop/src/main/updater.main.ts index 638c5efeda..314ea076b2 100644 --- a/libs/electron/src/updater.main.ts +++ b/apps/desktop/src/main/updater.main.ts @@ -4,10 +4,11 @@ import { autoUpdater } from "electron-updater"; import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; -import { isAppImage, isDev, isMacAppStore, isWindowsPortable, isWindowsStore } from "./utils"; +import { isAppImage, isDev, isMacAppStore, isWindowsPortable, isWindowsStore } from "../utils"; + import { WindowMain } from "./window.main"; -const UpdaterCheckInitalDelay = 5 * 1000; // 5 seconds +const UpdaterCheckInitialDelay = 5 * 1000; // 5 seconds const UpdaterCheckInterval = 12 * 60 * 60 * 1000; // 12 hours export class UpdaterMain { @@ -18,10 +19,6 @@ export class UpdaterMain { constructor( private i18nService: I18nService, private windowMain: WindowMain, - private gitHubProject: string, - private onCheckingForUpdate: () => void = null, - private onReset: () => void = null, - private onUpdateDownloaded: () => void = null, private projectName: string ) { autoUpdater.logger = log; @@ -36,13 +33,10 @@ export class UpdaterMain { } async init() { - global.setTimeout(async () => await this.checkForUpdate(), UpdaterCheckInitalDelay); + global.setTimeout(async () => await this.checkForUpdate(), UpdaterCheckInitialDelay); global.setInterval(async () => await this.checkForUpdate(), UpdaterCheckInterval); autoUpdater.on("checking-for-update", () => { - if (this.onCheckingForUpdate != null) { - this.onCheckingForUpdate(); - } this.doingUpdateCheck = true; }); @@ -87,10 +81,6 @@ export class UpdaterMain { }); autoUpdater.on("update-downloaded", async (info) => { - if (this.onUpdateDownloaded != null) { - this.onUpdateDownloaded(); - } - if (this.windowMain.win == null) { return; } @@ -132,7 +122,7 @@ export class UpdaterMain { if (!this.canUpdate) { if (withFeedback) { - shell.openExternal("https://github.com/bitwarden/" + this.gitHubProject + "/releases"); + shell.openExternal("https://github.com/bitwarden/clients/releases"); } return; @@ -147,9 +137,6 @@ export class UpdaterMain { } private reset() { - if (this.onReset != null) { - this.onReset(); - } autoUpdater.autoDownload = true; this.doingUpdateCheck = false; } diff --git a/libs/electron/src/window.main.ts b/apps/desktop/src/main/window.main.ts similarity index 99% rename from libs/electron/src/window.main.ts rename to apps/desktop/src/main/window.main.ts index 47f7e4e9cd..5b58172ac1 100644 --- a/libs/electron/src/window.main.ts +++ b/apps/desktop/src/main/window.main.ts @@ -6,7 +6,7 @@ import { app, BrowserWindow, screen } from "electron"; import { LogService } from "@bitwarden/common/abstractions/log.service"; import { StateService } from "@bitwarden/common/abstractions/state.service"; -import { cleanUserAgent, isDev, isMacAppStore, isSnapStore } from "./utils"; +import { cleanUserAgent, isDev, isMacAppStore, isSnapStore } from "../utils"; const mainWindowSizeKey = "mainWindowSize"; const WindowEventHandlingDelay = 100; diff --git a/libs/electron/src/services/electronCrypto.service.ts b/apps/desktop/src/services/electron-crypto.service.ts similarity index 100% rename from libs/electron/src/services/electronCrypto.service.ts rename to apps/desktop/src/services/electron-crypto.service.ts diff --git a/libs/electron/spec/services/electronLog.service.spec.ts b/apps/desktop/src/services/electron-log.service.spec.ts similarity index 75% rename from libs/electron/spec/services/electronLog.service.spec.ts rename to apps/desktop/src/services/electron-log.service.spec.ts index 5802478fb7..5b12edc945 100644 --- a/libs/electron/spec/services/electronLog.service.spec.ts +++ b/apps/desktop/src/services/electron-log.service.spec.ts @@ -1,4 +1,4 @@ -import { ElectronLogService } from "@bitwarden/electron/services/electronLog.service"; +import { ElectronLogService } from "./electron-log.service"; describe("ElectronLogService", () => { it("sets dev based on electron method", () => { diff --git a/libs/electron/src/services/electronLog.service.ts b/apps/desktop/src/services/electron-log.service.ts similarity index 100% rename from libs/electron/src/services/electronLog.service.ts rename to apps/desktop/src/services/electron-log.service.ts diff --git a/libs/electron/src/services/electronMainMessaging.service.ts b/apps/desktop/src/services/electron-main-messaging.service.ts similarity index 97% rename from libs/electron/src/services/electronMainMessaging.service.ts rename to apps/desktop/src/services/electron-main-messaging.service.ts index a025e32e37..b8d754b925 100644 --- a/libs/electron/src/services/electronMainMessaging.service.ts +++ b/apps/desktop/src/services/electron-main-messaging.service.ts @@ -3,8 +3,8 @@ import { app, dialog, ipcMain, Menu, MenuItem, nativeTheme, session } from "elec import { MessagingService } from "@bitwarden/common/abstractions/messaging.service"; import { ThemeType } from "@bitwarden/common/enums/themeType"; +import { WindowMain } from "../main/window.main"; import { RendererMenuItem } from "../utils"; -import { WindowMain } from "../window.main"; export class ElectronMainMessagingService implements MessagingService { constructor(private windowMain: WindowMain, private onMessage: (message: any) => void) { diff --git a/libs/electron/src/services/electronPlatformUtils.service.ts b/apps/desktop/src/services/electron-platform-utils.service.ts similarity index 100% rename from libs/electron/src/services/electronPlatformUtils.service.ts rename to apps/desktop/src/services/electron-platform-utils.service.ts diff --git a/libs/electron/src/services/electronRendererMessaging.service.ts b/apps/desktop/src/services/electron-renderer-messaging.service.ts similarity index 100% rename from libs/electron/src/services/electronRendererMessaging.service.ts rename to apps/desktop/src/services/electron-renderer-messaging.service.ts diff --git a/libs/electron/src/services/electronRendererSecureStorage.service.ts b/apps/desktop/src/services/electron-renderer-secure-storage.service.ts similarity index 100% rename from libs/electron/src/services/electronRendererSecureStorage.service.ts rename to apps/desktop/src/services/electron-renderer-secure-storage.service.ts diff --git a/libs/electron/src/services/electronRendererStorage.service.ts b/apps/desktop/src/services/electron-renderer-storage.service.ts similarity index 100% rename from libs/electron/src/services/electronRendererStorage.service.ts rename to apps/desktop/src/services/electron-renderer-storage.service.ts diff --git a/libs/electron/src/services/electronStorage.service.ts b/apps/desktop/src/services/electron-storage.service.ts similarity index 100% rename from libs/electron/src/services/electronStorage.service.ts rename to apps/desktop/src/services/electron-storage.service.ts diff --git a/libs/electron/spec/utils.spec.ts b/apps/desktop/src/utils.spec.ts similarity index 96% rename from libs/electron/spec/utils.spec.ts rename to apps/desktop/src/utils.spec.ts index 96af43eb75..e9fbad3df9 100644 --- a/libs/electron/spec/utils.spec.ts +++ b/apps/desktop/src/utils.spec.ts @@ -1,4 +1,4 @@ -import { cleanUserAgent } from "@bitwarden/electron/utils"; +import { cleanUserAgent } from "./utils"; const expectedUserAgent = `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${process.versions.chrome} Safari/537.36`; diff --git a/libs/electron/src/utils.ts b/apps/desktop/src/utils.ts similarity index 100% rename from libs/electron/src/utils.ts rename to apps/desktop/src/utils.ts diff --git a/apps/desktop/tsconfig.json b/apps/desktop/tsconfig.json index 74b0670b3e..9ae70b05f9 100644 --- a/apps/desktop/tsconfig.json +++ b/apps/desktop/tsconfig.json @@ -11,8 +11,7 @@ "baseUrl": ".", "paths": { "@bitwarden/common/*": ["../../libs/common/src/*"], - "@bitwarden/angular/*": ["../../libs/angular/src/*"], - "@bitwarden/electron/*": ["../../libs/electron/src/*"] + "@bitwarden/angular/*": ["../../libs/angular/src/*"] } }, "angularCompilerOptions": { diff --git a/jest.config.js b/jest.config.js index 535c9e00a3..13eefb7b7d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -19,7 +19,6 @@ module.exports = { "/libs/angular/jest.config.js", "/libs/common/jest.config.js", "/libs/components/jest.config.js", - "/libs/electron/jest.config.js", "/libs/node/jest.config.js", ], diff --git a/libs/electron/jest.config.js b/libs/electron/jest.config.js deleted file mode 100644 index 104e723a84..0000000000 --- a/libs/electron/jest.config.js +++ /dev/null @@ -1,14 +0,0 @@ -const { pathsToModuleNameMapper } = require("ts-jest"); - -const { compilerOptions } = require("../shared/tsconfig.libs"); - -const sharedConfig = require("../../libs/shared/jest.config.base"); - -module.exports = { - ...sharedConfig, - preset: "ts-jest", - testEnvironment: "jsdom", - moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, { - prefix: "/", - }), -}; diff --git a/libs/electron/package.json b/libs/electron/package.json deleted file mode 100644 index 1ecbea89a1..0000000000 --- a/libs/electron/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "@bitwarden/electron", - "version": "0.0.0", - "description": "Common code used across Bitwarden JavaScript projects.", - "keywords": [ - "bitwarden" - ], - "author": "Bitwarden Inc.", - "homepage": "https://bitwarden.com", - "repository": { - "type": "git", - "url": "https://github.com/bitwarden/jslib" - }, - "license": "GPL-3.0", - "scripts": { - "clean": "rimraf dist/**/*", - "build": "npm run clean && tsc", - "build:watch": "npm run clean && tsc -watch" - }, - "dependencies": { - "@bitwarden/common": "file:../common" - } -} diff --git a/libs/electron/src/baseMenu.ts b/libs/electron/src/baseMenu.ts deleted file mode 100644 index 6682f896c6..0000000000 --- a/libs/electron/src/baseMenu.ts +++ /dev/null @@ -1,225 +0,0 @@ -import { Menu, MenuItemConstructorOptions } from "electron"; - -import { I18nService } from "@bitwarden/common/abstractions/i18n.service"; - -import { WindowMain } from "./window.main"; - -export class BaseMenu { - protected editMenuItemOptions: MenuItemConstructorOptions; - protected viewSubMenuItemOptions: MenuItemConstructorOptions[]; - protected windowMenuItemOptions: MenuItemConstructorOptions; - protected macAppMenuItemOptions: MenuItemConstructorOptions[]; - protected macWindowSubmenuOptions: MenuItemConstructorOptions[]; - - constructor(protected i18nService: I18nService, protected windowMain: WindowMain) {} - - protected initProperties() { - this.editMenuItemOptions = { - label: this.i18nService.t("edit"), - submenu: [ - { - label: this.i18nService.t("undo"), - role: "undo", - }, - { - label: this.i18nService.t("redo"), - role: "redo", - }, - { type: "separator" }, - { - label: this.i18nService.t("cut"), - role: "cut", - }, - { - label: this.i18nService.t("copy"), - role: "copy", - }, - { - label: this.i18nService.t("paste"), - role: "paste", - }, - { type: "separator" }, - { - label: this.i18nService.t("selectAll"), - role: "selectAll", - }, - ], - }; - - this.viewSubMenuItemOptions = [ - { - label: this.i18nService.t("zoomIn"), - role: "zoomIn", - accelerator: "CmdOrCtrl+=", - }, - { - label: this.i18nService.t("zoomOut"), - role: "zoomOut", - accelerator: "CmdOrCtrl+-", - }, - { - label: this.i18nService.t("resetZoom"), - role: "resetZoom", - accelerator: "CmdOrCtrl+0", - }, - { type: "separator" }, - { - label: this.i18nService.t("toggleFullScreen"), - role: "togglefullscreen", - }, - { type: "separator" }, - { - label: this.i18nService.t("reload"), - role: "forceReload", - }, - { - label: this.i18nService.t("toggleDevTools"), - role: "toggleDevTools", - accelerator: "F12", - }, - ]; - - this.windowMenuItemOptions = { - label: this.i18nService.t("window"), - role: "window", - submenu: [ - { - label: this.i18nService.t("minimize"), - role: "minimize", - }, - { - label: this.i18nService.t("close"), - role: "close", - }, - ], - }; - - if (process.platform === "darwin") { - this.macAppMenuItemOptions = [ - { - label: this.i18nService.t("services"), - role: "services", - submenu: [], - }, - { type: "separator" }, - { - label: this.i18nService.t("hideBitwarden"), - role: "hide", - }, - { - label: this.i18nService.t("hideOthers"), - role: "hideOthers", - }, - { - label: this.i18nService.t("showAll"), - role: "unhide", - }, - { type: "separator" }, - { - label: this.i18nService.t("quitBitwarden"), - role: "quit", - }, - ]; - - this.macWindowSubmenuOptions = [ - { - label: this.i18nService.t("minimize"), - role: "minimize", - }, - { - label: this.i18nService.t("zoom"), - role: "zoom", - }, - { type: "separator" }, - { - label: this.i18nService.t("bringAllToFront"), - role: "front", - }, - { - label: this.i18nService.t("close"), - role: "close", - }, - ]; - } - } - - protected initContextMenu() { - if (this.windowMain.win == null) { - return; - } - - const selectionMenu = Menu.buildFromTemplate([ - { - label: this.i18nService.t("copy"), - role: "copy", - }, - { type: "separator" }, - { - label: this.i18nService.t("selectAll"), - role: "selectAll", - }, - ]); - - const inputMenu = Menu.buildFromTemplate([ - { - label: this.i18nService.t("undo"), - role: "undo", - }, - { - label: this.i18nService.t("redo"), - role: "redo", - }, - { type: "separator" }, - { - label: this.i18nService.t("cut"), - role: "cut", - enabled: false, - }, - { - label: this.i18nService.t("copy"), - role: "copy", - enabled: false, - }, - { - label: this.i18nService.t("paste"), - role: "paste", - }, - { type: "separator" }, - { - label: this.i18nService.t("selectAll"), - role: "selectAll", - }, - ]); - - const inputSelectionMenu = Menu.buildFromTemplate([ - { - label: this.i18nService.t("cut"), - role: "cut", - }, - { - label: this.i18nService.t("copy"), - role: "copy", - }, - { - label: this.i18nService.t("paste"), - role: "paste", - }, - { type: "separator" }, - { - label: this.i18nService.t("selectAll"), - role: "selectAll", - }, - ]); - - this.windowMain.win.webContents.on("context-menu", (e, props) => { - const selected = props.selectionText && props.selectionText.trim() !== ""; - if (props.isEditable && selected) { - inputSelectionMenu.popup({ window: this.windowMain.win }); - } else if (props.isEditable) { - inputMenu.popup({ window: this.windowMain.win }); - } else if (selected) { - selectionMenu.popup({ window: this.windowMain.win }); - } - }); - } -} diff --git a/libs/electron/src/globals.d.ts b/libs/electron/src/globals.d.ts deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/libs/electron/tsconfig.json b/libs/electron/tsconfig.json deleted file mode 100644 index 6004a56fb5..0000000000 --- a/libs/electron/tsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "../shared/tsconfig.libs", - "include": ["src", "spec"], - "exclude": ["node_modules", "dist"] -} diff --git a/libs/electron/tsconfig.spec.json b/libs/electron/tsconfig.spec.json deleted file mode 100644 index fc8520e737..0000000000 --- a/libs/electron/tsconfig.spec.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "./tsconfig.json" -} diff --git a/libs/shared/tsconfig.libs.json b/libs/shared/tsconfig.libs.json index 5ac6b719fa..bb739dcfa2 100644 --- a/libs/shared/tsconfig.libs.json +++ b/libs/shared/tsconfig.libs.json @@ -4,7 +4,6 @@ "paths": { "@bitwarden/common/*": ["../common/src/*"], "@bitwarden/angular/*": ["../angular/src/*"], - "@bitwarden/electron/*": ["../electron/src/*"], "@bitwarden/node/*": ["../node/src/*"] } } diff --git a/package-lock.json b/package-lock.json index c407dbe3a4..72c67ede2b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -246,14 +246,6 @@ "name": "@bitwarden/components", "version": "0.0.0" }, - "libs/electron": { - "name": "@bitwarden/electron", - "version": "0.0.0", - "license": "GPL-3.0", - "dependencies": { - "@bitwarden/common": "file:../common" - } - }, "libs/node": { "name": "@bitwarden/node", "version": "0.0.0", @@ -3092,10 +3084,6 @@ "resolved": "apps/desktop/desktop_native", "link": true }, - "node_modules/@bitwarden/electron": { - "resolved": "libs/electron", - "link": true - }, "node_modules/@bitwarden/node": { "resolved": "libs/node", "link": true @@ -45193,12 +45181,6 @@ "@napi-rs/cli": "^2.6.2" } }, - "@bitwarden/electron": { - "version": "file:libs/electron", - "requires": { - "@bitwarden/common": "file:../common" - } - }, "@bitwarden/node": { "version": "file:libs/node", "requires": { diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index cf7bbd7c96..6988851dbc 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -17,7 +17,6 @@ "paths": { "@bitwarden/common/*": ["./libs/common/src/*"], "@bitwarden/angular/*": ["./libs/angular/src/*"], - "@bitwarden/electron/*": ["./libs/electron/src/*"], "@bitwarden/node/*": ["./libs/node/src/*"], "@bitwarden/components": ["./libs/components/src"] }, diff --git a/tsconfig.json b/tsconfig.json index 6761a4f5c2..d9189e23eb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,6 @@ "paths": { "@bitwarden/common/*": ["./libs/common/src/*"], "@bitwarden/angular/*": ["./libs/angular/src/*"], - "@bitwarden/electron/*": ["./libs/electron/src/*"], "@bitwarden/node/*": ["./libs/node/src/*"], "@bitwarden/components": ["./libs/components/src"] },