瀏覽代碼

fix: persist zoom level on navigation

Konstantinos Kaloutas 3 年之前
父節點
當前提交
73bbcc2ba0
共有 3 個文件被更改,包括 13 次插入2 次删除
  1. 4 0
      resources/js/preload.js
  2. 3 1
      src/electron/electron/window.cljs
  3. 6 1
      src/main/frontend/ui.cljs

+ 4 - 0
resources/js/preload.js

@@ -168,5 +168,9 @@ contextBridge.exposeInMainWorld('apis', {
     webFrame.setZoomFactor(factor)
   },
 
+  setZoomLevel (level) {
+    webFrame.setZoomLevel(level)
+  },
+
   isAbsolutePath: path.isAbsolute.bind(path)
 })

+ 3 - 1
src/electron/electron/window.cljs

@@ -143,7 +143,9 @@
 
       (doto web-contents
         (.on "new-window" new-win-handler)
-        (.on "will-navigate" will-navigate-handler))
+        (.on "will-navigate" will-navigate-handler)
+        (.on "did-start-navigation" #(.send web-contents "persist-zoom-level" (.getZoomLevel web-contents)))
+        (.on "did-navigate-in-page" #(.send web-contents "restore-zoom-level")))
 
       (doto win
         (.on "enter-full-screen" #(.send web-contents "full-screen" "enter"))

+ 6 - 1
src/main/frontend/ui.cljs

@@ -7,6 +7,7 @@
             [frontend.modules.shortcut.core :as shortcut]
             [frontend.rum :as r]
             [frontend.state :as state]
+            [frontend.storage :as storage]
             [frontend.ui.date-picker]
             [frontend.util :as util]
             [frontend.util.cursor :as cursor]
@@ -337,7 +338,11 @@
     (when (mobile-util/native-iphone-without-notch?) (.add cl "is-native-iphone-without-notch"))
     (when (mobile-util/native-ipad?) (.add cl "is-native-ipad"))
     (when (util/electron?)
-      (js/window.apis.on "full-screen" #(js-invoke cl (if (= % "enter") "add" "remove") "is-fullscreen"))
+      (doto js/window.apis
+        (.on "persist-zoom-level" #(storage/set :zoom-level %))
+        (.on "restore-zoom-level" #(when-let [zoom-level (storage/get :zoom-level)]
+                                     (js/window.apis.setZoomLevel zoom-level)))
+        (.on "full-screen" #(js-invoke cl (if (= % "enter") "add" "remove") "is-fullscreen")))
       (p/then (ipc/ipc :getAppBaseInfo) #(let [{:keys [isFullScreen]} (js->clj % :keywordize-keys true)]
                                            (and isFullScreen (.add cl "is-fullscreen")))))))