Просмотр исходного кода

[desktop] Code tweaks (#1401)

- Remove top level wrapper
- Document the tray icon
- Update to the new product name where possible
Manav Rathi 1 год назад
Родитель
Сommit
334fd61ea3

+ 12 - 4
desktop/src/main/init.ts

@@ -77,16 +77,24 @@ export const createWindow = async () => {
 };
 
 export const setupTrayItem = (mainWindow: BrowserWindow) => {
-    const iconName = isPlatform("mac")
-        ? "taskbar-icon-Template.png"
-        : "taskbar-icon.png";
+    // There are a total of 6 files corresponding to this tray icon.
+    //
+    // On macOS, use template images (filename needs to end with "Template.ext")
+    // https://www.electronjs.org/docs/latest/api/native-image#template-image-macos
+    //
+    // And for each (template or otherwise), there are 3 "retina" variants
+    // https://www.electronjs.org/docs/latest/api/native-image#high-resolution-image
+    const iconName =
+        process.platform == "darwin"
+            ? "taskbar-icon-Template.png"
+            : "taskbar-icon.png";
     const trayImgPath = path.join(
         isDev ? "build" : process.resourcesPath,
         iconName,
     );
     const trayIcon = nativeImage.createFromPath(trayImgPath);
     const tray = new Tray(trayIcon);
-    tray.setToolTip("ente");
+    tray.setToolTip("Ente Photos");
     tray.setContextMenu(createTrayContextMenu(mainWindow));
 };
 

+ 2 - 2
desktop/src/main/menu.ts

@@ -53,7 +53,7 @@ export const createApplicationMenu = async (mainWindow: BrowserWindow) => {
 
     return Menu.buildFromTemplate([
         {
-            label: "ente",
+            label: "Ente Photos",
             submenu: [
                 ...macOSOnly([
                     {
@@ -155,7 +155,7 @@ export const createApplicationMenu = async (mainWindow: BrowserWindow) => {
                     { type: "separator" },
                     { label: "Bring All to Front", role: "front" },
                     { type: "separator" },
-                    { label: "Ente", role: "window" },
+                    { label: "Ente Photos", role: "window" },
                 ]),
             ],
         },

+ 45 - 45
desktop/src/services/app-update.ts

@@ -26,56 +26,56 @@ export const forceCheckForAppUpdates = (mainWindow: BrowserWindow) => {
 };
 
 const checkForUpdatesAndNotify = async (mainWindow: BrowserWindow) => {
-    try {
-        const { updateInfo } = await autoUpdater.checkForUpdates();
-        const { version } = updateInfo;
+    const updateCheckResult = await autoUpdater.checkForUpdates();
+    if (!updateCheckResult) {
+        log.error("Failed to check for updates");
+        return;
+    }
 
-        log.debug(() => `Checking for updates found version ${version}`);
+    const { version } = updateCheckResult.updateInfo;
 
-        if (compareVersions(version, app.getVersion()) <= 0) {
-            log.debug(() => "Skipping update, already at latest version");
-            return;
-        }
+    log.debug(() => `Update check found version ${version}`);
 
-        if (version === userPreferencesStore.get("skipAppVersion")) {
-            log.info(`User chose to skip version ${version}`);
-            return;
-        }
+    if (compareVersions(version, app.getVersion()) <= 0) {
+        log.debug(() => "Skipping update, already at latest version");
+        return;
+    }
 
-        const mutedVersion = userPreferencesStore.get(
-            "muteUpdateNotificationVersion",
-        );
-        if (version === mutedVersion) {
-            log.info(
-                `User has muted update notifications for version ${version}`,
-            );
-            return;
-        }
-
-        const showUpdateDialog = (updateInfo: AppUpdateInfo) =>
-            mainWindow.webContents.send("appUpdateAvailable", updateInfo);
-
-        log.debug(() => "Attempting auto update");
-        autoUpdater.downloadUpdate();
-
-        let timeout: NodeJS.Timeout;
-        const fiveMinutes = 5 * 60 * 1000;
-        autoUpdater.on("update-downloaded", () => {
-            timeout = setTimeout(
-                () => showUpdateDialog({ autoUpdatable: true, version }),
-                fiveMinutes,
-            );
-        });
-        autoUpdater.on("error", (error) => {
-            clearTimeout(timeout);
-            log.error("Auto update failed", error);
-            showUpdateDialog({ autoUpdatable: false, version });
-        });
-
-        setIsUpdateAvailable(true);
-    } catch (e) {
-        log.error("checkForUpdateAndNotify failed", e);
+    if (version === userPreferencesStore.get("skipAppVersion")) {
+        log.info(`User chose to skip version ${version}`);
+        return;
     }
+
+    const mutedVersion = userPreferencesStore.get(
+        "muteUpdateNotificationVersion",
+    );
+    if (version === mutedVersion) {
+        log.info(`User has muted update notifications for version ${version}`);
+        return;
+    }
+
+    const showUpdateDialog = (updateInfo: AppUpdateInfo) =>
+        mainWindow.webContents.send("appUpdateAvailable", updateInfo);
+
+    log.debug(() => "Attempting auto update");
+    autoUpdater.downloadUpdate();
+
+    let timeout: NodeJS.Timeout;
+    const fiveMinutes = 5 * 60 * 1000;
+    autoUpdater.on("update-downloaded", () => {
+        timeout = setTimeout(
+            () => showUpdateDialog({ autoUpdatable: true, version }),
+            fiveMinutes,
+        );
+    });
+
+    autoUpdater.on("error", (error) => {
+        clearTimeout(timeout);
+        log.error("Auto update failed", error);
+        showUpdateDialog({ autoUpdatable: false, version });
+    });
+
+    setIsUpdateAvailable(true);
 };
 
 /**

+ 7 - 1
desktop/src/services/watch.ts

@@ -2,7 +2,6 @@ import type { FSWatcher } from "chokidar";
 import ElectronLog from "electron-log";
 import { watchStore } from "../stores/watch.store";
 import { WatchMapping, WatchStoreType } from "../types/ipc";
-import { isMappingPresent } from "../utils/watch";
 
 export const addWatchMapping = async (
     watcher: FSWatcher,
@@ -29,6 +28,13 @@ export const addWatchMapping = async (
     setWatchMappings(watchMappings);
 };
 
+function isMappingPresent(watchMappings: WatchMapping[], folderPath: string) {
+    const watchMapping = watchMappings?.find(
+        (mapping) => mapping.folderPath === folderPath,
+    );
+    return !!watchMapping;
+}
+
 export const removeWatchMapping = async (
     watcher: FSWatcher,
     folderPath: string,

+ 0 - 11
desktop/src/utils/watch.ts

@@ -1,11 +0,0 @@
-import { WatchMapping } from "../types/ipc";
-
-export function isMappingPresent(
-    watchMappings: WatchMapping[],
-    folderPath: string,
-) {
-    const watchMapping = watchMappings?.find(
-        (mapping) => mapping.folderPath === folderPath,
-    );
-    return !!watchMapping;
-}