Skip to content

Commit

Permalink
Make filter way faster, use local C for subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
heliguy4599 committed Oct 3, 2023
1 parent c918927 commit 1695cae
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 109 deletions.
16 changes: 9 additions & 7 deletions src/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ def __init__(self, window, **kwargs):
self.user_data_path = self.host_home + "/.var/app/"
self.install_success = True
self.uninstall_success = True
self.new_env = dict( os.environ )
self.new_env['LC_ALL'] = 'C'

def trashFolder(self, path):
if not os.path.exists(path):
return 1
try:
subprocess.run(["flatpak-spawn", "--host", "gio", "trash", path], capture_output=True, check=True)
subprocess.run(["flatpak-spawn", "--host", "gio", "trash", path], capture_output=True, check=True, env=self.new_env)
return 0
except subprocess.CalledProcessError:
return 2
Expand Down Expand Up @@ -76,7 +78,7 @@ def findAppIcon(self, app_id):
return image

def getHostRemotes(self):
output = subprocess.run(["flatpak-spawn", "--host", "flatpak", "remotes", "--columns=all"], capture_output=True, text=True).stdout
output = subprocess.run(["flatpak-spawn", "--host", "flatpak", "remotes", "--columns=all"], capture_output=True, text=True, env=self.new_env).stdout
lines = output.strip().split("\n")
columns = lines[0].split("\t")
data = [columns]
Expand All @@ -99,7 +101,7 @@ def getHostRemotes(self):
return data

def getHostFlatpaks(self):
output = subprocess.run(["flatpak-spawn", "--host", "flatpak", "list", "--columns=all"], capture_output=True, text=True).stdout
output = subprocess.run(["flatpak-spawn", "--host", "flatpak", "list", "--columns=all"], capture_output=True, text=True, env=self.new_env).stdout
lines = output.strip().split("\n")
columns = lines[0].split("\t")
data = [columns]
Expand Down Expand Up @@ -127,7 +129,7 @@ def uninstallFlatpak(self, ref_arr, type_arr, should_trash):
for i in range(len(apps)):
command = ['flatpak-spawn', '--host', 'flatpak', 'remove', '-y', f"--{apps[i][2]}", apps[i][0]]
try:
subprocess.run(command, capture_output=False, check=True)
subprocess.run(command, capture_output=False, check=True, env=self.new_env)
except subprocess.CalledProcessError:
fails.append(apps[i])

Expand All @@ -143,7 +145,7 @@ def uninstallFlatpak(self, ref_arr, type_arr, should_trash):
pk_command.append(fails[i][0])
try:
print(pk_command)
subprocess.run(pk_command, capture_output=False, check=True)
subprocess.run(pk_command, capture_output=False, check=True, env=self.new_env)
except subprocess.CalledProcessError:
self.uninstall_success = False

Expand All @@ -166,7 +168,7 @@ def installFlatpak(self, app_arr, remote, user_or_system):
for i in range(len(app_arr)):
command = ['flatpak-spawn', '--host', 'flatpak', 'install', remote, f"--{user_or_system}", '-y', app_arr[i]]
try:
subprocess.run(command, capture_output=False, check=True)
subprocess.run(command, capture_output=False, check=True, env=self.new_env)
except subprocess.CalledProcessError:
fails.append(app_arr[i])

Expand All @@ -175,7 +177,7 @@ def installFlatpak(self, app_arr, remote, user_or_system):
for i in range(len(fails)):
pk_command.append(fails[i])
try:
subprocess.run(pk_command, capture_output=False, check=True)
subprocess.run(pk_command, capture_output=False, check=True, env=self.new_env)
except subprocess.CalledProcessError:
self.install_success = False

Expand Down
2 changes: 1 addition & 1 deletion src/filter_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, main_window, **kwargs):
self.add_controller(event_controller)

