Compare commits

...

3 Commits

Author SHA1 Message Date
06174de597 trying to update progress bar 2025-11-03 14:55:19 +01:00
e6523e0a7b status bar changes 2025-11-03 12:48:43 +01:00
78da3c37c0 Empty status bar 2025-11-03 11:52:48 +01:00
3 changed files with 63 additions and 22 deletions

View File

@@ -1,4 +1,4 @@
#!/bin/env sh
protoc --java_out java/protoc/ resources/proto/otpauth-migration.proto
protoc --java_out projects/core/java/protoc/ projects/core/resources/proto/otpauth-migration.proto
#javac -cp resources/protobuf-java-3.25.8.jar -d target/classes/proto src/OtpauthMigration.java

View File

@@ -100,20 +100,28 @@
([secret]
(get-otp secret "sha1" 6 30)))
(defn calculate-offset-millis
[period]
(let [step-millis (* 1000 period)
now (System/currentTimeMillis)]
(int (rem now step-millis))))
(defn calculate-delay-millis
[period]
(let [step-millis (* 1000 period)]
(inc (- step-millis (calculate-offset-millis period)))))
(- step-millis (calculate-offset-millis period))))
(comment
(do
(println "Now in seconds: " (int (/ (System/currentTimeMillis) 1000)))
(println "Offset in seconds: " (int (/ (calculate-offset-millis 30) 1000)))
(println "Delay in seconds: " (int (/ (calculate-delay-millis 30) 1000))))
)
(let [now (System/currentTimeMillis)
off (calculate-offset-millis 30)
delay (calculate-delay-millis 30)
]
(println "Now: " (int (/ now 1000)) "secs" now "millis")
(println "Offset:" (int (/ off 1000)) "secs" off "millis")
(println "Delay: " (int (/ delay 1000)) "secs" delay "millis")
(println "Total: " (+ (int (/ off 1000)) (int (/ delay 1000))) "secs" (+ delay off) "millis")
)
)

View File

@@ -6,7 +6,8 @@
[seesaw.core :refer :all]
[seesaw.mig :refer :all]
[seesaw.clipboard :as cp]
[seesaw.dev :refer :all]))
[seesaw.dev :refer :all])
(:import [java.util TimerTask Timer]))
@@ -43,6 +44,7 @@
(defn make-otp-list
"Make panel with OTPs"
[]
(mig-panel
:constraints ["wrap 3"
@@ -61,22 +63,30 @@
(comment
(make-otp-list)
(let [apps (with-config (filter some? #_{:clj-kondo/ignore [:unresolved-symbol]} cfg))]
(reduce (fn [acc a]
(let [{:keys [name secret algorithm digits period]} a]
(-> acc
(conj [name])
(conj [(get-otp secret algorithm digits period)]))
))
[] apps))
)
(defn make-time-bar
"Make the progress bar with the remaining time"
[init-val]
(border-panel
:hgap 5
:center (progress-bar :id "timer-bar"
:value init-val
:max 30)
:east (text :id "timer-text"
:text init-val
:editable? false
:columns 2
:halign :right)
))
(defn make-frame-content
[]
(border-panel :hgap 10 :vgap 10
:center (make-otp-list)
;:north "NORTH"
:north (make-time-bar (int(/ (calculate-offset-millis 30) 1000)))
;:south "SOUTH"
;:east "EAST"
;:west "WEST"
@@ -86,21 +96,43 @@
(defn make-frame
"Make main frame's content"
[]
(frame :title "Hello",
;:content "Hello, Seesaw"
(frame :title "TOTP",
:content (make-frame-content)
;:content (content-test2 nil nil nil nil)
;:minimum-size [320 :by 240]
;;:on-close :exit
:on-close :dispose))
(defn update-progress
[root]
(let [time-bar (select root [:#timer-bar])
time-text (select root [:#timer-text])
offset (int (/ (calculate-offset-millis 30) 1000))]
(println "Updating at at" (System/currentTimeMillis))
(config! time-bar :value offset)
(config! time-text :text offset)
))
(defn start-updater
[root]
(. (new Timer) (scheduleAtFixedRate
(proxy [TimerTask] []
(run [] (update-progress root)))
(calculate-delay-millis 30)
(* 30 1000)))
)
(defn -main [& args]
(native!)
(invoke-later
(-> (make-frame)
pack!
show!)))
show!
start-updater))
(println "Gui started"))
(comment
;; This kills your REPL connection
@@ -108,4 +140,5 @@
(show-options (frame))
(show-options (text))
)