Skip to content

Commit

Permalink
async background load for fix user change freeze
Browse files Browse the repository at this point in the history
  • Loading branch information
sulincix committed Nov 26, 2024
1 parent 42c340c commit e6227c6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/data/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</packing>
</child>
<child type="overlay">
<object class="GtkStack" id="ui_stack_mai">
<object class="GtkStack" id="ui_stack_window">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
Expand Down
16 changes: 9 additions & 7 deletions src/module/gtkwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self):
self.__update_user_background_loop()
self.__connect_signals()
self.__last_hash = gsettings_get("last-hash").split("\n")
self.set_background()

def __init_variables(self):
self.image_status = True
Expand Down Expand Up @@ -213,7 +214,7 @@ def __event_username_entry_clicked(self, widget=None):
" ", "") == "root")
if is_root:
return
self.update_username_button(lightdm.get_username())
self.__event_username_entry_changed(widget)

def __event_username_entry_changed(self, w=None):
widget = self.o("ui_entry_username")
Expand All @@ -225,11 +226,11 @@ def __event_username_entry_changed(self, w=None):
if is_root:
return
# Cancel current auth and auth new user if user is valid
lightdm.set(username=widget.get_text())
self.err_handler()
if not self.greeter_loaded:
self.ignore_password_cache = False
if lightdm.is_valid_user(widget.get_text()):
lightdm.reset()
lightdm.greeter.authenticate(widget.get_text())
# Update user background
self.update_username_button(widget.get_text())
# Update login button label
Expand All @@ -241,7 +242,6 @@ def __event_username_entry_changed(self, w=None):
self.o("ui_button_login").set_label(_("Login"))
self.o("ui_box_session_menu").show()

self.o("ui_window_main").queue_draw()

def __event_password_entry_changed(self, widget):
# ignore if disabled
Expand Down Expand Up @@ -329,9 +329,11 @@ def update_user_background(self):
u = LightDM.UserList.get_instance().get_user_by_name(username)
if u != None:
background = u.get_background()
self.set_background(background)
th = threading.Thread(target=self.set_background, args=[background])
else:
self.set_background(None)
th = threading.Thread(target=self.set_background, args=[None])

th.start()

def set_background(self, bg=None):
if bg == None or not os.path.isfile(bg):
Expand All @@ -353,7 +355,7 @@ def set_background(self, bg=None):
print(str(e))
if self.background_handler != None:
self.background_pixbuf = self.background_handler(self.background_pixbuf)
self.draw_background()
GLib.idle_add(self.draw_background)

def draw_background(self):
if self.image_status:
Expand Down

0 comments on commit e6227c6

Please sign in to comment.