Skip to content

Commit

Permalink
Merge branch 'remove-whatsnew' into update-flatpak-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbende committed Dec 22, 2023
2 parents ad2a57d + 254da19 commit ac2b8e6
Show file tree
Hide file tree
Showing 40 changed files with 942 additions and 1,536 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ See [DEVELOPMENT.md](DEVELOPMENT.md) for detailed instructions and developing Co
- `distro`
- `requests`
- `pytz`
- `packaging`
- `gi-cairo`
- `gst-1.0`
- `file`
Expand Down
14 changes: 0 additions & 14 deletions com.github.geigi.cozy.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,6 @@
}
]
},
{
"name": "python3-packaging",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"packaging\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/ec/1a/610693ac4ee14fcdf2d9bf3c493370e4f2ef7ae2e19217d7a237ff42367d/packaging-23.2-py3-none-any.whl",
"sha256": "8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7"
}
]
},
{
"name": "python3-peewee",
"buildsystem": "simple",
Expand Down
11 changes: 6 additions & 5 deletions cozy/app_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from cozy.ui.main_view import CozyUI
from cozy.ui.media_controller import MediaController
from cozy.ui.search_view import SearchView
from cozy.ui.widgets.whats_new_window import WhatsNewWindow
from cozy.view import View
from cozy.view_model.app_view_model import AppViewModel
from cozy.view_model.book_detail_view_model import BookDetailViewModel
Expand All @@ -37,6 +36,7 @@
from cozy.view_model.search_view_model import SearchViewModel
from cozy.view_model.settings_view_model import SettingsViewModel
from cozy.view_model.sleep_timer_view_model import SleepTimerViewModel
from cozy.view_model.storages_view_model import StoragesViewModel


class AppController(metaclass=Singleton):
Expand All @@ -49,8 +49,6 @@ def __init__(self, gtk_app, main_window_builder, main_window):

reporter.info("main", "startup")

self.whats_new_window: WhatsNewWindow = WhatsNewWindow()

self.library_view: LibraryView = LibraryView(main_window_builder)
self.app_view: AppView = AppView(main_window_builder)
self.search_view: SearchView = SearchView()
Expand All @@ -75,7 +73,7 @@ def __init__(self, gtk_app, main_window_builder, main_window):
self.library_view_model.add_listener(self._on_open_view)
self.library_view_model.add_listener(self._on_library_view_event)
self.playback_control_view_model.add_listener(self._on_open_view)
self.headerbar_view_model.add_listener(self._on_open_view)
self.headerbar_view_model.add_listener(self._on_working_event)
self.app_view_model.add_listener(self._on_app_view_event)

self.main_window.add_listener(self._on_main_window_event)
Expand Down Expand Up @@ -108,6 +106,7 @@ def configure_inject(self, binder):
binder.bind_to_constructor(ToastNotifier, lambda: ToastNotifier())
binder.bind_to_constructor(AppViewModel, lambda: AppViewModel())
binder.bind_to_constructor(SettingsViewModel, lambda: SettingsViewModel())
binder.bind_to_constructor(StoragesViewModel, lambda: StoragesViewModel())

def open_author(self, author: str):
self.library_view_model.library_view_mode = LibraryViewMode.AUTHOR
Expand Down Expand Up @@ -146,10 +145,12 @@ def _on_app_view_event(self, event: str, data):
if event == "view":
self.headerbar_view_model.set_view(data)

def _on_main_window_event(self, event: str, data):
def _on_working_event(self, event: str, data) -> None:
if event == "working":
self.book_detail_view_model.lock_ui = data
self.settings_view_model.lock_ui = data

def _on_main_window_event(self, event: str, data):
if event == "open_view":
self._on_open_view(data, None)

Expand Down
71 changes: 14 additions & 57 deletions cozy/application.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import gettext
import locale
import logging
import os
import platform
Expand All @@ -9,59 +7,26 @@
from traceback import format_exception

import distro

import gi

from cozy.db.storage import Storage
from cozy.ui.widgets.filter_list_box import FilterListBox
from cozy.ui.widgets.seek_bar import SeekBar

from gi.repository import Gtk, GLib, Adw
from gi.repository import Adw, GLib

from cozy.app_controller import AppController
from cozy.control.db import init_db
from cozy.control.mpris import MPRIS
from cozy.db.settings import Settings
from cozy.db.storage import Storage
from cozy.report import reporter
from cozy.ui.main_view import CozyUI
from cozy.ui.widgets.filter_list_box import FilterListBox
from cozy.version import __version__


log = logging.getLogger("application")


def setup_thread_excepthook():
"""
Workaround for `sys.excepthook` thread bug from:
http://bugs.python.org/issue1230540
Call once from the main thread before creating any threads.
"""

init_original = threading.Thread.__init__

def init(self, *args, **kwargs):

init_original(self, *args, **kwargs)
run_original = self.run

def run_with_except_hook(*args2, **kwargs2):
try:
run_original(*args2, **kwargs2)
except Exception:
sys.excepthook(*sys.exc_info())

self.run = run_with_except_hook

threading.Thread.__init__ = init


class Application(Adw.Application):
ui: CozyUI
app_controller: AppController

def __init__(self, localedir: str, pkgdatadir: str):
self.localedir = localedir
def __init__(self, pkgdatadir: str):
self.pkgdatadir = pkgdatadir

super().__init__(application_id='com.github.geigi.cozy')
Expand All @@ -70,19 +35,7 @@ def __init__(self, localedir: str, pkgdatadir: str):
GLib.setenv("PULSE_PROP_media.role", "music", True)
GLib.set_application_name("Cozy")

self.old_except_hook = sys.excepthook
sys.excepthook = self.handle_exception
setup_thread_excepthook()

# We need to call `locale.*textdomain` to get the strings in UI files translated
locale.bindtextdomain('com.github.geigi.cozy', localedir)
locale.textdomain('com.github.geigi.cozy')

# But also `gettext.*textdomain`, to make `_("foo")` in Python work as well
gettext.bindtextdomain('com.github.geigi.cozy', localedir)
gettext.textdomain('com.github.geigi.cozy')

gettext.install('com.github.geigi.cozy', localedir)
threading.excepthook = self.handle_exception

def do_startup(self):
log.info(distro.linux_distribution(full_distribution_name=False))
Expand Down Expand Up @@ -114,14 +67,18 @@ def do_activate(self):
mpris = MPRIS(self)
mpris._on_current_changed()

def handle_exception(self, exc_type, exc_value, exc_traceback):
def handle_exception(self, _):
print("handle exception")

exc_type, exc_value, exc_traceback = sys.exc_info()

if exc_type is SystemExit:
return

try:
reporter.exception("uncaught", exc_value, "\n".join(format_exception(exc_type, exc_value, exc_traceback)))
except Exception:
None

self.old_except_hook(exc_type, exc_value, exc_traceback)
finally:
sys.excepthook(exc_type, exc_value, exc_traceback)

def quit(self):
self.app_controller.quit()
Expand Down
Loading

0 comments on commit ac2b8e6

Please sign in to comment.