# Connections
self.apply_button.connect("clicked", lambda *_: main_window.updateFilter(self.filter_list))
self.apply_button.connect("clicked", lambda *_: main_window.applyFilter(self.filter_list))
self.apply_button.connect("clicked", lambda *_: self.close())

self.cancel_button.connect("clicked", lambda *_: main_window.filter_button.set_active(False))
Expand Down
5 changes: 4 additions & 1 deletion src/popular_remotes_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def on_add_response(self, _dialog, response_id, _function):

command = ['flatpak-spawn', '--host', 'flatpak', 'remote-add', '--if-not-exists', self.name_to_add, self.url_to_add, install_type]
try:
subprocess.run(command, capture_output=True, check=True)
subprocess.run(command, capture_output=True, check=True, env=self.new_env)
except Exception as e:
self.toast_overlay.add_toast(Adw.Toast.new(_("Could not add {}").format(self.name_to_add)))
print(e)
Expand Down Expand Up @@ -175,6 +175,9 @@ def __init__(self, parent_window, **kwargs):
self.my_utils = myUtils(self)
self.parent_window = parent_window

self.new_env = dict( os.environ )
self.new_env['LC_ALL'] = 'C'

self.set_modal(True)
self.set_transient_for(parent_window)
self.generate_list()
10 changes: 7 additions & 3 deletions src/remotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from .common import myUtils
from .popular_remotes_window import PopularRemotesWindow
import subprocess
import os
import re

class RemotesWindow(Adw.Window):

def key_handler(self, _a, event, _c, _d):
if event == Gdk.KEY_Escape:
self.close()
Expand All @@ -14,7 +14,7 @@ def make_toast(self, text):
self.toast_overlay.add_toast(Adw.Toast.new(text))

def get_host_flatpaks(self):
output = subprocess.run(["flatpak-spawn", "--host", "flatpak", "list", "--columns=all"], capture_output=True, text=True).stdout
output = subprocess.run(["flatpak-spawn", "--host", "flatpak", "list", "--columns=all"], capture_output=True, text=True, env=self.new_env).stdout
lines = output.strip().split("\n")
columns = lines[0].split("\t")
data = [columns]
Expand All @@ -32,7 +32,7 @@ def remove_on_response(self, _dialog, response_id, _function, index):
install_type = self.host_remotes[index][7]
command = ['flatpak-spawn', '--host', 'flatpak', 'remote-delete', '--force', name, f'--{install_type}']
try:
subprocess.run(command, capture_output=True, check=True)
subprocess.run(command, capture_output=True, check=True, env=self.new_env)
except subprocess.CalledProcessError as e:
self.make_toast(_("Could not remove {}").format(title))
self.generate_list()
Expand Down Expand Up @@ -122,6 +122,8 @@ def __init__(self, main_window, **kwargs):
self.window_title = _("Manage Remotes")
self.host_remotes = []
self.host_flatpaks = []
self.new_env = dict( os.environ )
self.new_env['LC_ALL'] = 'C'

# Create Widgets
self.scroll = Gtk.ScrolledWindow()
Expand All @@ -134,6 +136,8 @@ def __init__(self, main_window, **kwargs):
self.user_data_row = Adw.ActionRow(title="No User Data")
self.add_button = Gtk.Button(icon_name="plus-large-symbolic", tooltip_text="Add Remote")
self.stack = Gtk.Stack()
self.new_env = dict( os.environ )
self.new_env['LC_ALL'] = 'C'

# Apply Widgets
self.toolbar.set_content(self.toast_overlay)
Expand Down
2 changes: 1 addition & 1 deletion src/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ template WarehouseWindow : Adw.ApplicationWindow {
ScrolledWindow scrolled_window {
vexpand: true;
Adw.Clamp{
ListBox list_of_flatpaks{
ListBox flatpaks_list_box {
margin-top: 6;
margin-bottom: 24;
margin-start: 12;
Expand Down
Loading

0 comments on commit 1695cae

Please sign in to comment.