Skip to content

Commit

Permalink
Merge pull request #191 from quexten/feature/gtk-blueprints
Browse files Browse the repository at this point in the history
Feature/gtk blueprints
  • Loading branch information
quexten authored May 3, 2024
2 parents 142b808 + cb6d3d5 commit f415d98
Show file tree
Hide file tree
Showing 21 changed files with 1,091 additions and 700 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ __pycache__
.flatpak-builder
flatpak-pip-generator
repo
__debug*
__debug*
.templates
8 changes: 8 additions & 0 deletions com.quexten.Goldwarden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ finish-args:
# biometric / user password auth
- --system-talk-name=org.freedesktop.PolicyKit1
modules:
- name: "blueprint-compiler"
buildsystem: meson
cleanup: ['*']
sources:
- type: git
url: https://gitlab.gnome.org/jwestman/blueprint-compiler
tag: v0.12.0
- ./gui/python3-requirements.json
- name: goldwarden-python-ui
buildsystem: simple
Expand All @@ -35,6 +42,7 @@ modules:
- install -D ./gui/com.quexten.Goldwarden.desktop /app/share/applications/com.quexten.Goldwarden.desktop
- install -D ./gui/goldwarden.svg /app/share/icons/hicolor/scalable/apps/com.quexten.Goldwarden.svg
- install -Dm644 ./gui/com.quexten.Goldwarden.metainfo.xml -t /app/share/metainfo/
- blueprint-compiler batch-compile /app/bin/src/gui/.templates/ /app/bin/src/gui/ /app/bin/src/gui/*.blp
sources:
- type: dir
path: ./
Expand Down
44 changes: 44 additions & 0 deletions gui/src/gui/browserbiometrics.blp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Gtk 4.0;
using Adw 1;

Adw.Window window {
default-width: 500;
default-height: 500;

Adw.ToolbarView view {
content: Box{
orientation: vertical;
ScrolledWindow {
vexpand: true;
hexpand: true;
child: Box content {
orientation: vertical;
Adw.PreferencesPage preferences_page {
title: "General";

Adw.PreferencesGroup register_browser_biometrics_group {
title: "Register Browser Biometrics";
description: "Run the following command in your terminal to set up the browser biometrics integration";

Adw.ActionRow setup_command_row {
subtitle: "flatpak run --filesystem=home --command=goldwarden com.quexten.Goldwarden setup browserbiometrics";
subtitle-selectable: true;
}
}
}
};
}
};

[top]
Adw.HeaderBar {
halign: baseline;

title-widget: Adw.WindowTitle {
title: 'Goldwarden Browser Biometrics Setup';
};

valign: start;
}
}
}
59 changes: 19 additions & 40 deletions gui/src/gui/browserbiometrics.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,32 @@
#!/usr/bin/env python3
import sys
import gi

gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
import gc
import time
from gi.repository import Gtk, Adw, GLib, Notify, Gdk

from gi.repository import Gtk, Adw, GLib, Gdk, Gio
from ..services import goldwarden
from threading import Thread
import sys
import os
from .template_loader import load_template
import subprocess
from . import components
import os

class MyApp(Adw.Application):
class GoldwardenBrowserBiometricsSetupGuideApp(Adw.Application):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.connect('activate', self.on_activate)

def on_activate(self, app):
self.pinentry_window = MainWindow(application=app)
self.pinentry_window.present()
self.app = app

class MainWindow(Gtk.ApplicationWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

# vertical box
self.box = Gtk.Box()
self.box.set_orientation(Gtk.Orientation.VERTICAL)
self.set_child(self.box)

self.stack = Gtk.Stack()
self.stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
self.box.append(self.stack)

self.preferences_page = Adw.PreferencesPage()
self.preferences_page.set_title("General")
self.stack.add_named(self.preferences_page, "preferences_page")

self.register_browser_biometrics_group = Adw.PreferencesGroup()
self.register_browser_biometrics_group.set_title("Register Browser Biometrics")
self.register_browser_biometrics_group.set_description("Run the following command in your terminal to set up the browser biometrics integration")
self.preferences_page.add(self.register_browser_biometrics_group)

self.setup_command_row = Adw.ActionRow()
self.setup_command_row.set_subtitle("flatpak run --filesystem=home --command=goldwarden com.quexten.Goldwarden setup browserbiometrics")
self.setup_command_row.set_subtitle_selectable(True)
self.register_browser_biometrics_group.add(self.setup_command_row)
self.load()
self.window.present()

self.set_default_size(700, 400)
self.set_title("Goldwarden Browser Biometrics Setup")
def load(self):
builder = load_template("browserbiometrics.ui")
self.window = builder.get_object("window")
self.window.set_application(self)

app = MyApp(application_id="com.quexten.Goldwarden.browserbiometrics")
app.run(sys.argv)
if __name__ == "__main__":
app = GoldwardenBrowserBiometricsSetupGuideApp(application_id="com.quexten.Goldwarden.browserbiometrics")
app.run(sys.argv)
69 changes: 69 additions & 0 deletions gui/src/gui/login.blp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Gtk 4.0;
using Adw 1;

Adw.Window window {
default-width: 400;
default-height: 550;

Adw.ToolbarView view {
content: Box {
orientation: vertical;
spacing: 6;

Adw.PreferencesPage preferences_page {
Adw.PreferencesGroup {
title: "Authentication";
margin-start: 12;
margin-end: 12;
margin-bottom: 12;
Adw.EntryRow email_row {
title: "Email";
text: "";
}
Adw.EntryRow client_id_row {
title: "Client ID (optional)";
text: "";
}
Adw.EntryRow client_secret_row {
title: "Client Secret (optional)";
text: "";
}
}
Adw.PreferencesGroup {
title: "Server";
margin-start: 12;
margin-end: 12;
margin-top: 12;
margin-bottom: 12;
Adw.EntryRow server_row {
title: "Server URL";
text: "https://vault.bitwarden.com";
}
}
Adw.PreferencesGroup {
margin-start: 12;
margin-end: 12;
margin-top: 12;
margin-bottom: 12;
Button login_button {
label: "Login";
styles [
"suggested-action"
]
}
}
}
};

[top]
Adw.HeaderBar {
halign: baseline;

title-widget: Adw.WindowTitle {
title: 'Goldwarden Login';
};

valign: start;
}
}
}
66 changes: 66 additions & 0 deletions gui/src/gui/login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import gi
gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
import gc
import time
from gi.repository import Gtk, Adw, GLib, Notify, Gdk
from threading import Thread
from .template_loader import load_template
import sys
import os
from ..services import goldwarden

goldwarden.create_authenticated_connection(None)

class GoldwardenLoginApp(Adw.Application):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.connect('activate', self.on_activate)

def on_activate(self, app):
self.load()
self.window.present()

def load(self):
builder = load_template("login.ui")
self.window = builder.get_object("window")
self.window.set_application(self)
self.email_row = builder.get_object("email_row")
self.client_id_row = builder.get_object("client_id_row")
self.client_secret_row = builder.get_object("client_secret_row")
self.server_row = builder.get_object("server_row")
self.login_button = builder.get_object("login_button")
self.login_button.connect("clicked", lambda x: self.on_login())

evk = Gtk.EventControllerKey.new()
evk.set_propagation_phase(Gtk.PropagationPhase.CAPTURE)
evk.connect("key-pressed", self.key_press)
self.window.add_controller(evk)

def key_press(self, event, keyval, keycode, state):
if keyval == Gdk.KEY_Escape:
os._exit(0)

if keyval == Gdk.KEY_Return and state & Gdk.ModifierType.CONTROL_MASK:
self.on_login()
return True

def on_login(self):
email = self.email_row.get_text()
client_id = self.client_id_row.get_text()
client_secret = self.client_secret_row.get_text()
server = self.server_row.get_text()
goldwarden.set_url(server)
if client_id != "":
goldwarden.set_client_id(client_id)
if client_secret != "":
goldwarden.set_client_secret(client_secret)
goldwarden.login_with_password(email, "")
self.window.close()

if __name__ == "__main__":
settings = Gtk.Settings.get_default()
settings.set_property("gtk-error-bell", False)

app = GoldwardenLoginApp(application_id="com.quexten.Goldwarden.login")
app.run(sys.argv)
43 changes: 43 additions & 0 deletions gui/src/gui/main_view.blp
Original file line number Diff line number Diff line change
@@ -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",
]
}
}
}
48 changes: 48 additions & 0 deletions gui/src/gui/pinentry.blp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Gtk 4.0;
using Adw 1;

Adw.Window window {
default-width: 400;
default-height: 700;

Adw.ToolbarView view {
content: Box {
orientation: vertical;
spacing: 6;

Label message {
label: 'Placeholder label';
}

Entry password_entry {
placeholder-text: "Enter your password";
visibility: false;
}

Box button_box {
spacing: 6;

Button cancel_button {
label: "Cancel";
hexpand: true;
}

Button approve_button {
label: "Approve";
hexpand: true;
}
}
};

[top]
Adw.HeaderBar {
halign: baseline;

title-widget: Adw.WindowTitle {
title: 'Goldwarden Pinentry';
};

valign: start;
}
}
}
Loading

0 comments on commit f415d98

Please sign in to comment.