Skip to content

Commit

Permalink
Add telemetry preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Maksimov committed Jan 22, 2024
1 parent 63f6892 commit 0863da3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
15 changes: 15 additions & 0 deletions data/ui/preferences_general.blp
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,19 @@ template $PreferencesGeneralPage : Adw.PreferencesPage {
}
}
}

Adw.PreferencesGroup {
title: _("Telemetry");

Adw.ActionRow {
title: _("Collect analytics");
use-underline: true;
subtitle: _("Allow anonymous analytics.");
activatable-widget: telemetry_switch;

Switch telemetry_switch {
valign: center;
}
}
}
}
2 changes: 1 addition & 1 deletion data/ui/preferences_window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Gtk 4.0;
using Adw 1;

template $PreferencesWindow : Adw.PreferencesWindow {
default-height: 400;
default-height: 480;
default-width: 640;
width-request: 360;
height-request: 300;
Expand Down
12 changes: 12 additions & 0 deletions frog/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def do_startup(self, *args, **kwargs):
self.create_action('preferences', self.on_preferences, ['<primary>comma'])
self.create_action('github_star', self.on_github_star)

self.settings.connect("changed", self.on_settings_changed)

def do_activate(self):
win = self.props.active_window
if not win:
Expand Down Expand Up @@ -139,6 +141,16 @@ def ensure_installation_id(self):

telemetry.set_installation_id(self.installation_id)

def on_settings_changed(self, settings, key):
logger.debug('SETTINGS: %s changed', key)
if key == "telemetry":
value = settings.get_boolean(key)
if value:
telemetry.capture('telemetry activated')
else:
telemetry.capture('telemetry deactivated')
telemetry.set_is_active(value)

def on_preferences(self, _action, _param) -> None:
telemetry.capture('preferences activated')
self.get_active_window().show_preferences()
Expand Down
2 changes: 2 additions & 0 deletions frog/widgets/preferences_general_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class PreferencesGeneralPage(Adw.PreferencesPage):
extra_language_combo: Adw.ComboRow = Gtk.Template.Child()
autocopy_switch: Gtk.Switch = Gtk.Template.Child()
autolinks_switch: Gtk.Switch = Gtk.Template.Child()
telemetry_switch: Gtk.Switch = Gtk.Template.Child()

def __init__(self):
super().__init__()
Expand All @@ -49,6 +50,7 @@ def __init__(self):

self.settings.bind('autocopy', self.autocopy_switch, 'active', Gio.SettingsBindFlags.DEFAULT)
self.settings.bind('autolinks', self.autolinks_switch, 'active', Gio.SettingsBindFlags.DEFAULT)
self.settings.bind('telemetry', self.telemetry_switch, 'active', Gio.SettingsBindFlags.DEFAULT)

downloaded_langs = language_manager.get_downloaded_languages()
# Fill second language
Expand Down

0 comments on commit 0863da3

Please sign in to comment.