Add GTK blueprint for settings

This commit is contained in:
Bernd Schoolmann 2024-04-30 22:53:29 +02:00
parent 142b8088bc
commit 34dd188a98
No known key found for this signature in database
5 changed files with 447 additions and 282 deletions

1
.gitignore vendored
View file

@ -5,3 +5,4 @@ __pycache__
flatpak-pip-generator flatpak-pip-generator
repo repo
__debug* __debug*
.templates

43
gui/src/gui/main_view.blp Normal file
View file

@ -0,0 +1,43 @@
using Gtk 4.0;
using Adw 1;
Adw.ToolbarView view {
content: Box{
orientation: vertical;
Adw.Banner paused_banner {
title: 'Backups paused due to Power Saver Mode';
revealed: false;
}
ScrolledWindow {
vexpand: true;
hexpand: true;
margin-top: 20;
child: Box content {
orientation: vertical;
spacing: 6;
margin-start: 80;
margin-end: 80;
};
}
};
[top]
Adw.HeaderBar {
halign: baseline;
title-widget: Adw.WindowTitle {
title: 'Backup View';
};
valign: start;
Button add_button {
label: 'Add Backup';
styles [
"suggested-action",
]
}
}
}

84
gui/src/gui/settings.blp Normal file
View file

@ -0,0 +1,84 @@
using Gtk 4.0;
using Adw 1;
Box content {
orientation: vertical;
Adw.Banner paused_banner {
title: 'No pin set, please set it now';
button-label: 'Set Pin';
revealed: false;
}
Adw.PreferencesPage preferences_page {
title: "General";
Adw.PreferencesGroup {
title: "Actions";
Button quick_access_button {
label: "Quick Access";
margin-top: 20;
styles [
"suggested-action"
]
}
Button login_button {
label: "Login";
margin-top: 20;
styles [
"suggested-action"
]
}
Button pin_button {
label: "Set pin";
margin-top: 20;
styles [
"suggested-action"
]
}
Button unlock_button {
label: "Unlock";
sensitive: false;
margin-top: 20;
styles [
"suggested-action"
]
}
Button logout_button {
label: "Logout";
margin-top: 20;
styles [
"destructive-action"
]
}
LinkButton {
uri: "https://github.com/quexten/goldwarden/wiki/Flatpak-Configuration";
label: "Help & Wiki";
}
}
Adw.PreferencesGroup {
title: "Vault Status";
Adw.ActionRow {
title: "Vault Status";
subtitle: "Locked";
}
Adw.ActionRow {
title: "Last Sync";
subtitle: "Never";
icon-name: "emblem-synchronizing-symbolic";
}
Adw.ActionRow {
title: "Websocked Connected";
subtitle: "False";
}
Adw.ActionRow {
title: "Vault Login Entries";
subtitle: "0";
icon-name: "dialog-password-symbolic";
}
Adw.ActionRow {
title: "Vault Notes";
subtitle: "0";
icon-name: "emblem-documents-symbolic";
}
}
}
}

View file

