Class: Otpui::OtpList
- Inherits:
-
Object
- Object
- Otpui::OtpList
- Defined in:
- lib/otpui/otp_list.rb
Instance Method Summary collapse
- #get_current_second(totp, otp) ⇒ Object
- #get_fraction_progress(totp, otp) ⇒ Object
-
#initialize(builder) ⇒ OtpList
constructor
A new instance of OtpList.
- #list_size ⇒ Object
- #refresh_all ⇒ Object
- #refresh_progress_bar ⇒ Object
- #refresh_values ⇒ Object
- #run ⇒ Object
- #update_row(iter, secret = nil, issuer = nil) ⇒ Object
Constructor Details
#initialize(builder) ⇒ OtpList
Returns a new instance of OtpList.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/otpui/otp_list.rb', line 3 def initialize(builder) @otps = Settings.load.secrets @model = Gtk::ListStore.new(String, String) = builder["totp_timeout_progress_bar"] text_renderer = Gtk::CellRendererText.new column_name = Gtk::TreeViewColumn.new("Issuer", text_renderer, { text: 0 }) column_secret = Gtk::TreeViewColumn.new("Secret", text_renderer, { text: 1 }) treeview = Gtk::TreeView.new(@model) treeview.append_column(column_name) treeview.append_column(column_secret) treeview.selection.set_mode(:single) builder["scrolled_otps_win"].(treeview) treeview.signal_connect("row_activated") do |_treeview, path, _column| iter = @model.get_iter(path) Clipboard.copy iter[1] end end |
Instance Method Details
#get_current_second(totp, otp) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/otpui/otp_list.rb', line 31 def get_current_second(totp, otp) future_seconds = 0.0 while totp.verify(otp, Time.now + future_seconds) future_seconds += 1 end future_seconds end |
#get_fraction_progress(totp, otp) ⇒ Object
39 40 41 |
# File 'lib/otpui/otp_list.rb', line 39 def get_fraction_progress(totp, otp) get_current_second(totp, otp) / 30 end |
#list_size ⇒ Object
25 26 27 28 29 |
# File 'lib/otpui/otp_list.rb', line 25 def list_size i = 0 @model.each { i += 1 } i end |
#refresh_all ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/otpui/otp_list.rb', line 57 def refresh_all @model.clear @otps.each do |issuer, secret| iter = @model.append update_row iter, secret, issuer end end |
#refresh_progress_bar ⇒ Object
65 66 67 68 |
# File 'lib/otpui/otp_list.rb', line 65 def totp = ROTP::TOTP.new("progress32secret3232") .fraction = get_fraction_progress(totp, totp.now.to_s) end |
#refresh_values ⇒ Object
51 52 53 54 55 |
# File 'lib/otpui/otp_list.rb', line 51 def refresh_values @model.each do |_model, path, iter| update_row iter end end |
#run ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/otpui/otp_list.rb', line 70 def run GLib::Timeout.add(1000) do list_size == @otps.size ? refresh_values : refresh_all true end end |
#update_row(iter, secret = nil, issuer = nil) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/otpui/otp_list.rb', line 43 def update_row(iter, secret = nil, issuer = nil) secret = @otps.fetch iter[0] unless secret iter[0] = issuer if issuer totp = ROTP::TOTP.new(secret) iter[1] = totp.now.to_s end |