Kaydet (Commit) 680142a7 authored tarafından Hakan Dündar's avatar Hakan Dündar

Improvements for system integration

üst 97265f23
......@@ -70,7 +70,8 @@ if package_type_var == "debian_rpm_archlinux_or_another_package":
("/usr/share/polkit-1/actions/", ["integration/io.github.hakandundar34coding.system-monitoring-center.policy"]),
("/usr/share/system-monitoring-center/database/", files_in_folder("database/")),
("/usr/share/system-monitoring-center/src/", files_in_folder("src/")),
("/usr/share/icons/hicolor/scalable/actions/", files_in_folder("icons/hicolor/scalable/actions/")),
("/usr/share/system-monitoring-center/icons/hicolor/scalable/actions/", files_in_folder("icons/hicolor/scalable/actions/")),
("/usr/share/system-monitoring-center/icons/hicolor/scalable/apps/", ["icons/hicolor/scalable/apps/system-monitoring-center.svg"]),
("/usr/share/icons/hicolor/scalable/apps/", ["icons/hicolor/scalable/apps/system-monitoring-center.svg"]),
("/usr/share/man/man1/", ["man/system-monitoring-center.1.gz"]),
("/usr/bin/", ["integration/system-monitoring-center"])
......@@ -83,9 +84,7 @@ if package_type_var == "flatpak_package":
install_requires=["PyGObject"]
entry_points={}
shutil.copy2("icons/hicolor/scalable/apps/system-monitoring-center.svg", "icons/hicolor/scalable/actions/system-monitoring-center.svg")
os.rename("icons/hicolor/scalable/apps/system-monitoring-center.svg", "icons/hicolor/scalable/apps/io.github.hakandundar34coding.system-monitoring-center.svg")
shutil.copy2("icons/hicolor/scalable/apps/system-monitoring-center.svg", "icons/hicolor/scalable/apps/io.github.hakandundar34coding.system-monitoring-center.svg")
with open("integration/io.github.hakandundar34coding.system-monitoring-center.desktop") as reader:
desktop_file_content = reader.read()
......@@ -102,10 +101,10 @@ if package_type_var == "flatpak_package":
data_files = [
("/app/share/applications/", ["integration/io.github.hakandundar34coding.system-monitoring-center.desktop"]),
("/app/share/polkit-1/actions/", ["integration/io.github.hakandundar34coding.system-monitoring-center.policy"]),
("/app/share/system-monitoring-center/database/", files_in_folder("database/")),
("/app/share/system-monitoring-center/src/", files_in_folder("src/")),
("/app/share/icons/hicolor/scalable/actions/", files_in_folder("icons/hicolor/scalable/actions/")),
("/app/share/system-monitoring-center/icons/hicolor/scalable/actions/", files_in_folder("icons/hicolor/scalable/actions/")),
("/app/share/system-monitoring-center/icons/hicolor/scalable/apps/", ["icons/hicolor/scalable/apps/system-monitoring-center.svg"]),
("/app/share/icons/hicolor/scalable/apps/", ["icons/hicolor/scalable/apps/io.github.hakandundar34coding.system-monitoring-center.svg"]),
("/app/share/man/man1/", ["man/system-monitoring-center.1.gz"]),
("/app/share/appdata/", ["io.github.hakandundar34coding.system-monitoring-center.appdata.xml"]),
......
......@@ -2,10 +2,11 @@
import gi
gi.require_version('Gtk', '4.0')
gi.require_version('Gdk', '4.0')
gi.require_version('GLib', '2.0')
gi.require_version('Gio', '2.0')
gi.require_version('Pango', '1.0')
from gi.repository import Gtk, GLib, Gio, Pango
from gi.repository import Gtk, Gdk, GLib, Gio, Pango
import os
import locale
......@@ -32,6 +33,10 @@ class MainWindow():
self.application_system_integration()
# Add images to the image theme for using them for application GUI.
image_theme = Gtk.IconTheme.get_for_display(Gdk.Display.get_default())
image_theme.add_search_path(os.path.dirname(os.path.realpath(__file__)) + "/../icons")
self.main_window_gui()
self.root_privileges_warning()
......@@ -1342,13 +1347,11 @@ class MainWindow():
def application_system_integration(self):
"""
Copy files for GUI icons and application shortcut (.desktop file) in user folders if they are not copied before.
These files are required if the application is installed as a Python package. Because these files are not copied
# in system image folders in this situation. These images will not be recolorable if they are not in system or
# user image folders. This function is stopped if environment type is Flatpak.
Copy files for application shortcut (.desktop file) in user folders if they are not copied before.
Because these files are not copied if the application is installed as a Python package.
"""
if Config.environment_type == "flatpak":
if Config.environment_type != "python_package":
return
# Called for removing files.
......@@ -1372,52 +1375,23 @@ class MainWindow():
except Exception:
pass
# Get current directory (which code of this application is in) and current user home directory (files will be copied in).
# Get current directory (which the code is in) and current user home directory (files will be copied in).
current_dir = os.path.dirname(os.path.realpath(__file__))
current_user_homedir = os.environ.get('HOME')
# Define folder list in the home directory for copying files.
home_dir_folder_list = [current_user_homedir + "/.local/share/applications/",
current_user_homedir + "/.local/share/icons/hicolor/scalable/actions/",
current_user_homedir + "/.local/share/icons/hicolor/scalable/apps/"]
# Generate folders to copy files in them if they are not generated before.
for folder in home_dir_folder_list:
if os.path.isdir(folder) == False:
generate_folder(folder)
# Get icon file paths in the home directory.
icon_list_actions = [current_user_homedir + "/.local/share/icons/hicolor/scalable/actions/" + file for file in os.listdir(current_user_homedir + "/.local/share/icons/hicolor/scalable/actions/") if file.startswith("system-monitoring-center-")]
icon_list_apps = [current_user_homedir + "/.local/share/icons/hicolor/scalable/apps/" + file for file in os.listdir(current_user_homedir + "/.local/share/icons/hicolor/scalable/apps/") if file.startswith("system-monitoring-center.svg")]
icon_list_home = sorted(icon_list_actions + icon_list_apps)
# Get icon file paths in the installation directory. These files are copied under this statement in order to avoid copying them if this is a system package which copies GUI images into "/usr/share/icons/..." folder during installation.
try:
icon_list_actions = [current_dir + "/../icons/hicolor/scalable/actions/" + file for file in os.listdir(current_dir + "/../icons/hicolor/scalable/actions/") if file.startswith("system-monitoring-center-")]
icon_list_apps = [current_dir + "/../icons/hicolor/scalable/apps/" + file for file in os.listdir(current_dir + "/../icons/hicolor/scalable/apps/") if file.startswith("system-monitoring-center.svg")]
icon_list_current = sorted(icon_list_actions + icon_list_apps)
# Copy .desktop file if it is not copied before.
if os.path.isfile(current_user_homedir + "/.local/share/applications/io.github.hakandundar34coding.system-monitoring-center.desktop") == False:
# Try to remove if there is a broken symlink of the file (symlink was generated in previous versions of the application).
remove_file(current_user_homedir + "/.local/share/applications/io.github.hakandundar34coding.system-monitoring-center.desktop")
# Import module for copying files
import shutil
copy_file(current_dir + "/../integration/io.github.hakandundar34coding.system-monitoring-center.desktop", current_user_homedir + "/.local/share/applications/")
except Exception:
icon_list_current = []
# Check if number of icon files are different. Remove the files in the home directory and copy the files in the installation directory if they are different.
if len(icon_list_home) != len(icon_list_current):
# Import module for copying files
# Copy .desktop file
file_name = "io.github.hakandundar34coding.system-monitoring-center.desktop"
sub_folder_name = "/.local/share/applications/"
if os.path.isfile(current_user_homedir + sub_folder_name + file_name) == False:
import shutil
copy_file(current_dir + "/../integration/" + file_name, current_user_homedir + sub_folder_name)
for file in icon_list_home:
remove_file(file)
for file in icon_list_current:
copy_file(file, current_user_homedir + "/.local/share/icons/hicolor/scalable/" + file.split("/")[-2] + "/")
# Copy application image
file_name = "system-monitoring-center.svg"
sub_folder_name = "/.local/share/icons/hicolor/scalable/apps/"
if os.path.isfile(current_user_homedir + sub_folder_name + file_name) == False:
import shutil
copy_file(current_dir + "/../icons/hicolor/scalable/apps/" + file_name, current_user_homedir + sub_folder_name)
def switch_to_default_tab(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment