@@ 1,6 1,7 @@
import argparse
import os
import gi
+import sys
from numberstation.window import NumberstationWindow
@@ 12,23 13,29 @@ from gi.repository import Handy
class NumberstationApplication(Gtk.Application):
- def __init__(self, application_id, flags, args, version):
+ def __init__(self, application_id, flags, version):
Gtk.Application.__init__(self, application_id=application_id, flags=flags)
- self.connect("activate", self.new_window)
- self.args = args
+ self.connect("activate", self.open_window)
+ self.connect("open", self.open_url)
self.version = version
+ self.window = None
- def new_window(self, *args):
- NumberstationWindow(self, self.args, self.version)
+ def open_window(self, *args):
+ if self.window is None:
+ self.window = NumberstationWindow(self, self.version)
+ self.window.present()
+ def open_url(self, app, files, *hint):
+ self.open_window()
+
+ for file in files:
+ self.window.import_url(file.get_uri())
+
+ self.window.build_code_list()
def main(version):
Handy.init()
- parser = argparse.ArgumentParser(description="Numberstation TOTP authenticator")
- parser.add_argument('url', help='TOTP url to register', nargs='?')
- args = parser.parse_args()
-
if os.path.isfile('numberstation/numberstation.gresource'):
print("Using resources from cwd/numberstation")
resource = Gio.resource_load("numberstation/numberstation.gresource")
@@ 38,9 45,9 @@ def main(version):
resource = Gio.resource_load("numberstation.gresource")
Gio.Resource._register(resource)
- app = NumberstationApplication("org.postmarketos.Numberstation", Gio.ApplicationFlags.FLAGS_NONE, args=args,
+ app = NumberstationApplication("org.postmarketos.Numberstation", Gio.ApplicationFlags.HANDLES_OPEN,
version=version)
- app.run()
+ app.run(sys.argv)
if __name__ == '__main__':
@@ 17,9 17,8 @@ from gi.repository import Handy
class NumberstationWindow:
- def __init__(self, application, args, version):
+ def __init__(self, application, version):
self.application = application
- self.args = args
self.version = version
Handy.init()
@@ 74,16 73,12 @@ class NumberstationWindow:
print("Could not unlock the keyring")
self.timers = []
- if args.url:
- self.import_url(args.url)
self.build_code_list()
GLib.timeout_add(1000, self.update_codes)
self.window.show()
- Gtk.main()
-
def apply_css(self, widget, provider):
Gtk.StyleContext.add_provider(widget.get_style_context(),
provider,
@@ 393,3 388,6 @@ class NumberstationWindow:
widget.token.initial_count += 1
self.save_keyring()
self.update_code_label(widget, None, widget.token)
+
+ def present(self):
+ self.window.present()