Skip to content

Commit

Permalink
new preference 'check-for-update' (#417)
Browse files Browse the repository at this point in the history
* config, adds new preference 'check-for-update'
* cli, adds new flag '--update-check' and it's complement '--no-update-check'
torkus authored Nov 23, 2023
1 parent eee4a98 commit 496cdb9
Showing 9 changed files with 100 additions and 39 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `flatpak-id`, looks like `la.ogri.strongbox` when running within a Flatpak.
* added plain-text and JSON views of the raw addon data to the 'raw data' widget on the addon detail tab.
- it's pretty basic but JavaFX really resists being able to select text within it's widgets.
* added new preference 'check for update' that toggles checking for an update to Strongbox on startup (default is `true`).
* added new command line flag `--update-check` and it's complement `--no-update-check` that toggles update checks.

### Changed

2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
:pedantic? false

:dependencies [[org.clojure/clojure "1.10.3"]
[org.clojure/tools.cli "1.0.214"] ;; cli arg parsing
[org.clojure/tools.cli "1.0.219"] ;; cli arg parsing
[org.clojure/tools.namespace "1.4.4"] ;; reload code
[org.clojure/data.json "2.4.0"] ;; json handling
[orchestra "2021.01.01-1"] ;; improved clojure.spec instrumentation
5 changes: 4 additions & 1 deletion src/strongbox/config.clj
Original file line number Diff line number Diff line change
@@ -52,7 +52,10 @@
:ui-selected-columns sp/default-column-list

;; refresh the user-catalogue every N days
:keep-user-catalogue-updated false}})
:keep-user-catalogue-updated false

;; fetch latest version details from github
:check-for-update true}})

(defn handle-install-dir
"`:install-dir` was once supported in the user configuration but is now only supported in the command line options.
30 changes: 15 additions & 15 deletions src/strongbox/core.clj
Original file line number Diff line number Diff line change
@@ -450,7 +450,7 @@
(swap! state merge final-config)
(reset-logging!)
;; erm, this is something I use while developing: (restart {:spec? false})
;; spec checking slows everything down so turning it off gives me a feel of actual performance.
;; spec checking slows everything down so turning it off gives me a feel for actual performance.
(when (contains? cli-opts :spec?)
(utils/instrument (:spec? cli-opts))))
nil)
@@ -1427,16 +1427,18 @@
(defn-spec latest-strongbox-release! ::sp/latest-strongbox-release
"downloads and sets the most recently released version of strongbox on github, returning the found version or `:failed` on error."
[]
(let [lsr (get-state :latest-strongbox-release)]
(case lsr
;; we haven't looked yet, so look.
nil (let [lsr (-download-strongbox-release)]
(swap! state assoc :latest-strongbox-release lsr)
lsr)
;; we've already looked and failed, don't try again this session.
:failed nil
;; we've already looked, return what we found
lsr)))
(let [lsr (get-state :latest-strongbox-release)
check-for-update? (get-state :cfg :preferences :check-for-update)]
(when check-for-update?
(case lsr
;; we haven't looked yet, so look.
nil (let [lsr (-download-strongbox-release)]
(swap! state assoc :latest-strongbox-release lsr)
lsr)
;; we've already looked and failed, don't try again this session.
:failed nil
;; we've already looked, return what we found
lsr))))

;; stats

@@ -1784,8 +1786,7 @@

useful-state
[[:state :paths :config-dir]
[:state :paths :data-dir]
]
[:state :paths :data-dir]]

useful-props
["javafx.version" ;; "15.0.1"
@@ -1814,8 +1815,7 @@
key-list (-> []
(into useful-state)
(into useful-props)
(into useful-envvars))
]
(into useful-envvars))]
(doseq [key key-list]
(if (sequential? key)
(let [val (nm key)]
12 changes: 11 additions & 1 deletion src/strongbox/jfx.clj
Original file line number Diff line number Diff line change
@@ -1474,6 +1474,15 @@
:on-action (fn [_]
(cli/set-preference :keep-user-catalogue-updated (not selected?)))}))

