瀏覽代碼

Final stretch

Manav Rathi 1 年之前
父節點
當前提交
c729516faf

+ 10 - 11
web/apps/photos/src/components/WatchFolder/index.tsx

@@ -1,17 +1,14 @@
+import DialogTitleWithCloseButton from "@ente/shared/components/DialogBox/TitleWithCloseButton";
 import { Button, Dialog, DialogContent, Stack } from "@mui/material";
+import UploadStrategyChoiceModal from "components/Upload/UploadStrategyChoiceModal";
+import { PICKED_UPLOAD_TYPE, UPLOAD_STRATEGY } from "constants/upload";
 import { t } from "i18next";
 import { AppContext } from "pages/_app";
 import { useContext, useEffect, useState } from "react";
 import watchFolderService from "services/watchFolder/watchFolderService";
 import { WatchMapping } from "types/watchFolder";
-import { MappingList } from "./mappingList";
-
-import ElectronAPIs from "@/next/electron";
-import DialogTitleWithCloseButton from "@ente/shared/components/DialogBox/TitleWithCloseButton";
-import UploadStrategyChoiceModal from "components/Upload/UploadStrategyChoiceModal";
-import { PICKED_UPLOAD_TYPE, UPLOAD_STRATEGY } from "constants/upload";
-import isElectron from "is-electron";
 import { getImportSuggestion } from "utils/upload";
+import { MappingList } from "./mappingList";
 
 interface Iprops {
     open: boolean;
@@ -24,10 +21,10 @@ export default function WatchFolder({ open, onClose }: Iprops) {
     const [choiceModalOpen, setChoiceModalOpen] = useState(false);
     const appContext = useContext(AppContext);
 
+    const electron = globalThis.electron;
+
     useEffect(() => {
-        if (!isElectron()) {
-            return;
-        }
+        if (!electron) return;
         watchFolderService.getWatchMappings().then((m) => setMappings(m));
     }, []);
 
@@ -52,8 +49,10 @@ export default function WatchFolder({ open, onClose }: Iprops) {
     };
 
     const addFolderForWatching = async (path: string) => {
+        if (!electron) return;
+
         setInputFolderPath(path);
-        const files = await ElectronAPIs.getDirFiles(path);
+        const files = await electron.getDirFiles(path);
         const analysisResult = getImportSuggestion(
             PICKED_UPLOAD_TYPE.FOLDERS,
             files,

+ 3 - 3
web/apps/photos/src/pages/_app.tsx

@@ -1,5 +1,4 @@
 import { CustomHead } from "@/next/components/Head";
-import ElectronAPIs from "@/next/electron";
 import { setupI18n } from "@/next/i18n";
 import log from "@/next/log";
 import { logStartupBanner } from "@/next/log-web";
@@ -154,7 +153,8 @@ export default function App({ Component, pageProps }: AppProps) {
     }, []);
 
     useEffect(() => {
-        if (isElectron()) {
+        const electron = globalThis.electron;
+        if (electron) {
             const showUpdateDialog = (updateInfo: AppUpdateInfo) => {
                 if (updateInfo.autoUpdatable) {
                     setDialogMessage(
@@ -174,7 +174,7 @@ export default function App({ Component, pageProps }: AppProps) {
                     });
                 }
             };
-            ElectronAPIs.registerUpdateEventListener(showUpdateDialog);
+            electron.registerUpdateEventListener(showUpdateDialog);
         }
     }, []);
 

+ 3 - 2
web/apps/photos/src/utils/file/index.ts

@@ -489,8 +489,9 @@ const convertToJPEGInElectron = async (
     try {
         const startTime = Date.now();
         const inputFileData = new Uint8Array(await fileBlob.arrayBuffer());
-        const convertedFileData = isElectron()
-            ? await ElectronAPIs.convertToJPEG(inputFileData, filename)
+        const electron = globalThis.electron;
+        const convertedFileData = electron
+            ? await electron.convertToJPEG(inputFileData, filename)
             : await workerBridge.convertToJPEG(inputFileData, filename);
         log.info(
             `originalFileSize:${convertBytesToHumanReadable(