From f79813cba1a96fb88532649639160e4c37d597d0 Mon Sep 17 00:00:00 2001 From: tisfeng Date: Wed, 23 Oct 2024 19:37:36 +0800 Subject: [PATCH] fix: call reloadLLMServicesSubscribers when app launch (#702) * fix: call reloadLLMServicesSubscribers when init * fix: do not call reloadLLMServicesSubscribers when service tab onAppear --- Easydict/Swift/Utility/GlobalContext.swift | 11 +++++++++-- .../View/SettingView/Tabs/TabView/ServiceTab.swift | 3 --- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Easydict/Swift/Utility/GlobalContext.swift b/Easydict/Swift/Utility/GlobalContext.swift index 3c6682a98..31f35422a 100644 --- a/Easydict/Swift/Utility/GlobalContext.swift +++ b/Easydict/Swift/Utility/GlobalContext.swift @@ -13,7 +13,7 @@ import Sparkle class GlobalContext: NSObject { // MARK: Lifecycle - override init() { + private override init() { self.updaterHelper = SPUUpdaterHelper() self.userDriverHelper = SPUUserDriverHelper() self.updaterController = SPUStandardUpdaterController( @@ -21,13 +21,18 @@ class GlobalContext: NSObject { updaterDelegate: updaterHelper, userDriverDelegate: userDriverHelper ) + + super.init() + + reloadLLMServicesSubscribers() } // MARK: Internal class SPUUpdaterHelper: NSObject, SPUUpdaterDelegate { func feedURLString(for _: SPUUpdater) -> String? { - var feedURLString = "https://raw.githubusercontent.com/tisfeng/Easydict/main/appcast.xml" + var feedURLString = + "https://raw.githubusercontent.com/tisfeng/Easydict/main/appcast.xml" #if DEBUG feedURLString = "http://localhost:8000/appcast.xml" #endif @@ -47,6 +52,8 @@ class GlobalContext: NSObject { // refresh subscribed services after duplicate service func reloadLLMServicesSubscribers() { + logInfo("reloadLLMServicesSubscribers") + for service in services { if let llmService = service as? LLMStreamService { llmService.cancelSubscribers() diff --git a/Easydict/Swift/View/SettingView/Tabs/TabView/ServiceTab.swift b/Easydict/Swift/View/SettingView/Tabs/TabView/ServiceTab.swift index 6e013bf93..3bf3dc8fe 100644 --- a/Easydict/Swift/View/SettingView/Tabs/TabView/ServiceTab.swift +++ b/Easydict/Swift/View/SettingView/Tabs/TabView/ServiceTab.swift @@ -58,9 +58,6 @@ struct ServiceTab: View { } .layoutPriority(1) } - .onAppear { - GlobalContext.shared.reloadLLMServicesSubscribers() - } .environmentObject(viewModel) }