Add item uuid launch to quick access menu

This commit is contained in:
Bernd Schoolmann 2024-01-20 13:04:04 +01:00
parent 8eb55f2808
commit 2f21f27da9
No known key found for this signature in database
3 changed files with 90 additions and 70 deletions

View file

@ -3,7 +3,7 @@ gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
import gc
import time
from gi.repository import Gtk, Adw, GLib, Notify
from gi.repository import Gtk, Adw, GLib, Notify, Gdk
import goldwarden
import clipboard
from threading import Thread
@ -65,6 +65,7 @@ class MainWindow(Gtk.ApplicationWindow):
action_row.set_activatable(True)
action_row.password = i["password"]
action_row.username = i["username"]
action_row.uuid = i["uuid"]
self.history_list.append(action_row)
self.starts_with_logins = None
self.other_logins = None
@ -101,6 +102,13 @@ class MainWindow(Gtk.ApplicationWindow):
notification=Notify.Notification.new("Goldwarden", "Username Copied", "dialog-information")
notification.set_timeout(5)
notification.show()
elif keyval == 118:
print("open web vault")
environment = goldwarden.get_environment()
if environment == None:
return
item_uri = environment["vault"] + "#/vault?itemId=" + self.history_list.get_selected_row().uuid
Gtk.show_uri(None, item_uri, Gdk.CURRENT_TIME)
keycont.connect('key-pressed', handle_keypress, self)
self.add_controller(keycont)

View file

@ -27,6 +27,31 @@ def set_notification_url(url):
if result.returncode != 0:
raise Exception("Failed to initialize repository, err", result.stderr)
def set_vault_url(url):
restic_cmd = f"{BINARY_PATH} config set-vault-url {url}"
result = subprocess.run(restic_cmd.split(), capture_output=True, text=True)
if result.returncode != 0:
raise Exception("Failed err", result.stderr)
def set_url(url):
restic_cmd = f"{BINARY_PATH} config set-url {url}"
result = subprocess.run(restic_cmd.split(), capture_output=True, text=True)
if result.returncode != 0:
raise Exception("Failed err", result.stderr)
def get_environment():
restic_cmd = f"{BINARY_PATH} config get-environment"
result = subprocess.run(restic_cmd.split(), capture_output=True, text=True)
if result.returncode != 0:
return None
try:
result_text = result.stdout
print(result_text)
return json.loads(result_text)
except Exception as e:
print(e)
return None
def set_client_id(client_id):
restic_cmd = f"{BINARY_PATH} config set-client-id \"{client_id}\""
result = subprocess.run(restic_cmd.split(), capture_output=True, text=True)

View file

