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

fix: can't open new graph on Linux

close #3202
Tienson Qin 4 лет назад
Родитель
Сommit
40b315de6b

+ 24 - 23
src/electron/electron/core.cljs

@@ -119,53 +119,54 @@
      (.unregisterProtocol protocol "assets")))
 
 (defn- handle-export-publish-assets [_event html custom-css-path repo-path asset-filenames]
-  (let [app-path (. app getAppPath)
-        asset-filenames (js->clj asset-filenames)
-        paths (js->clj (. dialog showOpenDialogSync (clj->js {:properties ["openDirectory" "createDirectory" "promptToCreate", "multiSelections"]})))]
-    (when (seq paths)
-      (let [root-dir (first paths)
-            static-dir (path/join root-dir "static")
+  (p/let [app-path (. app getAppPath)
+          asset-filenames (js->clj asset-filenames)
+          result (. dialog showOpenDialog (clj->js {:properties ["openDirectory" "createDirectory" "promptToCreate", "multiSelections"]}))
+          result (get (js->clj result) "filePaths")
+          root-dir (first result)]
+    (when root-dir
+      (let [static-dir (path/join root-dir "static")
             assets-from-dir (path/join repo-path "assets")
             assets-to-dir (path/join root-dir "assets")
             index-html-path (path/join root-dir "index.html")]
         (p/let [_ (. fs ensureDir static-dir)
                 _ (. fs ensureDir assets-to-dir)
                 _ (p/all (concat
-                           [(. fs writeFile index-html-path html)
+                          [(. fs writeFile index-html-path html)
 
 
-                            (. fs copy (path/join app-path "404.html") (path/join root-dir "404.html"))]
+                           (. fs copy (path/join app-path "404.html") (path/join root-dir "404.html"))]
 
-                           (map
-                             (fn [filename]
-                               (-> (. fs copy (path/join assets-from-dir filename) (path/join assets-to-dir filename))
-                                   (p/catch
-                                     (fn [e]
-                                       (println (str "Failed to copy " (path/join assets-from-dir filename) " to " (path/join assets-to-dir filename)))
-                                       (js/console.error e)))))
-                             asset-filenames)
+                          (map
+                            (fn [filename]
+                              (-> (. fs copy (path/join assets-from-dir filename) (path/join assets-to-dir filename))
+                                  (p/catch
+                                      (fn [e]
+                                        (println (str "Failed to copy " (path/join assets-from-dir filename) " to " (path/join assets-to-dir filename)))
+                                        (js/console.error e)))))
+                            asset-filenames)
 
-                           (map
-                             (fn [part]
-                               (. fs copy (path/join app-path part) (path/join static-dir part)))
-                             ["css" "fonts" "icons" "img" "js"])))
+                          (map
+                            (fn [part]
+                              (. fs copy (path/join app-path part) (path/join static-dir part)))
+                            ["css" "fonts" "icons" "img" "js"])))
                 custom-css (. fs readFile custom-css-path)
                 _ (. fs writeFile (path/join static-dir "css" "custom.css") custom-css)
                 js-files ["main.js" "code-editor.js" "excalidraw.js"]
                 _ (p/all (map (fn [file]
                                 (. fs removeSync (path/join static-dir "js" file)))
-                              js-files))
+                           js-files))
                 _ (p/all (map (fn [file]
                                 (. fs moveSync
                                    (path/join static-dir "js" "publishing" file)
                                    (path/join static-dir "js" file)))
-                              js-files))
+                           js-files))
                 _ (. fs removeSync (path/join static-dir "js" "publishing"))
                 ;; remove source map files
                 ;; TODO: ugly, replace with ls-files and filter with ".map"
                 _ (p/all (map (fn [file]
                                 (. fs removeSync (path/join static-dir "js" (str file ".map"))))
-                              ["main.js" "code-editor.js" "excalidraw.js" "age-encryption.js"]))]
+                           ["main.js" "code-editor.js" "excalidraw.js" "age-encryption.js"]))]
           (. dialog showMessageBox (clj->js {:message (str "Export public pages and publish assets to " root-dir " successfully")})))))))
 
 (defn setup-app-manager!

+ 13 - 12
src/electron/electron/handler.cljs

@@ -123,16 +123,17 @@
     (vec (cons {:path (utils/fix-win-path! path)} result))))
 
 (defmethod handle :openDir [^js window _messages]
-  (let [result (.showOpenDialogSync dialog (bean/->js
-                                             {:properties ["openDirectory" "createDirectory" "promptToCreate"]}))
-        path (first result)]
+  (p/let [result (.showOpenDialog dialog (bean/->js
+                                          {:properties ["openDirectory" "createDirectory" "promptToCreate"]}))
+          result (get (js->clj result) "filePaths")
+          path (first result)]
     (if path
       (do
         (.. ^js window -webContents
-           (send "open-dir-confirmed"
-                 (bean/->js {:opened? true})))
-        (get-files path))
-      (throw (js/Error "path empty")))))
+            (send "open-dir-confirmed"
+                  (bean/->js {:opened? true})))
+        (p/resolved (bean/->js (get-files path))))
+      (p/rejected (js/Error "path empty")))))
 
 (defmethod handle :getFiles [window [_ path]]
   (get-files path))
@@ -182,11 +183,11 @@
   (when dir
     (watcher/watch-dir! window dir)))
 
-(defmethod handle :openDialogSync [^js window _messages]
-  (let [result (.showOpenDialogSync dialog (bean/->js
-                                             {:properties ["openDirectory"]}))
-        path (first result)]
-    path))
+(defmethod handle :openDialog [^js window messages]
+  (p/let [result (.showOpenDialog dialog (bean/->js
+                                          {:properties ["openDirectory"]}))
+          result (get (js->clj result) "filePaths")]
+    (p/resolved (first result))))
 
 (defmethod handle :getLogseqDotDirRoot []
   (utils/get-ls-dotdir-root))

+ 1 - 1
src/main/frontend/handler/plugin.cljs

@@ -274,7 +274,7 @@
 (defn load-unpacked-plugin
   []
   (when util/electron?
-    (p/let [path (ipc/ipc "openDialogSync")]
+    (p/let [path (ipc/ipc "openDialog")]
       (when-not (:plugin/selected-unpacked-pkg @state/state)
         (state/set-state! :plugin/selected-unpacked-pkg path)))))