π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Rearrange and simplify
Manav Rathi278df2aae896
diff --git a/desktop/src/main.ts b/desktop/src/main.tsindex df9f207601..9d45f68559 100644--- a/desktop/src/main.ts+++ b/desktop/src/main.ts@@ -24,7 +24,7 @@ import { attachFSWatchIPCHandlers, attachIPCHandlers } from "./main/ipc";import log, { initLogging } from "./main/log";import { createApplicationMenu, createTrayContextMenu } from "./main/menu";import { setupAutoUpdater } from "./main/services/app-update";-import autoLauncher from "./main/services/autoLauncher";+import autoLauncher from "./main/services/auto-launcher";import { initWatcher } from "./main/services/chokidar";import { userPreferences } from "./main/stores/user-preferences";import { registerStreamProtocol } from "./main/stream";diff --git a/desktop/src/main/menu.ts b/desktop/src/main/menu.tsindex 3441f3f2ab..bd8810428b 100644--- a/desktop/src/main/menu.ts+++ b/desktop/src/main/menu.ts@@ -7,7 +7,7 @@ import {} from "electron";import { allowWindowClose } from "../main";import { forceCheckForAppUpdates } from "./services/app-update";-import autoLauncher from "./services/autoLauncher";+import autoLauncher from "./services/auto-launcher";import { userPreferences } from "./stores/user-preferences";import { openLogDirectory } from "./util";diff --git a/desktop/src/main/services/auto-launcher.ts b/desktop/src/main/services/auto-launcher.tsnew file mode 100644index 0000000000..e738b613d9--- /dev/null+++ b/desktop/src/main/services/auto-launcher.ts@@ -0,0 +1,51 @@+import AutoLaunch from "auto-launch";+import { app } from "electron";++class AutoLauncher {+ /**+ * This property will be set and used on Linux and Windows. On macOS,+ * there's a separate API+ */+ private autoLaunch?: AutoLaunch;++ constructor() {+ if (process.platform != "darwin") {+ this.autoLaunch = new AutoLaunch({+ name: "ente",+ isHidden: true,+ });+ }+ }++ async isEnabled() {+ const autoLaunch = this.autoLaunch;+ if (autoLaunch) {+ return await autoLaunch.isEnabled();+ } else {+ return app.getLoginItemSettings().openAtLogin;+ }+ }++ async toggleAutoLaunch() {+ const isEnabled = await this.isEnabled();+ const autoLaunch = this.autoLaunch;+ if (autoLaunch) {+ if (isEnabled) await autoLaunch.disable();+ else await autoLaunch.enable();+ } else {+ if (isEnabled) app.setLoginItemSettings({ openAtLogin: false });+ else app.setLoginItemSettings({ openAtLogin: true });+ }+ }++ async wasAutoLaunched() {+ if (this.autoLaunch) {+ return app.commandLine.hasSwitch("hidden");+ } else {+ // TODO(MR): This apparently doesn't work anymore.+ return app.getLoginItemSettings().wasOpenedAtLogin;+ }+ }+}++export default new AutoLauncher();diff --git a/desktop/src/main/services/autoLauncher.ts b/desktop/src/main/services/autoLauncher.tsdeleted file mode 100644index 614c151bac..0000000000--- a/desktop/src/main/services/autoLauncher.ts+++ /dev/null@@ -1,41 +0,0 @@-import { AutoLauncherClient } from "../../types/main";-import { isPlatform } from "../platform";-import linuxAndWinAutoLauncher from "./autoLauncherClients/linuxAndWinAutoLauncher";-import macAutoLauncher from "./autoLauncherClients/macAutoLauncher";--class AutoLauncher {- private client: AutoLauncherClient;- async init() {- if (isPlatform("linux") || isPlatform("windows")) {- this.client = linuxAndWinAutoLauncher;- } else {- this.client = macAutoLauncher;- }- // migrate old auto launch settings for windows from mac auto launcher to linux and windows auto launcher- if (isPlatform("windows") && (await macAutoLauncher.isEnabled())) {- await macAutoLauncher.toggleAutoLaunch();- await linuxAndWinAutoLauncher.toggleAutoLaunch();- }- }- async isEnabled() {- if (!this.client) {- await this.init();- }- return await this.client.isEnabled();- }- async toggleAutoLaunch() {- if (!this.client) {- await this.init();- }- await this.client.toggleAutoLaunch();- }-- async wasAutoLaunched() {- if (!this.client) {- await this.init();- }- return this.client.wasAutoLaunched();- }-}--export default new AutoLauncher();diff --git a/desktop/src/main/services/autoLauncherClients/linuxAndWinAutoLauncher.ts b/desktop/src/main/services/autoLauncherClients/linuxAndWinAutoLauncher.tsdeleted file mode 100644index 0d2c1bb427..0000000000--- a/desktop/src/main/services/autoLauncherClients/linuxAndWinAutoLauncher.ts+++ /dev/null@@ -1,39 +0,0 @@-import AutoLaunch from "auto-launch";-import { app } from "electron";-import { AutoLauncherClient } from "../../../types/main";--const LAUNCHED_AS_HIDDEN_FLAG = "hidden";--class LinuxAndWinAutoLauncher implements AutoLauncherClient {- private instance: AutoLaunch;- constructor() {- const autoLauncher = new AutoLaunch({- name: "ente",- isHidden: true,- });- this.instance = autoLauncher;- }- async isEnabled() {- return await this.instance.isEnabled();- }- async toggleAutoLaunch() {- if (await this.isEnabled()) {- await this.disableAutoLaunch();- } else {- await this.enableAutoLaunch();- }- }-- async wasAutoLaunched() {- return app.commandLine.hasSwitch(LAUNCHED_AS_HIDDEN_FLAG);- }-- private async disableAutoLaunch() {- await this.instance.disable();- }- private async enableAutoLaunch() {- await this.instance.enable();- }-}--export default new LinuxAndWinAutoLauncher();diff --git a/desktop/src/main/services/autoLauncherClients/macAutoLauncher.ts b/desktop/src/main/services/autoLauncherClients/macAutoLauncher.tsdeleted file mode 100644index 00320e870f..0000000000--- a/desktop/src/main/services/autoLauncherClients/macAutoLauncher.ts+++ /dev/null@@ -1,28 +0,0 @@-import { app } from "electron";-import { AutoLauncherClient } from "../../../types/main";--class MacAutoLauncher implements AutoLauncherClient {- async isEnabled() {- return app.getLoginItemSettings().openAtLogin;- }- async toggleAutoLaunch() {- if (await this.isEnabled()) {- this.disableAutoLaunch();- } else {- this.enableAutoLaunch();- }- }-- async wasAutoLaunched() {- return app.getLoginItemSettings().wasOpenedAtLogin;- }-- private disableAutoLaunch() {- app.setLoginItemSettings({ openAtLogin: false });- }- private enableAutoLaunch() {- app.setLoginItemSettings({ openAtLogin: true });- }-}--export default new MacAutoLauncher();diff --git a/desktop/src/main/services/store.ts b/desktop/src/main/services/store.tsindex f5c6274ba9..9ec65c8c38 100644--- a/desktop/src/main/services/store.ts+++ b/desktop/src/main/services/store.ts@@ -1,12 +1,15 @@import { safeStorage } from "electron/main";-import { keysStore } from "../stores/keys.store";-import { safeStorageStore } from "../stores/safeStorage.store";-import { uploadStatusStore } from "../stores/upload.store";+import { safeStorageStore } from "../stores/safe-storage";+import { uploadStatusStore } from "../stores/upload-status";import { watchStore } from "../stores/watch";+/**+ * Clear all stores except user preferences.+ *+ * This is useful to reset state when the user logs out.+ */export const clearStores = () => {uploadStatusStore.clear();- keysStore.clear();safeStorageStore.clear();watchStore.clear();};diff --git a/desktop/src/main/services/upload.ts b/desktop/src/main/services/upload.tsindex e3fbc16e62..2bf941bcf5 100644--- a/desktop/src/main/services/upload.ts+++ b/desktop/src/main/services/upload.ts@@ -2,7 +2,7 @@ import StreamZip from "node-stream-zip";import path from "path";import { ElectronFile, FILE_PATH_TYPE } from "../../types/ipc";import { FILE_PATH_KEYS } from "../../types/main";-import { uploadStatusStore } from "../stores/upload.store";+import { uploadStatusStore } from "../stores/upload-status";import { getElectronFile, getValidPaths, getZipFileStream } from "./fs";export const getPendingUploads = async () => {diff --git a/desktop/src/main/stores/safeStorage.store.ts b/desktop/src/main/stores/safe-storage.tssimilarity index 63%rename from desktop/src/main/stores/safeStorage.store.tsrename to desktop/src/main/stores/safe-storage.tsindex da95df3be0..1e1369db89 100644--- a/desktop/src/main/stores/safeStorage.store.ts+++ b/desktop/src/main/stores/safe-storage.ts@@ -1,7 +1,10 @@import Store, { Schema } from "electron-store";-import type { SafeStorageStoreType } from "../../types/main";-const safeStorageSchema: Schema<SafeStorageStoreType> = {+interface SafeStorageStore {+ encryptionKey: string;+}++const safeStorageSchema: Schema<SafeStorageStore> = {encryptionKey: {type: "string",},diff --git a/desktop/src/main/stores/upload.store.ts b/desktop/src/main/stores/upload-status.tssimilarity index 66%rename from desktop/src/main/stores/upload.store.tsrename to desktop/src/main/stores/upload-status.tsindex 20b1f419d5..2acaea2ba1 100644--- a/desktop/src/main/stores/upload.store.ts+++ b/desktop/src/main/stores/upload-status.ts@@ -1,7 +1,12 @@import Store, { Schema } from "electron-store";-import type { UploadStoreType } from "../../types/main";-const uploadStoreSchema: Schema<UploadStoreType> = {+interface UploadStatusStore {+ filePaths: string[];+ zipPaths: string[];+ collectionName: string;+}++const uploadStatusSchema: Schema<UploadStatusStore> = {filePaths: {type: "array",items: {@@ -21,5 +26,5 @@ const uploadStoreSchema: Schema<UploadStoreType> = {export const uploadStatusStore = new Store({name: "upload-status",- schema: uploadStoreSchema,+ schema: uploadStatusSchema,});diff --git a/desktop/src/main/stores/user-preferences.ts b/desktop/src/main/stores/user-preferences.tsindex a305f1a99b..b4a02bc5be 100644--- a/desktop/src/main/stores/user-preferences.ts+++ b/desktop/src/main/stores/user-preferences.ts@@ -1,12 +1,12 @@import Store, { Schema } from "electron-store";-interface UserPreferencesSchema {+interface UserPreferences {hideDockIcon: boolean;skipAppVersion?: string;muteUpdateNotificationVersion?: string;}-const userPreferencesSchema: Schema<UserPreferencesSchema> = {+const userPreferencesSchema: Schema<UserPreferences> = {hideDockIcon: {type: "boolean",},diff --git a/desktop/src/types/main.ts b/desktop/src/types/main.tsindex 546749c54b..501a552f1f 100644--- a/desktop/src/types/main.ts+++ b/desktop/src/types/main.ts@@ -1,22 +1,6 @@import { FILE_PATH_TYPE } from "./ipc";-export interface AutoLauncherClient {- isEnabled: () => Promise<boolean>;- toggleAutoLaunch: () => Promise<void>;- wasAutoLaunched: () => Promise<boolean>;-}-export interface UploadStoreType {- filePaths: string[];- zipPaths: string[];- collectionName: string;-}--export interface KeysStoreType {- AnonymizeUserID: {- id: string;- };-}/* eslint-disable no-unused-vars */export const FILE_PATH_KEYS: {@@ -26,6 +10,3 @@ export const FILE_PATH_KEYS: {[FILE_PATH_TYPE.FILES]: "filePaths",};-export interface SafeStorageStoreType {- encryptionKey: string;-}