@ -39,6 +39,57 @@ class SettingsWinvdow(Gtk.ApplicationWindow):
self.preferences_page.set_title("General")
self.stack.add_named(self.preferences_page, "preferences_page")
self.action_preferences_group = Adw.PreferencesGroup()
self.action_preferences_group.set_title("Actions")
self.preferences_page.add(self.action_preferences_group)
self.autotype_button = Gtk.Button()
self.autotype_button.set_label("Quick Access")
self.autotype_button.set_margin_top(10)
self.autotype_button.connect("clicked", lambda button: subprocess.Popen(["python3", "/app/bin/autofill.py"], start_new_session=True))
self.autotype_button.get_style_context().add_class("suggested-action")
self.action_preferences_group.add(self.autotype_button)
self.login_button = Gtk.Button()
self.login_button.set_label("Login")
self.login_button.connect("clicked", lambda button: show_login())
self.login_button.set_sensitive(False)
self.login_button.set_margin_top(10)
self.login_button.get_style_context().add_class("suggested-action")
self.action_preferences_group.add(self.login_button)
self.set_pin_button = Gtk.Button()
self.set_pin_button.set_label("Set Pin")
self.set_pin_button.connect("clicked", lambda button: set_pin())
self.set_pin_button.set_margin_top(10)
self.set_pin_button.set_sensitive(False)
self.set_pin_button.get_style_context().add_class("suggested-action")
self.action_preferences_group.add(self.set_pin_button)
self.unlock_button = Gtk.Button()
self.unlock_button.set_label("Unlock")
self.unlock_button.set_margin_top(10)
def unlock_button_clicked():
action = goldwarden.unlock if self.unlock_button.get_label() == "Unlock" else goldwarden.lock
unlock_thread = Thread(target=action)
unlock_thread.start()
self.unlock_button.connect("clicked", lambda button: unlock_button_clicked())
# set disabled
self.unlock_button.set_sensitive(False)
self.action_preferences_group.add(self.unlock_button)
self.logout_button = Gtk.Button()
self.logout_button.set_label("Logout")
self.logout_button.set_margin_top(10)
self.logout_button.connect("clicked", lambda button: goldwarden.purge())
self.logout_button.get_style_context().add_class("destructive-action")
self.action_preferences_group.add(self.logout_button)
self.wiki_button = Gtk.LinkButton(uri="https://github.com/quexten/goldwarden/wiki/Flatpak-Configuration")
self.wiki_button.set_label("Help & Wiki")
self.wiki_button.set_margin_top(10)
self.action_preferences_group.add(self.wiki_button)
self.preferences_group = Adw.PreferencesGroup()
self.preferences_group.set_title("Services")
self.preferences_page.add(self.preferences_group)
@ -127,57 +178,6 @@ class SettingsWinvdow(Gtk.ApplicationWindow):
self.notes_row.set_subtitle("0")
self.notes_row.set_icon_name("emblem-documents-symbolic")
self.vault_status_preferences_group.add(self.notes_row)
self.action_preferences_group = Adw.PreferencesGroup()
self.action_preferences_group.set_title("Actions")
self.preferences_page.add(self.action_preferences_group)
self.autotype_button = Gtk.Button()
self.autotype_button.set_label("Autotype")
self.autotype_button.set_margin_top(10)
self.autotype_button.connect("clicked", lambda button: subprocess.Popen(["python3", "/app/bin/autofill.py"], start_new_session=True))
self.autotype_button.get_style_context().add_class("suggested-action")
self.action_preferences_group.add(self.autotype_button)
self.login_button = Gtk.Button()
self.login_button.set_label("Login")
self.login_button.connect("clicked", lambda button: show_login())
self.login_button.set_sensitive(False)
self.login_button.set_margin_top(10)
self.login_button.get_style_context().add_class("suggested-action")
self.action_preferences_group.add(self.login_button)
self.set_pin_button = Gtk.Button()
self.set_pin_button.set_label("Set Pin")
self.set_pin_button.connect("clicked", lambda button: set_pin())
self.set_pin_button.set_margin_top(10)
self.set_pin_button.set_sensitive(False)
self.set_pin_button.get_style_context().add_class("suggested-action")
self.action_preferences_group.add(self.set_pin_button)
self.unlock_button = Gtk.Button()
self.unlock_button.set_label("Unlock")
self.unlock_button.set_margin_top(10)
def unlock_button_clicked():
action = goldwarden.unlock if self.unlock_button.get_label() == "Unlock" else goldwarden.lock
unlock_thread = Thread(target=action)
unlock_thread.start()
self.unlock_button.connect("clicked", lambda button: unlock_button_clicked())
# set disabled
self.unlock_button.set_sensitive(False)
self.action_preferences_group.add(self.unlock_button)
self.logout_button = Gtk.Button()
self.logout_button.set_label("Logout")
self.logout_button.set_margin_top(10)
self.logout_button.connect("clicked", lambda button: goldwarden.purge())
self.logout_button.get_style_context().add_class("destructive-action")
self.action_preferences_group.add(self.logout_button)
self.wiki_button = Gtk.LinkButton(uri="https://github.com/quexten/goldwarden/wiki/Flatpak-Configuration")
self.wiki_button.set_label("Help & Wiki")
self.wiki_button.set_margin_top(10)
self.action_preferences_group.add(self.wiki_button)
def update_labels():
GLib.timeout_add(1000, update_labels)
@ -271,21 +271,10 @@ def show_login():
dialog.get_content_area().append(preference_group)
api_url_entry = Adw.EntryRow()
api_url_entry.set_title("API Url")
# set value
api_url_entry.set_text("https://vault.bitwarden.com/api")
preference_group.add(api_url_entry)
identity_url_entry = Adw.EntryRow()
identity_url_entry.set_title("Identity Url")
identity_url_entry.set_text("https://vault.bitwarden.com/identity")
preference_group.add(identity_url_entry)
notification_url_entry = Adw.EntryRow()
notification_url_entry.set_title("Notification URL")
notification_url_entry.set_text("https://notifications.bitwarden.com/")
preference_group.add(notification_url_entry)
url_entry = Adw.EntryRow()
url_entry.set_title("Base Url")
url_entry.set_text("https://vault.bitwarden.com/")
preference_group.add(url_entry)
auth_preference_group = Adw.PreferencesGroup()
auth_preference_group.set_title("Authentication")
@ -310,9 +299,7 @@ def show_login():
def on_save(res):
if res != Gtk.ResponseType.OK:
return
goldwarden.set_api_url(api_url_entry.get_text())
goldwarden.set_identity_url(identity_url_entry.get_text())
goldwarden.set_notification_url(notification_url_entry.get_text())
goldwarden.set_url(url_entry.get_text())
goldwarden.set_client_id(client_id_entry.get_text())
goldwarden.set_client_secret(client_secret_entry.get_text())
def login():