feat: add remote news fetching
This commit is contained in:
parent
60a1929c8e
commit
a17ea0a9e1
|
@ -17,10 +17,10 @@
|
|||
<default>false</default>
|
||||
</key>
|
||||
<key name="enabled-providers" type="as">
|
||||
<default>["baichat", "catgpt", "huggingchat", "openaigpt35turbo"]</default>
|
||||
<default>["baichat", "hfopenassistantsft1pythia12b", "catgpt", "openaigpt35turbo"]</default>
|
||||
</key>
|
||||
<key name="latest-provider" type="s">
|
||||
<default>'huggingchat'</default>
|
||||
<default>'hfopenassistantsft1pythia12b'</default>
|
||||
</key>
|
||||
<key name="providers-data" type="a{ss}">
|
||||
<default>{}</default>
|
||||
|
@ -31,5 +31,8 @@
|
|||
<key name="close-all-without-dialog" type="b">
|
||||
<default>false</default>
|
||||
</key>
|
||||
<key name="allow-remote-fetching" type="b">
|
||||
<default>true</default>
|
||||
</key>
|
||||
</schema>
|
||||
</schemalist>
|
||||
|
|
|
@ -37,6 +37,15 @@ template Preferences : Adw.PreferencesWindow {
|
|||
valign: center;
|
||||
}
|
||||
}
|
||||
|
||||
Adw.ActionRow {
|
||||
title: _("Look for provider news");
|
||||
subtitle: _("News about issues with providers will be fetched from Bavarder website");
|
||||
activatable-widget: allow_remote_fetching_switch;
|
||||
Gtk.Switch allow_remote_fetching_switch {
|
||||
valign: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Adw.PreferencesGroup provider_group {
|
||||
|
|
37
src/main.py
37
src/main.py
|
@ -85,19 +85,6 @@ class KillableThread(threading.Thread):
|
|||
|
||||
ANNOUCEMENT_URL = "https://bavarder.codeberg.page/annoucements.json"
|
||||
|
||||
class Annoucements:
|
||||
def __init__(self):
|
||||
self.annoucements = {}
|
||||
self.load()
|
||||
|
||||
def load(self):
|
||||
try:
|
||||
self.annoucements = requests.get(ANNOUCEMENT_URL).json()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
class BavarderApplication(Adw.Application):
|
||||
"""The main application singleton class."""
|
||||
|
@ -144,12 +131,26 @@ class BavarderApplication(Adw.Application):
|
|||
GLib.Variant("s", self.latest_provider),
|
||||
self.on_set_provider_action
|
||||
)
|
||||
|
||||
self.load_annoucements()
|
||||
self.allow_remote_fetching = self.settings.get_boolean("allow-remote-fetching")
|
||||
self.use_theme = False
|
||||
|
||||
def load_annoucements(self):
|
||||
self.annoucements = requests.get(ANNOUCEMENT_URL).json()
|
||||
try:
|
||||
self.annoucements = requests.get(ANNOUCEMENT_URL).json()
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
self.latest = self.annoucements["latest"]
|
||||
del self.annoucements["latest"]
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
if not self.latest in version:
|
||||
self.win.banner.set_title(_("New version available!"))
|
||||
self.win.banner.set_revealed(True)
|
||||
|
||||
|
||||
|
||||
def on_open_help(self, action, *args):
|
||||
GLib.spawn_command_line_async(
|
||||
|
@ -253,6 +254,8 @@ class BavarderApplication(Adw.Application):
|
|||
necessary.
|
||||
"""
|
||||
self.new_window()
|
||||
if self.allow_remote_fetching:
|
||||
self.load_annoucements()
|
||||
self.win.prompt_text_view.grab_focus()
|
||||
|
||||
def load_dropdown(self, window=None):
|
||||
|
@ -1127,6 +1130,8 @@ Close All Without Dialog: {self.close_all_without_dialog}
|
|||
if an["provider"] == self.provider:
|
||||
if an["status"] == "open":
|
||||
self.win.banner.set_title(an["message"])
|
||||
self.win.banner.props.button_label = "Open settings"
|
||||
self.win.banner.connect("button-clicked", self.on_preferences_action)
|
||||
self.win.banner.set_revealed(True)
|
||||
return
|
||||
break
|
||||
|
|
|
@ -11,6 +11,7 @@ class Preferences(Adw.PreferencesWindow):
|
|||
provider_group = Gtk.Template.Child()
|
||||
use_text_view_switch = Gtk.Template.Child()
|
||||
close_all_without_dialog_switch = Gtk.Template.Child()
|
||||
allow_remote_fetching_switch = Gtk.Template.Child()
|
||||
|
||||
def __init__(self, application, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
@ -33,6 +34,11 @@ class Preferences(Adw.PreferencesWindow):
|
|||
"notify::active", self.on_close_all_without_dialog_switch_toggled
|
||||
)
|
||||
|
||||
self.allow_remote_fetching_switch.set_active(self.app.allow_remote_fetching)
|
||||
self.allow_remote_fetching_switch.connect(
|
||||
"notify::active", self.on_allow_remote_fetching_switch_toggled
|
||||
)
|
||||
|
||||
self.setup_providers()
|
||||
|
||||
def on_clear_after_send_switch_toggled(self, widget, *args):
|
||||
|
@ -62,6 +68,15 @@ class Preferences(Adw.PreferencesWindow):
|
|||
self.settings.set_boolean("close-all-without-dialog", False)
|
||||
self.app.close_all_without_dialog = False
|
||||
|
||||
def on_allow_remote_fetching_switch_toggled(self, widget, *args):
|
||||
"""Callback for the allow_remote_fetching_switch toggled event."""
|
||||
if widget.get_active():
|
||||
self.settings.set_boolean("allow-remote-fetching", True)
|
||||
self.app.allow_remote_fetching = True
|
||||
else:
|
||||
self.settings.set_boolean("allow-remote-fetching", False)
|
||||
self.app.allow_remote_fetching = False
|
||||
|
||||
def setup_providers(self):
|
||||
# for provider in self.app.providers.values():
|
||||
# try:
|
||||
|
|
Loading…
Reference in New Issue
Block a user