Skip to content

Persist enhancements #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{:paths ["src"]
:deps {akiroz.re-frame/storage {:mvn/version "0.1.4"}
binaryage/devtools {:mvn/version "1.0.7"}
:deps {binaryage/devtools {:mvn/version "1.0.7"}
camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.3"}
clj-kdtree/clj-kdtree {:git/url "https://github.com/abscondment/clj-kdtree.git"
:sha "5ec321c5e8006db00fa8b45a8ed9eb0b8f3dd56d"
Expand Down
28 changes: 28 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"karma-cljs-test": "0.1.0",
"karma-electron": "7.3.0",
"karma-junit-reporter": "2.0.1",
"localforage": "1.10.0",
"mdn-data": "2.21.0",
"npm-run-all": "4.1.5",
"opentype.js": "1.3.4",
Expand Down
2 changes: 0 additions & 2 deletions src/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

(def ext "rps")

(def app-key :repath-studio)

(def app-name "Repath Studio")

(def mime-type "application/x-repath-studio")
Expand Down
45 changes: 20 additions & 25 deletions src/electron/main.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
(when (and (secure-url? url-parsed) (allowed-url? url-parsed))
(.openExternal shell url-parsed.href))))

(defn register-ipc-on-events!
[]
(defn register-ipc-on-events! []
(doseq
[[e f]
[["relaunch" #(do (.relaunch app) (.exit app))]
[["initialized" #(.close ^js @loading-window)]
["relaunch" #(doto app (.relaunch) (.exit))]
["open-remote-url" open-external!]
["open-directory" #(.showItemInFolder shell %)]
["window-minimize" #(.minimize ^js @main-window)]
Expand All @@ -59,8 +59,7 @@
(.maximize ^js @main-window))]]]
(.on ipcMain e #(f %2))))

(defn register-ipc-handle-events!
[]
(defn register-ipc-handle-events! []
(doseq
[[e f]
[["open-documents" file/open!]
Expand All @@ -70,8 +69,7 @@
["print" file/print!]]]
(.handle ipcMain e #(f %2))))

(defn register-window-events!
[]
(defn register-window-events! []
(doseq
[[window-event f]
[["maximize" #(send-to-renderer! "window-maximized")]
Expand All @@ -87,31 +85,29 @@
"window-unmaximized"))]]]
(.on ^js @main-window window-event f)))

(defn register-web-contents-events!
[]
(doseq
[[web-contents-event f]
[["will-frame-navigate" #(.preventDefault %)]
["closed" #(reset! main-window nil)]]]
(.on (.-webContents ^js @main-window) web-contents-event f)))
(defn register-web-contents-events! []
(let [web-contents (.-webContents ^js @main-window)]
(doseq
[[web-contents-event f]
[["will-frame-navigate" #(.preventDefault %)]
["closed" #(reset! main-window nil)]]]
(.on web-contents web-contents-event f))))

(defn handle-on-ready-to-show!
(defn on-ready-to-show!
[^js window]
(doseq
[action
[(if (.isMaximized window) "window-maximized" "window-unmaximized")
(if (.isFullScreen window) "window-entered-fullscreen" "window-leaved-fullscreen")
(if (.isFocused window) "window-focused" "window-blurred")
"window-loaded"]]
(if (.isFocused window) "window-focused" "window-blurred")]]
(send-to-renderer! action)))

(defn resource-path
[s]
(url/format #js {:pathname (.join path js/__dirname s)
:protocol "file"}))

(defn init-main-window!
[]
(defn init-main-window! []
(let [win-state (window-state-keeper #js {:defaultWidth 1920
:defaultHeight 1080})]
(reset! main-window
Expand All @@ -120,12 +116,12 @@
:y (.-y win-state)
:width (.-width win-state)
:height (.-height win-state)
:backgroundColor "#313131"
:titleBarStyle (when (= (.platform os) "darwin") "hidden")
:trafficLightPosition #js {:x 8 :y 10}
:icon (.join path js/__dirname "/public/img/icon.png")
:frame false
:show false
:transparent true
:webPreferences
#js {:sandbox false
:preload (.join path js/__dirname "preload.js")}}))
Expand All @@ -134,11 +130,9 @@
"ready-to-show"
(fn []
(.show ^js @main-window)
(.manage win-state ^js @main-window)
(.hide ^js @loading-window)
(.close ^js @loading-window)))
(.manage win-state ^js @main-window)))

(.on ^js @main-window "ready-to-show" #(handle-on-ready-to-show! @main-window))
(.on ^js @main-window "ready-to-show" #(on-ready-to-show! @main-window))

(.loadURL ^js @main-window
(if config/debug?
Expand All @@ -156,9 +150,10 @@
(BrowserWindow.
#js {:width 720
:height 576
:backgroundColor "#313131"
:icon (.join path js/__dirname "/public/img/icon.png")
:show false
:alwaysOnTop true
:transparent true
:frame false}))
(.once ^js @loading-window "show" init-main-window!)
(.loadURL ^js @loading-window (resource-path "/public/loading.html"))
Expand Down
4 changes: 3 additions & 1 deletion src/lang/ar-EG.edn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
:source-code "الكود المصدري"
:changelog "سجل التغييرات"}

:renderer.app.events
{:create-doc "إنشاء مستند"}

:renderer.dialog.views
{:search-command "البحث عن أمر"
:no-results "لا توجد نتائج."
Expand Down Expand Up @@ -502,7 +505,6 @@
:renderer.document.events
{:save-changes "هل تريد حفظ التغييرات؟"
:create-doc "إنشاء مستند"
:init-doc "تهيئة مستند"
:create-doc-from-template "إنشاء مستند من قالب"
:load-doc "تحميل مستند"
:error-loading "خطأ أثناء تحميل %1"
Expand Down
4 changes: 3 additions & 1 deletion src/lang/el-GR.edn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
:source-code "Πηγαίος κώδικας"
:changelog "Αρχείο αλλαγών"}

:renderer.app.events
{:create-doc "Δημιουργία εγγράφου"}

:renderer.dialog.views
{:search-command "Αναζήτηση εντολής"
:no-results "Δεν βρέθηκαν αποτελέσματα."
Expand Down Expand Up @@ -546,7 +549,6 @@
:renderer.document.events
{:save-changes "Θέλετε να αποθηκεύσετε τις αλλαγές σας;"
:create-doc "Δημιουργία εγγράφου"
:init-doc "Αρχικοποίηση εγγράφου"
:create-doc-from-template "Δημιουργία εγγράφου από πρότυπο"
:load-doc "Φόρτωση εγγράφου"
:error-loading "Σφάλμα κατα τη φόρτωση %1"
Expand Down
4 changes: 3 additions & 1 deletion src/lang/en-US.edn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
:source-code "Source Code"
:changelog "Changelog"}

:renderer.app.events
{:create-doc "Create document"}

:renderer.dialog.views
{:search-command "Search for a command"
:no-results "No results found."
Expand Down Expand Up @@ -518,7 +521,6 @@
:renderer.document.events
{:save-changes "Do you want to save your changes?"
:create-doc "Create document"
:init-doc "Init document"
:create-doc-from-template "Create document from template"
:load-doc "Load document"
:error-loading "Error while loading %1"
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/app/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@
[:notifications {:default []} [:* Notification]]
[:debug-info {:default false} boolean?]
[:help-bar {:default true} boolean?]
[:loading {:default true} boolean?]
[:pen-mode {:default false} boolean?]
[:backdrop {:default false} boolean?]
[:lang {:optional true :persist true} Lang]
[:dir {:optional true :persist true} string?]
[:system-lang {:optional true} string?]
[:platform {:optional true} Platform]
[:versions {:optional true} [:maybe map?]]
[:env {:optional true} [:maybe map?]]
Expand Down
37 changes: 25 additions & 12 deletions src/renderer/app/effects.cljs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
(ns renderer.app.effects
(:require
[akiroz.re-frame.storage :as rf.storage]
["localforage" :as localforage]
[cognitect.transit :as transit]
[config :as config]
[re-frame.core :as rf]
[re-frame.db :as rf.db]
[renderer.app.db :as app.db]
[renderer.history.handlers :as history.handlers]))

(rf.storage/reg-co-fx! config/app-key {:cofx :store})
[renderer.history.handlers :as history.handlers]
[renderer.notification.events :as-alias notification.events]))

(rf/reg-cofx
::platform
Expand Down Expand Up @@ -36,29 +36,42 @@
(assoc coeffects :user-agent (.-userAgent js/navigator))))

(rf/reg-cofx
::system-language
::language
(fn [coeffects _]
(assoc coeffects :system-language (.-language js/navigator))))
(assoc coeffects :language (.-language js/navigator))))

(rf/reg-fx
::query-local-fonts
(fn [{:keys [on-success on-error formatter]}]
(when-not (undefined? js/window.queryLocalFonts)
(-> (.queryLocalFonts js/window)
(.then #(when on-success (rf/dispatch (conj on-success
(cond-> %
formatter formatter)))))
(.then #(when on-success (rf/dispatch (conj on-success (cond-> %
formatter formatter)))))
(.catch #(when on-error (rf/dispatch (conj on-error %))))))))

(defn json->clj
[json]
(transit/read (transit/reader :json) json))

(rf/reg-fx
::get-local-db
(fn [{:keys [on-success on-error on-finally]}]
(-> (localforage/getItem config/app-name)
(.then #(when on-success (rf/dispatch (conj on-success (json->clj %)))))
(.catch #(when on-error (rf/dispatch (conj on-error %))))
(.finally #(when on-finally (rf/dispatch on-finally))))))

(rf/reg-fx
::persist
(fn []
(let [db @rf.db/app-db
db (cond-> db
(:active-document db)
history.handlers/drop-rest)]
(->> (select-keys db app.db/persisted-keys)
(rf.storage/->store config/app-key)))))
(.catch (->> (select-keys db app.db/persisted-keys)
(transit/write (transit/writer :json))
(localforage/setItem config/app-name))
#(rf/dispatch [::notification.events/show-exception %])))))

(rf/reg-fx
::validate
Expand All @@ -70,4 +83,4 @@
(rf/reg-fx
::clear-local-storage
(fn []
(rf.storage/->store config/app-key {})))
(localforage/clear)))
Loading