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) }