diff --git a/errands/utils/goa.py b/errands/utils/goa.py new file mode 100644 index 00000000..9fa9d245 --- /dev/null +++ b/errands/utils/goa.py @@ -0,0 +1,41 @@ +# Copyright 2023-2024 Vlad Krupinskii +# SPDX-License-Identifier: MIT + +from errands.utils.logging import Log + + +def get_goa_credentials(acc_name: str) -> dict[str, str] | None: + """ + If Gnome Online Accounts is installed, try to get account info. + Only for password based account yet. + """ + + try: + import gi + + gi.require_version("Goa", "1.0") + from gi.repository import Goa + except (ValueError, ModuleNotFoundError): + Log.debug("Gnome Online Accounts is not installed. Skipping...") + return None + + client: Goa.Client = Goa.Client.new_sync(None) + accounts: list[Goa.ObjectProxy] = client.get_accounts() + for account in accounts: + acc: Goa.AccountProxy = account.get_account() + name: str = acc.get_cached_property("ProviderName").get_string() + if name == acc_name: + Log.debug(f"GOA: Getting data for {acc_name}") + username, url = ( + acc.get_cached_property("PresentationIdentity").get_string().split("@") + ) + password = account.get_password_based().call_get_password_sync( + arg_id=acc.get_cached_property("Id").get_string() + ) + result: dict[str, str] = { + "url": url, + "username": username, + "password": password, + } + return result + return None diff --git a/errands/utils/sync.py b/errands/utils/sync.py index 9ee260c5..9de7dc65 100644 --- a/errands/utils/sync.py +++ b/errands/utils/sync.py @@ -2,7 +2,6 @@ # SPDX-License-Identifier: MIT import datetime, urllib3 -from typing import Callable from caldav import Calendar, DAVClient, Principal, Todo from caldav.elements import dav from gi.repository import Adw, GLib diff --git a/errands/widgets/preferences.py b/errands/widgets/preferences.py index 1bccd94f..9165edf7 100644 --- a/errands/widgets/preferences.py +++ b/errands/widgets/preferences.py @@ -1,6 +1,7 @@ # Copyright 2023 Vlad Krupinskii # SPDX-License-Identifier: MIT +from errands.utils.goa import get_goa_credentials from gi.repository import Adw, Gtk from errands.utils.sync import Sync from errands.utils.gsettings import GSettings @@ -189,6 +190,17 @@ def _setup_sync(self) -> None: with self.sync_password.freeze_notify(): self.sync_password.props.text = password if password else "" + # Fill out forms from Gnome Online Accounts if needed + acc_name: str = self.sync_providers.props.selected_item.props.string + data: dict[str, str] | None = get_goa_credentials(acc_name) + if data: + if not GSettings.get("sync-url"): + self.sync_url.set_text(data["url"]) + if not GSettings.get("sync-username"): + self.sync_username.set_text(data["username"]) + if not GSettings.get_secret(acc_name): + self.sync_password.set_text(data["password"]) + def on_sync_provider_selected(self, *_) -> None: self._setup_sync() diff --git a/io.github.mrvladus.List.Devel.json b/io.github.mrvladus.List.Devel.json index 0d853336..53167e04 100644 --- a/io.github.mrvladus.List.Devel.json +++ b/io.github.mrvladus.List.Devel.json @@ -1,5 +1,5 @@ { - "app-id": "io.github.mrvladus.List.Devel", + "id": "io.github.mrvladus.List.Devel", "runtime": "org.gnome.Platform", "runtime-version": "45", "sdk": "org.gnome.Sdk", @@ -10,12 +10,44 @@ "--socket=fallback-x11", "--share=ipc", "--share=network", - "--talk-name=org.freedesktop.secrets" + "--talk-name=org.freedesktop.secrets", + "--talk-name=org.gnome.OnlineAccounts" ], "cleanup": [ - "/lib/debug" + "/lib/debug", + "/include", + "/lib/pkgconfig", + "/man", + "/share/aclocal", + "/share/gtk-doc", + "/share/man", + "/share/pkgconfig", + "/share/vala", + "*.la", + "*.a" ], "modules": [ + { + "name": "gnome-online-accounts", + "buildsystem": "meson", + "config-opts": [ + "-Dgoabackend=false", + "-Dexchange=false", + "-Dgoogle=false", + "-Dimap_smtp=false", + "-Dwebdav=false", + "-Dkerberos=false", + "-Dwindows_live=false", + "-Dvapi=false" + ], + "sources": [ + { + "type": "git", + "url": "https://gitlab.gnome.org/GNOME/gnome-online-accounts.git", + "branch": "master" + } + ] + }, "build-aux/python3-modules.json", { "name": "errands",