~sircmpwn/hiprompt-gtk-py

dd5ed36ff18c973247fbd977e746e878efadae66 — Alexey Yerin 2 years ago 52ac6fc
Implement new prompter protocol
2 files changed, 23 insertions(+), 4 deletions(-)

M hiprompt_gtk/proto.py
M hiprompt_gtk/window.py
M hiprompt_gtk/proto.py => hiprompt_gtk/proto.py +11 -2
@@ 14,7 14,9 @@ class Session:
        self.unlock = False
        self.status = 127
        self.mode = None
        self.parse()

    def parse(self):
        for line in sys.stdin:
            parts = line.strip().partition(" ")
            cmd = parts[0]


@@ 35,6 37,8 @@ class Session:

    def _unlock(self, args):
        self.unlock = True
        if len(self.keys) == 0:
            return False

    def _prompt(self, args):
        self.mode = PromptMode(args)


@@ 50,7 54,12 @@ class Session:
        sys.stdout.flush()
        # TODO: Don't block
        line = sys.stdin.readline()
        if line == "incorrect-password\n":
        if line == "password incorrect\n":
            return False
        else:
        elif line == "password correct\n":
            self.unlock = False
            self.parse()
            return True
        else:
            sys.stderr.write(f"Unexpected command '{line}'\n")
            exit(127)

M hiprompt_gtk/window.py => hiprompt_gtk/window.py +12 -2
@@ 25,10 25,15 @@ class Window:

        self.entry = None

        self.make_ui()

    def make_ui(self):
        if self.session.mode == PromptMode.disclose:
            self.make_disclose_ui()
        elif self.session.mode == PromptMode.delete:
            self.make_delete_ui()
        elif self.session.mode == None:
            assert(self.session.unlock)
        else:
            raise ValueError("Unexpected mode")



@@ 36,6 41,7 @@ class Window:
            self.make_unlock_ui()

        self.header.show_all()
        self.box.show_all()

    def on_close(self, *args):
        Gtk.main_quit()


@@ 47,9 53,13 @@ class Window:
    def on_unlock_grant(self, *args):
        password = self.entry.get_text()
        self.entry.set_sensitive(False)
        confirmed = len(self.session.keys) > 0
        if self.session.password(password):
            self.session.status = 0
            Gtk.main_quit()
            if not self.session.mode or confirmed:
                self.session.status = 0
                Gtk.main_quit()
            else:
                self.make_ui()
        else:
            self.entry.set_text("")
            self.entry.set_sensitive(True)