@ -1,312 +1,339 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys import sys
import gi import gi
gi.require_version('Gtk', '4.0') gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1') gi.require_version('Adw', '1')
import gc
from gi.repository import Gtk, Adw, GLib, Gdk, Gio from gi.repository import Gtk, Adw, GLib, Gdk, Gio
from ..services import goldwarden from ..services import goldwarden
from threading import Thread from threading import Thread
from .template_loader import load_template
import subprocess import subprocess
from . import components from . import components
import os import os
root_path = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir, os.pardir)) root_path = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir, os.pardir))
token = sys.stdin.readline() # token = sys.stdin.readline()
goldwarden.create_authenticated_connection(None) # goldwarden.create_authenticated_connection(None)
#
# def quickaccess_button_clicked():
# p = subprocess.Popen(["python3", "-m", "src.gui.quickaccess"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=root_path, start_new_session=True)
# if p.stdin != None:
# p.stdin.write(f"{token}\n".encode())
# p.stdin.flush()
#
# def shortcuts_button_clicked():
# p = subprocess.Popen(["python3", "-m", "src.gui.shortcuts"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=root_path, start_new_session=True)
# p.stdin.write(f"{token}\n".encode())
# p.stdin.flush()
#
# def ssh_button_clicked():
# p = subprocess.Popen(["python3", "-m", "src.gui.ssh"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=root_path, start_new_session=True)
# p.stdin.write(f"{token}\n".encode())
# p.stdin.flush()
#
# def browserbiometrics_button_clicked():
# p = subprocess.Popen(["python3", "-m", "src.gui.browserbiometrics"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=root_path, start_new_session=True)
# p.stdin.write(f"{token}\n".encode())
# p.stdin.flush()
#
# def add_action_row(parent, title, subtitle, icon=None):
# row = Adw.ActionRow()
# row.set_title(title)
# row.set_subtitle(subtitle)
# if icon != None:
# row.set_icon_name(icon)
# parent.add(row)
# return row
#
def quickaccess_button_clicked(): class SettingsWindow(Gtk.ApplicationWindow):
p = subprocess.Popen(["python3", "-m", "src.gui.quickaccess"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=root_path, start_new_session=True)
p.stdin.write(f"{token}\n".encode())
p.stdin.flush()
def shortcuts_button_clicked():
p = subprocess.Popen(["python3", "-m", "src.gui.shortcuts"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=root_path, start_new_session=True)
p.stdin.write(f"{token}\n".encode())
p.stdin.flush()
def ssh_button_clicked():
p = subprocess.Popen(["python3", "-m", "src.gui.ssh"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=root_path, start_new_session=True)
p.stdin.write(f"{token}\n".encode())
p.stdin.flush()
def browserbiometrics_button_clicked():
p = subprocess.Popen(["python3", "-m", "src.gui.browserbiometrics"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=root_path, start_new_session=True)
p.stdin.write(f"{token}\n".encode())
p.stdin.flush()
def add_action_row(parent, title, subtitle, icon=None):
row = Adw.ActionRow()
row.set_title(title)
row.set_subtitle(subtitle)
if icon != None:
row.set_icon_name(icon)
parent.add(row)
return row
class SettingsWinvdow(Gtk.ApplicationWindow):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
# # vertical box
# vertical box
self.box = Gtk.Box() self.box = Gtk.Box()
self.box.set_orientation(Gtk.Orientation.VERTICAL) self.box.set_orientation(Gtk.Orientation.VERTICAL)
self.set_child(self.box) self.set_child(self.box)
#
def set_pin(): # def set_pin():
set_pin_thread = Thread(target=goldwarden.enable_pin) # set_pin_thread = Thread(target=goldwarden.enable_pin)
set_pin_thread.start() # set_pin_thread.start()
#
self.banner = Adw.Banner() # self.banner = Adw.Banner()
self.banner.set_title("No pin set, please set it now") # self.banner.set_title("No pin set, please set it now")
self.banner.set_button_label("Set Pin") # self.banner.set_button_label("Set Pin")
self.banner.connect("button-clicked", lambda banner: set_pin()) # self.banner.connect("button-clicked", lambda banner: set_pin())
self.box.append(self.banner) # self.box.append(self.banner)
#
self.stack = Gtk.Stack() # self.stack = Gtk.Stack()
self.stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT) # self.stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
self.box.append(self.stack) # self.box.append(self.stack)
#
self.preferences_page = Adw.PreferencesPage() # self.preferences_page = Adw.PreferencesPage()
self.preferences_page.set_title("General") # self.preferences_page.set_title("General")
self.stack.add_named(self.preferences_page, "preferences_page") # self.stack.add_named(self.preferences_page, "preferences_page")
#
self.action_preferences_group = Adw.PreferencesGroup() # self.action_preferences_group = Adw.PreferencesGroup()
self.action_preferences_group.set_title("Actions") # self.action_preferences_group.set_title("Actions")
self.preferences_page.add(self.action_preferences_group) # self.preferences_page.add(self.action_preferences_group)
#
self.autotype_button = Gtk.Button() # self.autotype_button = Gtk.Button()
self.autotype_button.set_label("Quick Access") # self.autotype_button.set_label("Quick Access")
self.autotype_button.set_margin_top(10) # self.autotype_button.set_margin_top(10)
#
self.autotype_button.connect("clicked", lambda button: quickaccess_button_clicked()) # self.autotype_button.connect("clicked", lambda button: quickaccess_button_clicked())
self.autotype_button.get_style_context().add_class("suggested-action") # self.autotype_button.get_style_context().add_class("suggested-action")
self.action_preferences_group.add(self.autotype_button) # self.action_preferences_group.add(self.autotype_button)
#
self.login_button = Gtk.Button() # self.login_button = Gtk.Button()
self.login_button.set_label("Login") # self.login_button.set_label("Login")
self.login_button.connect("clicked", lambda button: show_login()) # self.login_button.connect("clicked", lambda button: show_login())
self.login_button.set_sensitive(False) # self.login_button.set_sensitive(False)
self.login_button.set_margin_top(10) # self.login_button.set_margin_top(10)
self.login_button.get_style_context().add_class("suggested-action") # self.login_button.get_style_context().add_class("suggested-action")
self.action_preferences_group.add(self.login_button) # self.action_preferences_group.add(self.login_button)
#
self.set_pin_button = Gtk.Button() # self.set_pin_button = Gtk.Button()
self.set_pin_button.set_label("Set Pin") # self.set_pin_button.set_label("Set Pin")
self.set_pin_button.connect("clicked", lambda button: 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_margin_top(10)
self.set_pin_button.set_sensitive(False) # self.set_pin_button.set_sensitive(False)
self.set_pin_button.get_style_context().add_class("suggested-action") # self.set_pin_button.get_style_context().add_class("suggested-action")
self.action_preferences_group.add(self.set_pin_button) # self.action_preferences_group.add(self.set_pin_button)
#
self.unlock_button = Gtk.Button() # self.unlock_button = Gtk.Button()
self.unlock_button.set_label("Unlock") # self.unlock_button.set_label("Unlock")
self.unlock_button.set_margin_top(10) # self.unlock_button.set_margin_top(10)
def unlock_button_clicked(): # def unlock_button_clicked():
action = goldwarden.unlock if self.unlock_button.get_label() == "Unlock" else goldwarden.lock # action = goldwarden.unlock if self.unlock_button.get_label() == "Unlock" else goldwarden.lock
unlock_thread = Thread(target=action) # unlock_thread = Thread(target=action)
unlock_thread.start() # unlock_thread.start()
self.unlock_button.connect("clicked", lambda button: unlock_button_clicked()) # self.unlock_button.connect("clicked", lambda button: unlock_button_clicked())
# set disabled # # set disabled
self.unlock_button.set_sensitive(False) # self.unlock_button.set_sensitive(False)
self.action_preferences_group.add(self.unlock_button) # self.action_preferences_group.add(self.unlock_button)
#
self.logout_button = Gtk.Button() # self.logout_button = Gtk.Button()
self.logout_button.set_label("Logout") # self.logout_button.set_label("Logout")
self.logout_button.set_margin_top(10) # self.logout_button.set_margin_top(10)
self.logout_button.connect("clicked", lambda button: goldwarden.purge()) # self.logout_button.connect("clicked", lambda button: goldwarden.purge())
self.logout_button.get_style_context().add_class("destructive-action") # self.logout_button.get_style_context().add_class("destructive-action")
self.action_preferences_group.add(self.logout_button) # 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 = Gtk.LinkButton(uri="https://github.com/quexten/goldwarden/wiki/Flatpak-Configuration")
self.wiki_button.set_label("Help & Wiki") # self.wiki_button.set_label("Help & Wiki")
self.wiki_button.set_margin_top(10) # self.wiki_button.set_margin_top(10)
self.action_preferences_group.add(self.wiki_button) # self.action_preferences_group.add(self.wiki_button)
#
self.vault_status_preferences_group = Adw.PreferencesGroup() # self.vault_status_preferences_group = Adw.PreferencesGroup()
self.vault_status_preferences_group.set_title("Vault Status") # self.vault_status_preferences_group.set_title("Vault Status")
self.preferences_page.add(self.vault_status_preferences_group) # self.preferences_page.add(self.vault_status_preferences_group)
#
self.status_row = add_action_row(self.vault_status_preferences_group, "Vault Status", "Locked") # self.status_row = add_action_row(self.vault_status_preferences_group, "Vault Status", "Locked")
#
self.vault_status_icon = components.StatusIcon() # self.vault_status_icon = components.StatusIcon()
self.vault_status_icon.set_icon("dialog-error", "error") # self.vault_status_icon.set_icon("dialog-error", "error")
self.status_row.add_prefix(self.vault_status_icon) # self.status_row.add_prefix(self.vault_status_icon)
#
self.last_sync_row = add_action_row(self.vault_status_preferences_group, "Last Sync", "Never", "emblem-synchronizing-symbolic") # self.last_sync_row = add_action_row(self.vault_status_preferences_group, "Last Sync", "Never", "emblem-synchronizing-symbolic")
self.websocket_connected_row = add_action_row(self.vault_status_preferences_group, "Websocket Connected", "False") # self.websocket_connected_row = add_action_row(self.vault_status_preferences_group, "Websocket Connected", "False")
#
self.websocket_connected_status_icon = components.StatusIcon() # self.websocket_connected_status_icon = components.StatusIcon()
self.websocket_connected_status_icon.set_icon("dialog-error", "error") # self.websocket_connected_status_icon.set_icon("dialog-error", "error")
self.websocket_connected_row.add_prefix(self.websocket_connected_status_icon) # self.websocket_connected_row.add_prefix(self.websocket_connected_status_icon)
#
self.login_row = add_action_row(self.vault_status_preferences_group, "Vault Login Entries", "0", "dialog-password-symbolic") # self.login_row = add_action_row(self.vault_status_preferences_group, "Vault Login Entries", "0", "dialog-password-symbolic")
self.notes_row = add_action_row(self.vault_status_preferences_group, "Vault Notes", "0", "emblem-documents-symbolic") # self.notes_row = add_action_row(self.vault_status_preferences_group, "Vault Notes", "0", "emblem-documents-symbolic")
#
self.header = Gtk.HeaderBar() # self.header = Gtk.HeaderBar()
self.set_titlebar(self.header) # self.set_titlebar(self.header)
#
action = Gio.SimpleAction.new("shortcuts", None) # action = Gio.SimpleAction.new("shortcuts", None)
action.connect("activate", lambda action, parameter: shortcuts_button_clicked()) # action.connect("activate", lambda action, parameter: shortcuts_button_clicked())
self.add_action(action) # self.add_action(action)
menu = Gio.Menu.new() # menu = Gio.Menu.new()
menu.append("Keyboard Shortcuts", "win.shortcuts") # menu.append("Keyboard Shortcuts", "win.shortcuts")
self.popover = Gtk.PopoverMenu() # self.popover = Gtk.PopoverMenu()
self.popover.set_menu_model(menu) # self.popover.set_menu_model(menu)
#
action = Gio.SimpleAction.new("ssh", None) # action = Gio.SimpleAction.new("ssh", None)
action.connect("activate", lambda action, parameter: ssh_button_clicked()) # action.connect("activate", lambda action, parameter: ssh_button_clicked())
self.add_action(action) # self.add_action(action)
menu.append("SSH Agent", "win.ssh") # menu.append("SSH Agent", "win.ssh")
#
action = Gio.SimpleAction.new("browserbiometrics", None) # action = Gio.SimpleAction.new("browserbiometrics", None)
action.connect("activate", lambda action, parameter: browserbiometrics_button_clicked()) # action.connect("activate", lambda action, parameter: browserbiometrics_button_clicked())
self.add_action(action) # self.add_action(action)
menu.append("Browser Biometrics", "win.browserbiometrics") # menu.append("Browser Biometrics", "win.browserbiometrics")
#
self.hamburger = Gtk.MenuButton() # self.hamburger = Gtk.MenuButton()
self.hamburger.set_popover(self.popover) # self.hamburger.set_popover(self.popover)
self.hamburger.set_icon_name("open-menu-symbolic") # self.hamburger.set_icon_name("open-menu-symbolic")
self.header.pack_start(self.hamburger) # self.header.pack_start(self.hamburger)
#
#
def update_labels(): # def update_labels():
pin_set = goldwarden.is_pin_enabled() # pin_set = goldwarden.is_pin_enabled()
status = goldwarden.get_vault_status() # status = goldwarden.get_vault_status()
print("status", status) # print("status", status)
runtimeCfg = goldwarden.get_runtime_config() # runtimeCfg = goldwarden.get_runtime_config()
#
if status != None: # if status != None:
if pin_set: # if pin_set:
self.unlock_button.set_sensitive(True) # self.unlock_button.set_sensitive(True)
self.banner.set_revealed(False) # self.banner.set_revealed(False)
else: # else:
self.unlock_button.set_sensitive(False) # self.unlock_button.set_sensitive(False)
self.banner.set_revealed(True) # self.banner.set_revealed(True)
logged_in = status["loggedIn"] # logged_in = status["loggedIn"]
if logged_in and not status["locked"]: # if logged_in and not status["locked"]:
self.autotype_button.set_visible(True) # self.autotype_button.set_visible(True)
self.login_row.set_sensitive(True) # self.login_row.set_sensitive(True)
self.notes_row.set_sensitive(True) # self.notes_row.set_sensitive(True)
self.websocket_connected_row.set_sensitive(True) # self.websocket_connected_row.set_sensitive(True)
else: # else:
self.autotype_button.set_visible(False) # self.autotype_button.set_visible(False)
self.websocket_connected_row.set_sensitive(False) # self.websocket_connected_row.set_sensitive(False)
self.login_row.set_sensitive(False) # self.login_row.set_sensitive(False)
self.notes_row.set_sensitive(False) # self.notes_row.set_sensitive(False)
#
locked = status["locked"] # locked = status["locked"]
self.login_button.set_sensitive(pin_set and not locked) # self.login_button.set_sensitive(pin_set and not locked)
self.set_pin_button.set_sensitive(not pin_set or not locked) # self.set_pin_button.set_sensitive(not pin_set or not locked)
self.autotype_button.set_sensitive(not locked) # self.autotype_button.set_sensitive(not locked)
self.status_row.set_subtitle(str("Logged in" if (logged_in and not locked) else "Logged out") if not locked else "Locked") # self.status_row.set_subtitle(str("Logged in" if (logged_in and not locked) else "Logged out") if not locked else "Locked")
if locked or not logged_in: # if locked or not logged_in:
self.vault_status_icon.set_icon("dialog-warning", "warning") # self.vault_status_icon.set_icon("dialog-warning", "warning")
else: # else:
self.vault_status_icon.set_icon("emblem-default", "ok") # self.vault_status_icon.set_icon("emblem-default", "ok")
if not logged_in: # if not logged_in:
self.logout_button.set_sensitive(False) # self.logout_button.set_sensitive(False)
else: # else:
self.logout_button.set_sensitive(True) # self.logout_button.set_sensitive(True)
self.login_row.set_subtitle(str(status["loginEntries"])) # self.login_row.set_subtitle(str(status["loginEntries"]))
self.notes_row.set_subtitle(str(status["noteEntries"])) # self.notes_row.set_subtitle(str(status["noteEntries"]))
self.websocket_connected_row.set_subtitle("Connected" if status["websocketConnected"] else "Disconnected") # self.websocket_connected_row.set_subtitle("Connected" if status["websocketConnected"] else "Disconnected")
if status["websocketConnected"]: # if status["websocketConnected"]:
self.websocket_connected_status_icon.set_icon("emblem-default", "ok") # self.websocket_connected_status_icon.set_icon("emblem-default", "ok")
else: # else:
self.websocket_connected_status_icon.set_icon("dialog-error", "error") # self.websocket_connected_status_icon.set_icon("dialog-error", "error")
self.last_sync_row.set_subtitle(str(status["lastSynced"])) # self.last_sync_row.set_subtitle(str(status["lastSynced"]))
if status["lastSynced"].startswith("1970") or status["lastSynced"].startswith("1969"): # if status["lastSynced"].startswith("1970") or status["lastSynced"].startswith("1969"):
self.last_sync_row.set_subtitle("Never") # self.last_sync_row.set_subtitle("Never")
self.unlock_button.set_label("Unlock" if locked else "Lock") # self.unlock_button.set_label("Unlock" if locked else "Lock")
else: # else:
is_daemon_running = goldwarden.is_daemon_running() # is_daemon_running = goldwarden.is_daemon_running()
if not is_daemon_running: # if not is_daemon_running:
self.status_row.set_subtitle("Daemon not running") # self.status_row.set_subtitle("Daemon not running")
self.vault_status_icon.set_icon("dialog-error", "error") # self.vault_status_icon.set_icon("dialog-error", "error")
#
GLib.timeout_add(5000, update_labels) # GLib.timeout_add(5000, update_labels)
#
GLib.timeout_add(1000, update_labels) # GLib.timeout_add(1000, update_labels)
self.set_default_size(400, 700) self.set_default_size(400, 700)
self.set_title("Goldwarden") self.set_title("Goldwarden")
class MyApp(Adw.Application): def load(self):
builder = load_template("settings.ui")
self.edit_view = builder.get_object("window")
self.content = builder.get_object("content")
print(self.content)
# self.back_button = builder.get_object("back_button")
# self.back_button.connect("clicked", lambda _: self.navigate_callback("main", None))
# self.id_row = builder.get_object("id_row")
# self.name_row = builder.get_object("name_row")
# self.rclone_path_row = builder.get_object("rclone_path_row")
# self.password_row = builder.get_object("password_row")
# self.rclone_button = builder.get_object("rclone_row")
# self.rclone_button.connect("activated", lambda _: self.edit_rclone())
# self.save_button = builder.get_object("save_button")
# self.save_button.connect("clicked", lambda _: self.save())
# self.remove_button = builder.get_object("remove_button")
# self.remove_button.connect("clicked", lambda _: self.remove())
print(self.box)
print(self.content)
self.box.append(self.content)
return self.edit_view
class GoldwardenSettingsApp(Adw.Application):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self.connect('activate', self.on_activate) self.connect('activate', self.on_activate)
def on_activate(self, app): def on_activate(self, app):
self.settings_win = SettingsWinvdow(application=app) print("on activate")
self.settings_win = SettingsWindow(application=app)
self.settings_win.present() self.settings_win.present()
self.settings_win.load()
def show_login(): # def show_login():
dialog = Gtk.Dialog(title="Goldwarden") # dialog = Gtk.Dialog(title="Goldwarden")
#
auth_preference_group = Adw.PreferencesGroup() # auth_preference_group = Adw.PreferencesGroup()
auth_preference_group.set_title("Authentication") # auth_preference_group.set_title("Authentication")
auth_preference_group.set_margin_top(10) # auth_preference_group.set_margin_top(10)
auth_preference_group.set_margin_bottom(10) # auth_preference_group.set_margin_bottom(10)
auth_preference_group.set_margin_start(10) # auth_preference_group.set_margin_start(10)
auth_preference_group.set_margin_end(10) # auth_preference_group.set_margin_end(10)
dialog.get_content_area().append(auth_preference_group) # dialog.get_content_area().append(auth_preference_group)
#
email_entry = Adw.EntryRow() # email_entry = Adw.EntryRow()
email_entry.set_title("Email") # email_entry.set_title("Email")
email_entry.set_text("") # email_entry.set_text("")
auth_preference_group.add(email_entry) # auth_preference_group.add(email_entry)
#
client_id_entry = Adw.EntryRow() # client_id_entry = Adw.EntryRow()
client_id_entry.set_title("Client ID (optional)") # client_id_entry.set_title("Client ID (optional)")
client_id_entry.set_text("") # client_id_entry.set_text("")
auth_preference_group.add(client_id_entry) # auth_preference_group.add(client_id_entry)
#
client_secret_entry = Adw.EntryRow() # client_secret_entry = Adw.EntryRow()
client_secret_entry.set_title("Client Secret (optional)") # client_secret_entry.set_title("Client Secret (optional)")
client_secret_entry.set_text("") # client_secret_entry.set_text("")
auth_preference_group.add(client_secret_entry) # auth_preference_group.add(client_secret_entry)
#
dialog.add_button("Login", Gtk.ResponseType.OK) # dialog.add_button("Login", Gtk.ResponseType.OK)
def on_save(res): # def on_save(res):
if res != Gtk.ResponseType.OK: # if res != Gtk.ResponseType.OK:
return # return
goldwarden.set_url(url_entry.get_text()) # goldwarden.set_url(url_entry.get_text())
goldwarden.set_client_id(client_id_entry.get_text()) # goldwarden.set_client_id(client_id_entry.get_text())
goldwarden.set_client_secret(client_secret_entry.get_text()) # goldwarden.set_client_secret(client_secret_entry.get_text())
def login(): # def login():
res = goldwarden.login_with_password(email_entry.get_text(), "password") # res = goldwarden.login_with_password(email_entry.get_text(), "password")
def handle_res(): # def handle_res():
if res == "ok": # if res == "ok":
dialog.close() # dialog.close()
# elif res == "badpass": # # elif res == "badpass":
# bad_pass_diag = Gtk.MessageDialog(transient_for=dialog, modal=True, message_type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK, text="Bad password") # # bad_pass_diag = Gtk.MessageDialog(transient_for=dialog, modal=True, message_type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK, text="Bad password")
# bad_pass_diag.connect("response", lambda dialog, response: bad_pass_diag.close()) # # bad_pass_diag.connect("response", lambda dialog, response: bad_pass_diag.close())
# bad_pass_diag.present() # # bad_pass_diag.present()
GLib.idle_add(handle_res) # GLib.idle_add(handle_res)
#
login_thread = Thread(target=login) # login_thread = Thread(target=login)
login_thread.start() # login_thread.start()
#
preference_group = Adw.PreferencesGroup() # preference_group = Adw.PreferencesGroup()
preference_group.set_title("Config") # preference_group.set_title("Config")
preference_group.set_margin_top(10) # preference_group.set_margin_top(10)
preference_group.set_margin_bottom(10) # preference_group.set_margin_bottom(10)
preference_group.set_margin_start(10) # preference_group.set_margin_start(10)
preference_group.set_margin_end(10) # preference_group.set_margin_end(10)
#
dialog.get_content_area().append(preference_group) # dialog.get_content_area().append(preference_group)
#
url_entry = Adw.EntryRow() # url_entry = Adw.EntryRow()
url_entry.set_title("Base Url") # url_entry.set_title("Base Url")
url_entry.set_text("https://vault.bitwarden.com/") # url_entry.set_text("https://vault.bitwarden.com/")
preference_group.add(url_entry) # preference_group.add(url_entry)
#
#ok response # #ok response
dialog.connect("response", lambda dialog, response: on_save(response)) # dialog.connect("response", lambda dialog, response: on_save(response))
dialog.set_default_size(400, 200) # dialog.set_default_size(400, 200)
dialog.set_modal(True) # dialog.set_modal(True)
dialog.present() # dialog.present()
isflatpak = os.path.exists("/.flatpak-info") isflatpak = os.path.exists("/.flatpak-info")
pathprefix = "/app/bin/" if isflatpak else "./" pathprefix = "/app/bin/" if isflatpak else "./"
@ -318,5 +345,5 @@ Gtk.StyleContext.add_provider_for_display(
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
) )
app = MyApp(application_id="com.quexten.Goldwarden.settings") app = GoldwardenSettingsApp(application_id="com.quexten.Goldwarden.settings")
app.run(sys.argv) app.run(sys.argv)

View file

@ -0,0 +1,10 @@
import os
from gi.repository import Gtk
isflatpak = os.path.exists("/.flatpak-info")
pathprefix = "/app/bin/" if isflatpak else "./src/gui/"
def load_template(path):
builder = Gtk.Builder()
builder.add_from_file(pathprefix + ".templates/" + path)
return builder