From b50764a280311c62c6c4c56428c05ce15a7acd84 Mon Sep 17 00:00:00 2001 From: Romain Vigier Date: Sun, 30 Oct 2022 12:49:09 +0100 Subject: [PATCH] Timer: Send a notification when falling back to the manual schedule --- src/meson.build | 4 +++ src/modules/Timer.js | 29 ++++++++++++++++-- src/po/nightthemeswitcher@romainvigier.fr.pot | 30 +++++++++++++++---- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/meson.build b/src/meson.build index b954ad7..eb5ea14 100644 --- a/src/meson.build +++ b/src/meson.build @@ -22,6 +22,9 @@ main = [ enums = [ 'enums/Time.js', ] +icons = [ + 'data/icons/nightthemeswitcher-symbolic.svg', +] modules = [ 'modules/Switcher.js', 'modules/SwitcherCommands.js', @@ -43,6 +46,7 @@ preferences = [ install_data(main, install_dir: INSTALL_DIR) install_data(enums, install_dir: INSTALL_DIR / 'enums') +install_data(icons, install_dir: INSTALL_DIR / 'icons') install_data(modules, install_dir: INSTALL_DIR / 'modules') install_data(preferences, install_dir: INSTALL_DIR / 'preferences') diff --git a/src/modules/Timer.js b/src/modules/Timer.js index d2d9a06..f5d2849 100644 --- a/src/modules/Timer.js +++ b/src/modules/Timer.js @@ -4,10 +4,12 @@ const { Geoclue, Gio, GLib, GObject, Meta, Shell } = imports.gi; const { extensionUtils } = imports.misc; -const { main } = imports.ui; +const { main, messageTray } = imports.ui; const Me = extensionUtils.getCurrentExtension(); +const _ = extensionUtils.gettext; + const debug = Me.imports.debug; const { Time } = Me.imports.enums.Time; @@ -244,7 +246,7 @@ var Timer = class extends GObject.Object { this.#changeTime(time, true); } - #onGeoclueReady(_, result) { + #onGeoclueReady(_geoclue, result) { try { this.#geoclue = Geoclue.Simple.new_finish(result); this.#geoclueLocationConnectionId = this.#geoclue.connect('notify::location', this.#onLocationChanged.bind(this)); @@ -257,6 +259,29 @@ var Timer = class extends GObject.Object { this.#updateSuntimes(); } else { console.error(`[${Me.metadata.name}] Unable to retrieve the location, using the manual schedule times instead.\n${e}`); + + const source = new messageTray.Source(Me.metadata.name, 'dialog-information-symbolic'); + main.messageTray.add(source); + + const notification = new messageTray.Notification( + source, + _('Unknown Location'), + _('A manual schedule will be used to switch the dark mode.'), + { + gicon: Gio.icon_new_for_string(GLib.build_filenamev([Me.path, 'icons', 'nightthemeswitcher-symbolic.svg'])), + } + ); + notification.addAction(_('Edit Manual Schedule'), () => extensionUtils.openPrefs()); + + const locationSettingsApp = Shell.AppSystem.get_default().lookup_app('gnome-location-panel.desktop'); + if (locationSettingsApp) + notification.addAction(_('Open Location Settings'), () => locationSettingsApp.activate()); + + notification.connect('activated', () => extensionUtils.openPrefs()); + + source.showNotification(notification); + + this.#settings.set_boolean('manual-schedule', true); } } } diff --git a/src/po/nightthemeswitcher@romainvigier.fr.pot b/src/po/nightthemeswitcher@romainvigier.fr.pot index c0f80de..a2b5ecd 100644 --- a/src/po/nightthemeswitcher@romainvigier.fr.pot +++ b/src/po/nightthemeswitcher@romainvigier.fr.pot @@ -8,7 +8,11 @@ msgid "" msgstr "" "Project-Id-Version: nightthemeswitcher@romainvigier.fr\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-08-17 14:13+0200\n" +<<<<<<< HEAD +"POT-Creation-Date: 2022-10-30 14:28+0100\n" +======= +"POT-Creation-Date: 2022-10-30 14:03+0100\n" +>>>>>>> d754bee (Timer: Send a notification when falling back to the manual schedule) "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -21,7 +25,7 @@ msgstr "" msgid "Change background" msgstr "" -#: src/data/ui/BackgroundButton.ui:31 +#: src/data/ui/BackgroundButton.ui:24 msgid "Select your background image" msgstr "" @@ -64,7 +68,7 @@ msgstr "" msgid "notify-send \"Hello sunshine!\"" msgstr "" -#: src/data/ui/CommandsPage.ui:35 src/data/ui/SchedulePage.ui:39 +#: src/data/ui/CommandsPage.ui:35 src/data/ui/SchedulePage.ui:40 msgid "Sunset" msgstr "" @@ -104,7 +108,7 @@ msgstr "" msgid "Manual schedule" msgstr "" -#: src/data/ui/SchedulePage.ui:55 +#: src/data/ui/SchedulePage.ui:57 msgid "Keyboard shortcut" msgstr "" @@ -167,7 +171,23 @@ msgstr "" msgid ":" msgstr "" -#: src/preferences/BackgroundButton.js:69 +#: src/modules/Timer.js:268 +msgid "Unknown Location" +msgstr "" + +#: src/modules/Timer.js:269 +msgid "A manual schedule will be used to switch the dark mode." +msgstr "" + +#: src/modules/Timer.js:274 +msgid "Edit Manual Schedule" +msgstr "" + +#: src/modules/Timer.js:278 +msgid "Open Location Settings" +msgstr "" + +#: src/preferences/BackgroundButton.js:86 msgid "This image format is not supported." msgstr ""