More fixes to make autotype work
This commit is contained in:
parent
ca17380758
commit
fe64cc7807
7 changed files with 50 additions and 40 deletions
|
|
@ -13,10 +13,10 @@ import time
|
||||||
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))
|
||||||
|
is_flatpak = os.path.exists("/.flatpak-info")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
token = secrets.token_hex(32)
|
token = secrets.token_hex(32)
|
||||||
print("token", token)
|
|
||||||
if not os.environ.get("GOLDWARDEN_DAEMON_AUTH_TOKEN") == None:
|
if not os.environ.get("GOLDWARDEN_DAEMON_AUTH_TOKEN") == None:
|
||||||
token = os.environ["GOLDWARDEN_DAEMON_AUTH_TOKEN"]
|
token = os.environ["GOLDWARDEN_DAEMON_AUTH_TOKEN"]
|
||||||
|
|
||||||
|
|
@ -33,27 +33,20 @@ def main():
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
# start daemons
|
# start daemons
|
||||||
dbus_autofill_monitor.run_daemon() # todo: remove after migration
|
dbus_autofill_monitor.run_daemon(token) # todo: remove after migration
|
||||||
dbus_monitor.run_daemon(token)
|
dbus_monitor.run_daemon(token)
|
||||||
|
|
||||||
if not "--hidden" in sys.argv:
|
if not "--hidden" in sys.argv:
|
||||||
subprocess.Popen(["python3", "-m", "src.ui.settings"], cwd=root_path, start_new_session=True)
|
p = subprocess.Popen(["python3", "-m", "src.ui.settings"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=root_path, start_new_session=True)
|
||||||
|
p.stdin.write(f"{token}\n".encode())
|
||||||
|
p.stdin.flush()
|
||||||
|
|
||||||
# try:
|
if is_flatpak:
|
||||||
# subprocess.Popen(["python3", f'{source_path}/background.py'], start_new_session=True)
|
# to autostart the appes
|
||||||
# except Exception as e:
|
try:
|
||||||
# pass
|
subprocess.Popen(["python3", f'{source_path}/background.py'], start_new_session=True)
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
time.sleep(60)
|
time.sleep(60)
|
||||||
|
|
||||||
|
|
||||||
# def run_daemon():
|
|
||||||
# # todo: do a proper check
|
|
||||||
# if is_hidden:
|
|
||||||
# time.sleep(20)
|
|
||||||
# print("IS daemon running", goldwarden.is_daemon_running())
|
|
||||||
# if not goldwarden.is_daemon_running():
|
|
||||||
# print("running daemon")
|
|
||||||
# goldwarden.run_daemon()
|
|
||||||
# print("daemon running")
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import dbus.service
|
||||||
from dbus.mainloop.glib import DBusGMainLoop
|
from dbus.mainloop.glib import DBusGMainLoop
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
on_autofill = lambda: None
|
daemon_token = None
|
||||||
|
|
||||||
class GoldwardenDBUSService(dbus.service.Object):
|
class GoldwardenDBUSService(dbus.service.Object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
@ -16,7 +16,9 @@ class GoldwardenDBUSService(dbus.service.Object):
|
||||||
|
|
||||||
@dbus.service.method('com.quexten.Goldwarden.Autofill')
|
@dbus.service.method('com.quexten.Goldwarden.Autofill')
|
||||||
def autofill(self):
|
def autofill(self):
|
||||||
on_autofill()
|
p = subprocess.Popen(["python3", "-m", "src.ui.quickaccess"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=root_path, start_new_session=True)
|
||||||
|
p.stdin.write(f"{daemon_token}\n".encode())
|
||||||
|
p.stdin.flush()
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def daemon():
|
def daemon():
|
||||||
|
|
@ -25,7 +27,9 @@ def daemon():
|
||||||
from gi.repository import GLib, GObject as gobject
|
from gi.repository import GLib, GObject as gobject
|
||||||
gobject.MainLoop().run()
|
gobject.MainLoop().run()
|
||||||
|
|
||||||
def run_daemon():
|
def run_daemon(token):
|
||||||
|
global daemon_token
|
||||||
|
daemon_token = token
|
||||||
thread = Thread(target=daemon)
|
thread = Thread(target=daemon)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
|
|
@ -17,15 +17,15 @@ class GoldwardenDBUSService(dbus.service.Object):
|
||||||
@dbus.service.method('com.quexten.Goldwarden.ui.QuickAccess')
|
@dbus.service.method('com.quexten.Goldwarden.ui.QuickAccess')
|
||||||
def quickaccess(self):
|
def quickaccess(self):
|
||||||
p = subprocess.Popen(["python3", "-m", "src.ui.quickaccess"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=root_path, start_new_session=True)
|
p = subprocess.Popen(["python3", "-m", "src.ui.quickaccess"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=root_path, start_new_session=True)
|
||||||
print("writing token")
|
|
||||||
p.stdin.write(f"{daemon_token}\n".encode())
|
p.stdin.write(f"{daemon_token}\n".encode())
|
||||||
p.stdin.flush()
|
p.stdin.flush()
|
||||||
print("reading token")
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@dbus.service.method('com.quexten.Goldwarden.ui.Settings')
|
@dbus.service.method('com.quexten.Goldwarden.ui.Settings')
|
||||||
def settings(self):
|
def settings(self):
|
||||||
subprocess.Popen(["python3", "-m", "src.ui.settings"], cwd=root_path, start_new_session=True)
|
subprocess.Popen(["python3", "-m", "src.ui.settings"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=root_path, start_new_session=True)
|
||||||
|
p.stdin.write(f"{daemon_token}\n".encode())
|
||||||
|
p.stdin.flush()
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def daemon():
|
def daemon():
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,12 @@ BINARY_PATHS = [
|
||||||
str(Path.home()) + "/go/src/github.com/quexten/goldwarden/goldwarden"
|
str(Path.home()) + "/go/src/github.com/quexten/goldwarden/goldwarden"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
BINARY_PATH = ""
|
||||||
authenticated_connection = None
|
authenticated_connection = None
|
||||||
|
|
||||||
def create_authenticated_connection(token):
|
def create_authenticated_connection(token):
|
||||||
global authenticated_connection
|
global authenticated_connection
|
||||||
|
global BINARY_PATH
|
||||||
BINARY_PATH = None
|
BINARY_PATH = None
|
||||||
for path in BINARY_PATHS:
|
for path in BINARY_PATHS:
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
|
|
@ -123,16 +125,16 @@ def get_runtime_config():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# def autotype(username, password):
|
def autotype(username, password):
|
||||||
# # environment
|
env = os.environ.copy()
|
||||||
# env = os.environ.copy()
|
# todo convert to stdin
|
||||||
# env["PASSWORD"] = password
|
env["PASSWORD"] = password
|
||||||
# restic_cmd = f"{BINARY_PATH} autotype --username {username}"
|
goldwarden_cmd = f"{BINARY_PATH} autotype --username {username}"
|
||||||
# result = subprocess.run(restic_cmd.split(), capture_output=True, text=True, env=env)
|
result = subprocess.run(goldwarden_cmd.split(), capture_output=True, text=True, env=env)
|
||||||
# print(result.stderr)
|
print(result.stderr)
|
||||||
# print(result.stdout)
|
print(result.stdout)
|
||||||
# if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
# raise Exception("Failed to initialize repository, err", result.stderr)
|
raise Exception("Failed to initialize repository, err", result.stderr)
|
||||||
|
|
||||||
def is_daemon_running():
|
def is_daemon_running():
|
||||||
result = send_authenticated_command(f"vault status")
|
result = send_authenticated_command(f"vault status")
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,20 @@ class MyApp(Adw.Application):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.connect('activate', self.on_activate)
|
self.connect('activate', self.on_activate)
|
||||||
|
|
||||||
def on_activate(self, app):
|
def update_logins(self):
|
||||||
self.autofill_window = MainWindow(application=app)
|
|
||||||
self.autofill_window.logins = []
|
|
||||||
self.autofill_window.present()
|
|
||||||
logins = goldwarden.get_vault_logins()
|
logins = goldwarden.get_vault_logins()
|
||||||
if logins == None:
|
if logins == None:
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
return
|
return
|
||||||
app.autofill_window.logins = logins
|
self.app.autofill_window.logins = logins
|
||||||
|
|
||||||
|
def on_activate(self, app):
|
||||||
|
self.autofill_window = MainWindow(application=app)
|
||||||
|
self.autofill_window.logins = []
|
||||||
|
self.autofill_window.present()
|
||||||
|
self.app = app
|
||||||
|
thread = Thread(target=self.update_logins)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
class MainWindow(Gtk.ApplicationWindow):
|
class MainWindow(Gtk.ApplicationWindow):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ 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))
|
||||||
|
token = sys.stdin.readline()
|
||||||
goldwarden.create_authenticated_connection(None)
|
goldwarden.create_authenticated_connection(None)
|
||||||
|
|
||||||
class SettingsWinvdow(Gtk.ApplicationWindow):
|
class SettingsWinvdow(Gtk.ApplicationWindow):
|
||||||
|
|
@ -48,7 +50,11 @@ class SettingsWinvdow(Gtk.ApplicationWindow):
|
||||||
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: subprocess.Popen(["python3", "/app/bin/autofill.py"], start_new_session=True))
|
def quickaccess_button_clicked():
|
||||||
|
p = subprocess.Popen(["python3", "-m", "src.ui.quickaccess"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd=root_path, start_new_session=True)
|
||||||
|
p.stdin.write(f"{token}\n".encode())
|
||||||
|
p.stdin.flush()
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue