Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mijorus committed May 28, 2023
1 parent 95884e9 commit e91a651
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
2 changes: 2 additions & 0 deletions it.mijorus.gearlever.Devel.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

"--talk-name=org.freedesktop.FileManager1",
"--talk-name=org.freedesktop.Flatpak",
"--talk-name=org.freedesktop.portal.OpenURI",
"--talk-name=org.freedesktop.portal.OpenFile",

"--filesystem=/tmp:rw"
],
Expand Down
14 changes: 12 additions & 2 deletions src/lib/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import dbus
import re
import os
import time
import logging
import gi
import requests
import hashlib

from .costants import APP_ID

gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')

Expand Down Expand Up @@ -103,8 +105,16 @@ def send_notification(notification=Gio.Notification, tag=None):


def get_gsettings() -> Gio.Settings:
return Gio.Settings.new('it.mijorus.gearlever')
return Gio.Settings.new(APP_ID)


def create_dict(*args: str):
return dict({i: eval(i) for i in args})


def portal(interface: str, bus_name: str='org.freedesktop.portal.Desktop', object_path: str='/org/freedesktop/portal/desktop') -> dbus.Interface:
bus = dbus.SessionBus()
obj = bus.get_object(bus_name, object_path)
inter = dbus.Interface(obj, interface)

return inter
28 changes: 14 additions & 14 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,27 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import sys
import gi
import logging
import os

from .lib.terminal import sh
from .lib.utils import log
from .lib.utils import log, portal
from .lib.costants import APP_ID, APP_NAME
from .providers.providers_list import appimage_provider
from .AboutDialog import AboutDialog
from .GearleverWindow import GearleverWindow
from .preferences import Preferences
import sys
import gi
import logging
import os

gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')

LOG_FILE_MAX_N_LINES = 2000

from gi.repository import Gtk, Gio, Adw, Gdk, GLib, GObject # noqa

LOG_FILE_MAX_N_LINES = 2000
LOG_FOLDER = GLib.get_user_cache_dir() + '/logs'

class GearleverApplication(Adw.Application):
"""The main application singleton class."""

Expand Down Expand Up @@ -78,7 +80,6 @@ def on_about_action(self, widget, _):

def on_preferences_action(self, widget, _):
"""Callback for the app.preferences action."""
print('app.preferences action activated')
pref = Preferences()
pref.present()

Expand Down Expand Up @@ -107,7 +108,7 @@ def on_open_file_chooser_response(self, dialog, result):
if selected_file and isinstance(self.props.active_window, GearleverWindow):
self.props.active_window.on_selected_local_file(selected_file)

def on_open_file_chooser(self, widget, _):
def on_open_file_chooser(self, widget, event):
if not self.win:
return

Expand All @@ -119,21 +120,20 @@ def on_open_file_chooser(self, widget, _):
callback=self.on_open_file_chooser_response
)

def on_open_log_file(self, widget, _):
def on_open_log_file(self, widget, event):
if not self.win:
return

#!TODO: replace with a portal call
sh(['xdg-open', GLib.get_user_cache_dir() + '/logs'])


def main(version):
"""The application's entry point."""

log_file = GLib.get_user_cache_dir() + f'/logs/{APP_NAME}.log'
log_file = f'{LOG_FOLDER}/{APP_NAME}.log'

if not os.path.exists(GLib.get_user_cache_dir() + '/logs'):
os.makedirs(GLib.get_user_cache_dir() + '/logs')
if not os.path.exists(LOG_FOLDER):
os.makedirs(LOG_FOLDER)

print('Logging to file ' + log_file)

Expand Down
6 changes: 2 additions & 4 deletions src/preferences.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import gi
import dbus
import logging

from .models.Models import InternalError
from .lib.costants import APP_ID
from .lib.utils import get_gsettings
from .State import state

gi.require_version('Gtk', '4.0')
Expand All @@ -13,9 +12,8 @@
class Preferences(Adw.PreferencesWindow):
def __init__(self, **kwargs) :
super().__init__(**kwargs)
self.application_id = APP_ID

self.settings = Gio.Settings.new(APP_ID)
self.settings = get_gsettings()

# page 1
page1 = Adw.PreferencesPage()
Expand Down
2 changes: 1 addition & 1 deletion src/providers/AppImageProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ..lib import terminal
from ..models.AppListElement import AppListElement, InstalledStatus
from ..lib.async_utils import _async
from ..lib.utils import log, cleanhtml, get_giofile_content_type, get_gsettings, create_dict, gio_copy, get_file_hash
from ..lib.utils import log, cleanhtml, get_giofile_content_type, get_gsettings, gio_copy, get_file_hash
from ..components.CustomComponents import LabelStart
from ..models.Models import FlatpakHistoryElement, AppUpdateElement, InternalError
from typing import List, Callable, Union, Dict, Optional, List, TypedDict
Expand Down

0 comments on commit e91a651

Please sign in to comment.