Compare commits
3 Commits
3d305a0d70
...
06174de597
| Author | SHA1 | Date | |
|---|---|---|---|
| 06174de597 | |||
| e6523e0a7b | |||
| 78da3c37c0 |
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/env sh
|
#!/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
|
#javac -cp resources/protobuf-java-3.25.8.jar -d target/classes/proto src/OtpauthMigration.java
|
||||||
|
|||||||
@@ -100,20 +100,28 @@
|
|||||||
([secret]
|
([secret]
|
||||||
(get-otp secret "sha1" 6 30)))
|
(get-otp secret "sha1" 6 30)))
|
||||||
|
|
||||||
|
|
||||||
(defn calculate-offset-millis
|
(defn calculate-offset-millis
|
||||||
[period]
|
[period]
|
||||||
(let [step-millis (* 1000 period)
|
(let [step-millis (* 1000 period)
|
||||||
now (System/currentTimeMillis)]
|
now (System/currentTimeMillis)]
|
||||||
(int (rem now step-millis))))
|
(int (rem now step-millis))))
|
||||||
|
|
||||||
|
|
||||||
(defn calculate-delay-millis
|
(defn calculate-delay-millis
|
||||||
[period]
|
[period]
|
||||||
(let [step-millis (* 1000 period)]
|
(let [step-millis (* 1000 period)]
|
||||||
(inc (- step-millis (calculate-offset-millis period)))))
|
(- step-millis (calculate-offset-millis period))))
|
||||||
|
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(do
|
(let [now (System/currentTimeMillis)
|
||||||
(println "Now in seconds: " (int (/ (System/currentTimeMillis) 1000)))
|
off (calculate-offset-millis 30)
|
||||||
(println "Offset in seconds: " (int (/ (calculate-offset-millis 30) 1000)))
|
delay (calculate-delay-millis 30)
|
||||||
(println "Delay in seconds: " (int (/ (calculate-delay-millis 30) 1000))))
|
]
|
||||||
)
|
(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")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
[seesaw.core :refer :all]
|
[seesaw.core :refer :all]
|
||||||
[seesaw.mig :refer :all]
|
[seesaw.mig :refer :all]
|
||||||
[seesaw.clipboard :as cp]
|
[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
|
(defn make-otp-list
|
||||||
|
"Make panel with OTPs"
|
||||||
[]
|
[]
|
||||||
(mig-panel
|
(mig-panel
|
||||||
:constraints ["wrap 3"
|
:constraints ["wrap 3"
|
||||||
@@ -61,22 +63,30 @@
|
|||||||
|
|
||||||
(comment
|
(comment
|
||||||
(make-otp-list)
|
(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
|
(defn make-frame-content
|
||||||
[]
|
[]
|
||||||
(border-panel :hgap 10 :vgap 10
|
(border-panel :hgap 10 :vgap 10
|
||||||
:center (make-otp-list)
|
:center (make-otp-list)
|
||||||
;:north "NORTH"
|
:north (make-time-bar (int(/ (calculate-offset-millis 30) 1000)))
|
||||||
;:south "SOUTH"
|
;:south "SOUTH"
|
||||||
;:east "EAST"
|
;:east "EAST"
|
||||||
;:west "WEST"
|
;:west "WEST"
|
||||||
@@ -86,21 +96,43 @@
|
|||||||
(defn make-frame
|
(defn make-frame
|
||||||
"Make main frame's content"
|
"Make main frame's content"
|
||||||
[]
|
[]
|
||||||
(frame :title "Hello",
|
(frame :title "TOTP",
|
||||||
;:content "Hello, Seesaw"
|
|
||||||
:content (make-frame-content)
|
:content (make-frame-content)
|
||||||
;:content (content-test2 nil nil nil nil)
|
|
||||||
;:minimum-size [320 :by 240]
|
;:minimum-size [320 :by 240]
|
||||||
;;:on-close :exit
|
;;:on-close :exit
|
||||||
:on-close :dispose))
|
: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]
|
(defn -main [& args]
|
||||||
(native!)
|
(native!)
|
||||||
(invoke-later
|
(invoke-later
|
||||||
(-> (make-frame)
|
(-> (make-frame)
|
||||||
pack!
|
pack!
|
||||||
show!)))
|
show!
|
||||||
|
start-updater))
|
||||||
|
(println "Gui started"))
|
||||||
|
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
;; This kills your REPL connection
|
;; This kills your REPL connection
|
||||||
@@ -108,4 +140,5 @@
|
|||||||
|
|
||||||
(show-options (frame))
|
(show-options (frame))
|
||||||
(show-options (text))
|
(show-options (text))
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user