From 36f72082e9a6a77cf84c5000150e7f779d73b14d Mon Sep 17 00:00:00 2001 From: Heath Raftery Date: Thu, 19 Jun 2025 02:11:11 +1000 Subject: [PATCH] Restore non-App Store support for Slack A previous commit added support for when Slack is installed through the App Store. Alas, it broke support for non-App Store situations! This commit restores non- App Store support, while retaining the support for App Store scenarios. --- src/pycookiecheat/chrome.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/pycookiecheat/chrome.py b/src/pycookiecheat/chrome.py index 55e745a..aa58703 100644 --- a/src/pycookiecheat/chrome.py +++ b/src/pycookiecheat/chrome.py @@ -123,22 +123,28 @@ def get_macos_config(browser: BrowserType) -> dict: raise ValueError(errmsg) from e cookie_file = "~" / app_support / cookies_suffix - # Slack cookies can be in two places on MacOS depending on whether it was - # installed from the App Store or direct download. - if browser is BrowserType.SLACK and not cookie_file.exists(): - # And this location if Slack is installed from App Store + # Cookie location and keyring username in MacOS depends on whether the + # application was installed from the App Store or direct download. To find + # out, we simply assume it's direct download and fall back to App Store if + # it's not there. Currently this distinction is only known for Slack, so + # that is the only case handled here. + isAppStore = False + if browser is BrowserType.SLACK and not cookie_file.expanduser().exists(): + isAppStore = True cookie_file = ( "~/Library/Containers/com.tinyspeck.slackmacgap/Data" - / app_support - / cookies_suffix + / app_support / cookies_suffix ) browser_name = browser.title() keyring_service_name = f"{browser_name} Safe Storage" - keyring_username = browser_name - if browser is BrowserType.SLACK: - keyring_username = "Slack App Store Key" + if browser is BrowserType.SLACK and isAppStore: + keyring_username = f"{browser_name} App Store Key" + elif browser is BrowserType.SLACK: + keyring_username = f"{browser_name} Key" + else: + keyring_username = f"{browser_name}" key_material = keyring.get_password(keyring_service_name, keyring_username) if key_material is None: