From 8c3390106a61c85a0e2d77a0a83d068e5fff0397 Mon Sep 17 00:00:00 2001 From: Robert Sanek Date: Sat, 1 Dec 2018 08:13:38 -0800 Subject: [PATCH 1/3] Add API endpoint to load a profile If this needs tests please let me know --- AnkiConnect.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/AnkiConnect.py b/AnkiConnect.py index 605dd21..e943e93 100644 --- a/AnkiConnect.py +++ b/AnkiConnect.py @@ -507,6 +507,23 @@ class AnkiConnect: return False + @api() + def loadProfile(self, name): + if not self.window().isVisible(): + self.window().pm.load(name) + self.window().loadProfile() + self.window().profileDiag.closeWithoutQuitting() + return "Loaded profile {}.".format(name) + else: + cur_profile = self.window().pm.name + if cur_profile != name: + self.window().unloadProfileAndShowProfileManager() + self.loadProfile(name) + return "Switched from profile {} to profile {}.".format(cur_profile, name) + else: + return "Profile {} already loaded.".format(name) + + @api() def sync(self): self.window().onSync() From 0fe61050c92d1869b74d7b7a21c351a6d22dcf5d Mon Sep 17 00:00:00 2001 From: Robert Sanek Date: Sat, 1 Dec 2018 19:42:56 -0800 Subject: [PATCH 2/3] Update AnkiConnect.py --- AnkiConnect.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/AnkiConnect.py b/AnkiConnect.py index e943e93..c6bb2a4 100644 --- a/AnkiConnect.py +++ b/AnkiConnect.py @@ -509,19 +509,18 @@ class AnkiConnect: @api() def loadProfile(self, name): + if name not in self.window().pm.profiles(): + return False if not self.window().isVisible(): self.window().pm.load(name) self.window().loadProfile() self.window().profileDiag.closeWithoutQuitting() - return "Loaded profile {}.".format(name) else: cur_profile = self.window().pm.name if cur_profile != name: self.window().unloadProfileAndShowProfileManager() self.loadProfile(name) - return "Switched from profile {} to profile {}.".format(cur_profile, name) - else: - return "Profile {} already loaded.".format(name) + return True @api() From e54e95eb7e6dab7e333439b08ae815fe3cb9cc34 Mon Sep 17 00:00:00 2001 From: rsanek Date: Sat, 1 Dec 2018 19:48:06 -0800 Subject: [PATCH 3/3] update readme --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 37c154a..de3b6e7 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,30 @@ guarantee that your application continues to function properly in the future. } ``` +* **loadProfile** + + Selects the profile specified in request. + + *Sample request*: + ```json + { + "action": "loadProfile", + "params": { + "name": "user1" + }, + "version": 6 + + } + ``` + + *Sample result*: + ```json + { + "result": true, + "error": null + } + ``` + * **multi** Performs multiple actions in one request, returning an array with the response of each action (in the given order).