🐛 fix(_init_): thread safe utilization

This commit is contained in:
eshanized
2024-12-29 11:07:14 +05:30
parent 3f9dc5e16f
commit 6a23408d90

View File

@@ -65,35 +65,59 @@ label#label_style_eshan {
class Main(Gtk.Window): class Main(Gtk.Window):
def __init__(self): def __init__(self):
super(Main, self).__init__(title="Snigdha OS Welcome") super(Main, self).__init__(title="Snigdha OS Welcome")
self.set_border_width(10)
self.set_default_size(860, 450) # Basic Window Configuration
self.set_icon_from_file(os.path.join(base_dir, "images/snigdhaos-welcome-small.png")) self.set_border_width(10) # Set the border width of the window
self.set_position(Gtk.WindowPosition.CENTER) self.set_default_size(860, 450) # Set the default size of the window
self.results = "" self.set_icon_from_file(os.path.join(base_dir, "images/snigdhaos-welcome-small.png")) # Set the window icon
if not os.path.exists(GUI.home + "/.config/snigdhaos-welcome/"): self.set_position(Gtk.WindowPosition.CENTER) # Center the window on the screen
os.mkdir(GUI.home + "/.config/snigdhaos-welcome/") self.results = "" # Initialize results to an empty string
with open(GUI.Settings, "w") as f:
f.write("autostart=True") # Initialize Configuration Directory and Settings
f.close() config_dir = os.path.join(GUI.home, ".config/snigdhaos-welcome/") # Define the configuration directory path
self.style_provider = Gtk.CssProvider() if not os.path.exists(config_dir): # Check if the directory exists
try:
os.makedirs(config_dir, exist_ok=True) # Create the directory if it doesn't exist
with open(GUI.Settings, "w") as f: # Open the settings file in write mode
f.write("autostart=True") # Write default settings
except OSError as e:
print(f"Error initializing configuration: {e}") # Handle any file/directory creation errors
# CSS Styling
self.style_provider = Gtk.CssProvider() # Create a CSS provider
try:
# Load the CSS data into the style provider
self.style_provider.load_from_data(css, len(css)) self.style_provider.load_from_data(css, len(css))
# Apply the style provider to the default screen
Gtk.StyleContext.add_provider_for_screen( Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(), Gdk.Screen.get_default(),
self.style_provider, self.style_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION, # Set priority for application-specific styles
) )
self.pkg_queue = Queue() except GLib.Error as e:
self.pacman_lockfile = "/var/lib/pacman/db.lck" print(f"Error loading CSS: {e}") # Handle CSS loading errors
self.sudo_username = os.getlogin()
self.calamares_polkit = "/usr/bin/calamares_polkit" # Initialize Internal Attributes
self.session = None self.pkg_queue = Queue() # Initialize a queue for package operations
self.get_session() self.pacman_lockfile = "/var/lib/pacman/db.lck" # Define the lockfile path for pacman
GUI.GUI(self, Gtk, GdkPixbuf) self.sudo_username = os.getlogin() # Get the username of the user running the script
if GUI.username == GUI.user: self.calamares_polkit = "/usr/bin/calamares_polkit" # Path to the Calamares Polkit executable
threading.Thread( self.session = None # Initialize session attribute
target=self.internet_notifier, args=(), daemon=True
).start() # Retrieve Session Information
self.get_session() # Fetch the session information (implementation not shown here)
# Initialize GUI
GUI.GUI(self, Gtk, GdkPixbuf) # Initialize the graphical user interface components
# Start Internet Notifier Thread if the user matches the GUI user
if GUI.username == GUI.user: # Check if the username matches
internet_notifier_thread = threading.Thread(
target=self.internet_notifier, daemon=True # Create a thread for the internet notifier
)
internet_notifier_thread.start() # Start the thread
def get_session(self): def get_session(self):
try: try:
self.session = os.environ.get("XDG_SESSION_TYPE") self.session = os.environ.get("XDG_SESSION_TYPE")