(defn menu-item--check-for-update
[{:keys [fx/context]}]
(let [selected? (fx/sub-val context get-in [:app-state :cfg :preferences :check-for-update])]
{:fx/type :check-menu-item
:text "Check for updates when app starts"
:selected selected?
:on-action (fn [_]
(cli/set-preference :check-for-update (not selected?)))}))

(defn-spec build-column-menu ::sp/list-of-maps
"returns a list of columns that are 'selected' if present in `selected-column-list`."
[selected-column-list :ui/column-list]
@@ -1532,7 +1541,8 @@
(menu-item "E_xit" exit-handler {:key "Ctrl+Q"})]

prefs-menu [{:fx/type menu-item--num-zips-to-keep}
{:fx/type menu-item--keep-user-catalogue-updated}]
{:fx/type menu-item--keep-user-catalogue-updated}
{:fx/type menu-item--check-for-update}]

view-menu (into
[(menu-item "Refresh" (async-handler core/hard-refresh) {:key "F5"})
9 changes: 6 additions & 3 deletions src/strongbox/main.clj
Original file line number Diff line number Diff line change
@@ -112,7 +112,11 @@
["-a" "--action ACTION" "perform action and exit. action is one of: 'list', 'list-updates', 'update-all'"
:id :action
:parse-fn #(-> % lower-case keyword)
:validate [(in? [:print-config :list :list-updates :update-all])]]])
:validate [(in? [:print-config :list :list-updates :update-all])]]

[nil "--[no-]update-check"
:id :check-for-update
:default true]])

(defn validate
[parsed]
@@ -158,8 +162,7 @@
;; force `:noui` for certain actions
args (if (contains? #{:print-config} (:action options))
(assoc-in args [:options :ui] :noui)
args)
]
args)]
args))))

(defn exit
3 changes: 2 additions & 1 deletion test/fixtures/user-config-7.0.json
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@
"ui-selected-columns": [
"source", "name", "description", "installed-version", "available-version", "game-version", "uber-button"
],
"keep-user-catalogue-updated": true
"keep-user-catalogue-updated": true,
"check-for-update": false
}
}
70 changes: 56 additions & 14 deletions test/strongbox/config_test.clj
Original file line number Diff line number Diff line change
@@ -199,7 +199,10 @@
:combined-version
:game-version :uber-button]
;; new in 6.2.0
:keep-user-catalogue-updated false}}
:keep-user-catalogue-updated false

;; new in 7.1.0
:check-for-update true}}

:cli-opts {}
:file-opts {:debug? true
@@ -236,7 +239,10 @@
:combined-version
:game-version :uber-button]
;; new in 6.2.0
:keep-user-catalogue-updated false}}
:keep-user-catalogue-updated false

;; new in 7.1.0
:check-for-update true}}

:cli-opts {}
:file-opts {:selected-catalogue :full
@@ -274,7 +280,10 @@
:combined-version
:game-version :uber-button]
;; new in 6.2.0
:keep-user-catalogue-updated false}}
:keep-user-catalogue-updated false

;; new in 7.1.0
:check-for-update true}}

:cli-opts {}
:file-opts {:gui-theme :dark
@@ -313,7 +322,10 @@
:combined-version
:game-version :uber-button]
;; new in 6.2.0
:keep-user-catalogue-updated false}}
:keep-user-catalogue-updated false

;; new in 7.1.0
:check-for-update true}}

:cli-opts {}
:file-opts {:gui-theme :dark
@@ -351,7 +363,10 @@
:combined-version
:game-version :uber-button]
;; new in 6.2.0
:keep-user-catalogue-updated false}}
:keep-user-catalogue-updated false

;; new in 7.1.0
:check-for-update true}}

:cli-opts {}
:file-opts {:gui-theme :dark
@@ -401,7 +416,10 @@
:combined-version
:game-version :uber-button]
;; new in 6.2.0
:keep-user-catalogue-updated false}}
:keep-user-catalogue-updated false

;; new in 7.1.0
:check-for-update true}}

:cli-opts {}
:file-opts {:gui-theme :dark
@@ -452,7 +470,10 @@
:combined-version
:game-version :uber-button]
;; new in 6.2.0
:keep-user-catalogue-updated false}}
:keep-user-catalogue-updated false

;; new in 7.1.0
:check-for-update true}}

