mirror of
https://github.com/quexten/goldwarden.git
synced 2024-09-11 11:15:41 +03:00
Implement x11, mac, windows autotype
This commit is contained in:
parent
1133553022
commit
77eec0bc41
@ -6,6 +6,7 @@ import gc
|
||||
import time
|
||||
from gi.repository import Gtk, Adw, GLib, Notify, Gdk
|
||||
from ..services import goldwarden
|
||||
from ..services.autotype import autotype
|
||||
from threading import Thread
|
||||
from .resource_loader import load_template
|
||||
import sys
|
||||
@ -71,19 +72,19 @@ class GoldwardenQuickAccessApp(Adw.Application):
|
||||
# totp code
|
||||
if keyval == Gdk.KEY_t or keyval == Gdk.KEY_T:
|
||||
if auto_type_combo:
|
||||
self.autotype(totp.totp(self.filtered_logins[self.selected_index]["totp"]))
|
||||
self.run_autotype(totp.totp(self.filtered_logins[self.selected_index]["totp"]))
|
||||
if copy_combo:
|
||||
self.set_clipboard(totp.totp(self.filtered_logins[self.selected_index]["totp"]))
|
||||
|
||||
if keyval == Gdk.KEY_u or keyval == Gdk.KEY_U:
|
||||
if auto_type_combo:
|
||||
self.autotype(self.filtered_logins[self.selected_index]["username"])
|
||||
self.run_autotype(self.filtered_logins[self.selected_index]["username"])
|
||||
if copy_combo:
|
||||
self.set_clipboard(self.filtered_logins[self.selected_index]["username"])
|
||||
|
||||
if keyval == Gdk.KEY_p or keyval == Gdk.KEY_P:
|
||||
if auto_type_combo:
|
||||
self.autotype(self.filtered_logins[self.selected_index]["password"])
|
||||
self.run_autotype(self.filtered_logins[self.selected_index]["password"])
|
||||
if copy_combo:
|
||||
self.set_clipboard(self.filtered_logins[self.selected_index]["password"])
|
||||
|
||||
@ -100,18 +101,18 @@ class GoldwardenQuickAccessApp(Adw.Application):
|
||||
|
||||
if keyval == Gdk.KEY_Return:
|
||||
if auto_type_combo:
|
||||
self.autotype(f"{self.filtered_logins[self.selected_index]['username']}\t{self.filtered_logins[self.selected_index]['password']}")
|
||||
self.run_autotype(f"{self.filtered_logins[self.selected_index]['username']}\t{self.filtered_logins[self.selected_index]['password']}")
|
||||
|
||||
def update(self):
|
||||
self.update_list()
|
||||
self.render_list()
|
||||
return True
|
||||
|
||||
def autotype(self, text):
|
||||
def run_autotype(self, text):
|
||||
def perform_autotype(text):
|
||||
self.window.hide()
|
||||
time.sleep(0.1)
|
||||
goldwarden.autotype(text)
|
||||
autotype.autotype(text)
|
||||
time.sleep(0.1)
|
||||
os._exit(0)
|
||||
thread = Thread(target=perform_autotype, args=(text,))
|
||||
|
@ -1,101 +0,0 @@
|
||||
# TODO??!?!? for now using golang implementation
|
||||
|
||||
import dbus
|
||||
import dbus.mainloop.glib
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
|
||||
from gi.repository import GLib
|
||||
|
||||
import random
|
||||
import time
|
||||
|
||||
step = 0
|
||||
|
||||
def typestring(text):
|
||||
step = 0
|
||||
handle = ""
|
||||
|
||||
def handler(*args, **kwargs):
|
||||
global step
|
||||
if step == 0:
|
||||
handle_xdp_session_created(*args, **kwargs)
|
||||
elif step == 1:
|
||||
handle_xdp_devices_selected(*args, **kwargs)
|
||||
elif step == 2:
|
||||
handle_session_start(*args, **kwargs)
|
||||
else:
|
||||
print(args, kwargs)
|
||||
step += 1
|
||||
|
||||
def handle_session_start(code, results, object_path):
|
||||
global handle
|
||||
|
||||
if code != 0:
|
||||
raise Exception("Could not start session")
|
||||
|
||||
for sym in text:
|
||||
if sym == "\t":
|
||||
inter.NotifyKeyboardKeycode(handle, {}, 15, 1)
|
||||
time.sleep(0.001)
|
||||
inter.NotifyKeyboardKeycode(handle, {}, 15, 0)
|
||||
time.sleep(0.001)
|
||||
else:
|
||||
inter.NotifyKeyboardKeysym(handle, {}, ord(sym), 1)
|
||||
time.sleep(0.001)
|
||||
inter.NotifyKeyboardKeysym(handle, {}, ord(sym), 0)
|
||||
time.sleep(0.001)
|
||||
|
||||
bus
|
||||
|
||||
def handle_xdp_devices_selected(code, results, object_path):
|
||||
global handle
|
||||
|
||||
if code != 0:
|
||||
raise Exception("Could not select devices")
|
||||
|
||||
start_options = {
|
||||
"handle_token": "krfb" + str(random.randint(0, 999999999))
|
||||
}
|
||||
reply = inter.Start(handle, "", start_options)
|
||||
print(reply)
|
||||
|
||||
def handle_xdp_session_created(code, results, object_path):
|
||||
global handle
|
||||
|
||||
if code != 0:
|
||||
raise Exception("Could not create session")
|
||||
print(results)
|
||||
handle = results["session_handle"]
|
||||
|
||||
# select sources for the session
|
||||
selection_options = {
|
||||
"types": dbus.UInt32(7), # request all (KeyBoard, Pointer, TouchScreen)
|
||||
"handle_token": "krfb" + str(random.randint(0, 999999999))
|
||||
}
|
||||
selector_reply = inter.SelectDevices(handle, selection_options)
|
||||
print(selector_reply)
|
||||
|
||||
def main():
|
||||
global bus
|
||||
global inter
|
||||
loop = GLib.MainLoop()
|
||||
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
||||
bus = dbus.SessionBus()
|
||||
obj = bus.get_object("org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop")
|
||||
inter = dbus.Interface(obj, "org.freedesktop.portal.RemoteDesktop")
|
||||
|
||||
bus.add_signal_receiver(
|
||||
handler,
|
||||
signal_name="Response",
|
||||
dbus_interface="org.freedesktop.portal.Request",
|
||||
bus_name="org.freedesktop.portal.Desktop",
|
||||
path_keyword="object_path")
|
||||
|
||||
print(inter)
|
||||
result = inter.CreateSession({
|
||||
"session_handle_token": "sessionhandletoken"
|
||||
})
|
||||
print(result)
|
||||
loop.run()
|
||||
|
||||
main()
|
14
gui/src/services/autotype/autotype.py
Normal file
14
gui/src/services/autotype/autotype.py
Normal file
@ -0,0 +1,14 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
is_linux = sys.platform == 'linux'
|
||||
is_wayland = os.environ.get('XDG_SESSION_TYPE') == 'wayland'
|
||||
|
||||
def autotype(text):
|
||||
print("autotypeing, is_linux: {}, is_wayland: {}".format(is_linux, is_wayland))
|
||||
if is_linux and is_wayland:
|
||||
from .libportal_autotype import autotype_libportal
|
||||
autotype_libportal(text)
|
||||
|
||||
from .pyautogui_autotype import autotype_pyautogui
|
||||
autotype_pyautogui(text)
|
106
gui/src/services/autotype/libportal_autotype.py
Normal file
106
gui/src/services/autotype/libportal_autotype.py
Normal file
@ -0,0 +1,106 @@
|
||||
# TODO??!?!? for now using golang implementation
|
||||
from ..goldwarden import autotype
|
||||
|
||||
def libportal_autotype(text):
|
||||
print("autotypeing with libportal")
|
||||
goldwarden.autotype(text)
|
||||
|
||||
# import dbus
|
||||
# import dbus.mainloop.glib
|
||||
# from dbus.mainloop.glib import DBusGMainLoop
|
||||
|
||||
# from gi.repository import GLib
|
||||
|
||||
# import random
|
||||
# import time
|
||||
|
||||
# step = 0
|
||||
|
||||
# def typestring(text):
|
||||
# step = 0
|
||||
# handle = ""
|
||||
|
||||
# def handler(*args, **kwargs):
|
||||
# global step
|
||||
# if step == 0:
|
||||
# handle_xdp_session_created(*args, **kwargs)
|
||||
# elif step == 1:
|
||||
# handle_xdp_devices_selected(*args, **kwargs)
|
||||
# elif step == 2:
|
||||
# handle_session_start(*args, **kwargs)
|
||||
# else:
|
||||
# print(args, kwargs)
|
||||
# step += 1
|
||||
|
||||
# def handle_session_start(code, results, object_path):
|
||||
# global handle
|
||||
|
||||
# if code != 0:
|
||||
# raise Exception("Could not start session")
|
||||
|
||||
# for sym in text:
|
||||
# if sym == "\t":
|
||||
# inter.NotifyKeyboardKeycode(handle, {}, 15, 1)
|
||||
# time.sleep(0.001)
|
||||
# inter.NotifyKeyboardKeycode(handle, {}, 15, 0)
|
||||
# time.sleep(0.001)
|
||||
# else:
|
||||
# inter.NotifyKeyboardKeysym(handle, {}, ord(sym), 1)
|
||||
# time.sleep(0.001)
|
||||
# inter.NotifyKeyboardKeysym(handle, {}, ord(sym), 0)
|
||||
# time.sleep(0.001)
|
||||
|
||||
# bus
|
||||
|
||||
# def handle_xdp_devices_selected(code, results, object_path):
|
||||
# global handle
|
||||
|
||||
# if code != 0:
|
||||
# raise Exception("Could not select devices")
|
||||
|
||||
# start_options = {
|
||||
# "handle_token": "krfb" + str(random.randint(0, 999999999))
|
||||
# }
|
||||
# reply = inter.Start(handle, "", start_options)
|
||||
# print(reply)
|
||||
|
||||
# def handle_xdp_session_created(code, results, object_path):
|
||||
# global handle
|
||||
|
||||
# if code != 0:
|
||||
# raise Exception("Could not create session")
|
||||
# print(results)
|
||||
# handle = results["session_handle"]
|
||||
|
||||
# # select sources for the session
|
||||
# selection_options = {
|
||||
# "types": dbus.UInt32(7), # request all (KeyBoard, Pointer, TouchScreen)
|
||||
# "handle_token": "krfb" + str(random.randint(0, 999999999))
|
||||
# }
|
||||
# selector_reply = inter.SelectDevices(handle, selection_options)
|
||||
# print(selector_reply)
|
||||
|
||||
# def main():
|
||||
# global bus
|
||||
# global inter
|
||||
# loop = GLib.MainLoop()
|
||||
# dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
||||
# bus = dbus.SessionBus()
|
||||
# obj = bus.get_object("org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop")
|
||||
# inter = dbus.Interface(obj, "org.freedesktop.portal.RemoteDesktop")
|
||||
|
||||
# bus.add_signal_receiver(
|
||||
# handler,
|
||||
# signal_name="Response",
|
||||
# dbus_interface="org.freedesktop.portal.Request",
|
||||
# bus_name="org.freedesktop.portal.Desktop",
|
||||
# path_keyword="object_path")
|
||||
|
||||
# print(inter)
|
||||
# result = inter.CreateSession({
|
||||
# "session_handle_token": "sessionhandletoken"
|
||||
# })
|
||||
# print(result)
|
||||
# loop.run()
|
||||
|
||||
# main()
|
5
gui/src/services/autotype/pyautogui_autotype.py
Normal file
5
gui/src/services/autotype/pyautogui_autotype.py
Normal file
@ -0,0 +1,5 @@
|
||||
import pyautogui
|
||||
|
||||
def autotype_pyautogui(text):
|
||||
print("autotypeing with pyautogui")
|
||||
pyautogui.write(text, interval=0.02)
|
Loading…
Reference in New Issue
Block a user