From 75d3b565339798b22f4bf06fb9647f9dc7c62253 Mon Sep 17 00:00:00 2001 From: phlpsong Date: Fri, 19 Jan 2024 13:01:26 +0800 Subject: [PATCH] fix: update app item view model --- .../View/SettingView/Tabs/DisabledAppTab.swift | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Easydict/NewApp/View/SettingView/Tabs/DisabledAppTab.swift b/Easydict/NewApp/View/SettingView/Tabs/DisabledAppTab.swift index d12c0f4cd..3692ad44d 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/DisabledAppTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/DisabledAppTab.swift @@ -170,22 +170,22 @@ private struct ListButton: View { @available(macOS 13.0, *) private struct BlockAppItemView: View { - @StateObject private var appFetcher: AppFetcher + @StateObject private var appItemViewModel: AppItemViewModel @EnvironmentObject var disabledAppViewModel: DisabledAppViewModel init(with appModel: EZAppModel) { - _appFetcher = StateObject(wrappedValue: AppFetcher(appModel: appModel)) + _appItemViewModel = StateObject(wrappedValue: AppItemViewModel(appModel: appModel)) } var body: some View { HStack(alignment: .center) { - Image(nsImage: appFetcher.appIcon ?? NSImage()) + Image(nsImage: appItemViewModel.appIcon ?? NSImage()) .resizable() .scaledToFit() .frame(width: 24, height: 24) - Text(appFetcher.appName) + Text(appItemViewModel.appName) Spacer() } @@ -193,14 +193,11 @@ private struct BlockAppItemView: View { .contentShape(Rectangle()) .padding(.vertical, 4) .padding(.leading, 6) - .task { - appFetcher.getAppBundleInfo() - } } } @available(macOS 13.0, *) -class AppFetcher: ObservableObject { +private class AppItemViewModel: ObservableObject { @Published var appIcon: NSImage? = nil @Published var appName = "" @@ -209,6 +206,7 @@ class AppFetcher: ObservableObject { init(appModel: EZAppModel) { self.appModel = appModel + getAppBundleInfo() } func getAppBundleInfo() {