:cli-opts {}
:file-opts {:gui-theme :dark-green
@@ -502,7 +523,10 @@
:combined-version
:game-version :uber-button]
;; new in 6.2.0
:keep-user-catalogue-updated false}}
:keep-user-catalogue-updated false

;; new in 7.1.0
:check-for-update true}}

:cli-opts {}
:file-opts {:gui-theme :dark-green
@@ -549,7 +573,10 @@
;; new in 4.7.0
:ui-selected-columns [:source :name :description :available-version :uber-button]
;; new in 6.2.0
:keep-user-catalogue-updated false}}
:keep-user-catalogue-updated false

;; new in 7.1.0
:check-for-update true}}

:cli-opts {}
:file-opts {:gui-theme :dark-green
@@ -598,7 +625,10 @@
;; new in 4.7.0
:ui-selected-columns [:source :name :description :available-version :uber-button]
;; new in 6.2.0
:keep-user-catalogue-updated false}}
:keep-user-catalogue-updated false

;; new in 7.1.0
:check-for-update true}}

:cli-opts {}
:file-opts {:gui-theme :dark-green
@@ -652,7 +682,10 @@
:combined-version ;; new default in 5.0.0
:game-version :uber-button]
;; new in 6.2.0
:keep-user-catalogue-updated false}}
:keep-user-catalogue-updated false

;; new in 7.1.0
:check-for-update true}}

:cli-opts {}
:file-opts {:gui-theme :dark-green
@@ -707,7 +740,10 @@
:combined-version ;; new default in 5.0.0
:game-version :uber-button]
;; new in 6.2.0
:keep-user-catalogue-updated true}}
:keep-user-catalogue-updated true

;; new in 7.1.0
:check-for-update true}}

:cli-opts {}
:file-opts {:gui-theme :dark-green
@@ -763,7 +799,10 @@
:combined-version ;; new default in 5.0.0
:game-version :uber-button]
;; new in 6.2.0
:keep-user-catalogue-updated true}}
:keep-user-catalogue-updated true

;; new in 7.1.0
:check-for-update false}}

:cli-opts {}
:file-opts {:gui-theme :dark-green
@@ -787,7 +826,10 @@
:ui-selected-columns [:source :name :description
:installed-version :available-version ;; replaced in 5.0.0
:game-version :uber-button]
:keep-user-catalogue-updated true}}
:keep-user-catalogue-updated true

;; new in 7.1.0
:check-for-update false}}
:env {:no-color false}
:etag-db {}}]
(is (= expected (config/load-settings cli-opts cfg-file etag-db-file))))))
6 changes: 3 additions & 3 deletions test/strongbox/core_test.clj
Original file line number Diff line number Diff line change
@@ -1532,7 +1532,7 @@
(testing "throttled github response status for strongbox release data returns `:failed`"
(let [fake-routes {"https://api.github.com/repos/ogri-la/strongbox/releases/latest"
{:get (fn [req] {:status 403 :reason-phrase "asdf"})}}]
(with-running-app
(with-running-app+opts {:cfg {:preferences {:check-for-update true}}}
(with-global-fake-routes-in-isolation fake-routes
(is (= :failed (core/latest-strongbox-release!))))))))

@@ -1541,7 +1541,7 @@
(let [fake-routes {"https://api.github.com/repos/ogri-la/strongbox/releases/latest"
{:get (fn [req] {:status 403 :reason-phrase "asdf"})}}
expected "foo.bar.baz"]
(with-running-app
(with-running-app+opts {:cfg {:preferences {:check-for-update true}}}
(swap! core/state assoc :latest-strongbox-release expected)
(with-global-fake-routes-in-isolation fake-routes
(is (= expected (core/latest-strongbox-release!))))))))
@@ -1553,7 +1553,7 @@
(and (core/unsteady? (:name addon*))
(not (empty? (core/get-state :unsteady-addon-list)))))
addon-fn-affective (core/affects-addon-wrapper addon-fn)]
(with-running-app
(with-running-app+opts {:cfg {:preferences {:check-for-update true}}}
(is (empty? (core/get-state :unsteady-addon-list)))
(is (true? (addon-fn-affective addon)))
(is (empty? (core/get-state :unsteady-addon-list)))))))

0 comments on commit 496cdb9

Please sign in to comment.