From ceb5e3648b6b111dc26ffa636544dcd86c74a003 Mon Sep 17 00:00:00 2001 From: phlpsong Date: Fri, 19 Jan 2024 13:16:06 +0800 Subject: [PATCH] fix: remove item view model --- .../SettingView/Tabs/DisabledAppTab.swift | 33 +++++++------------ 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/Easydict/NewApp/View/SettingView/Tabs/DisabledAppTab.swift b/Easydict/NewApp/View/SettingView/Tabs/DisabledAppTab.swift index 3692ad44d..62c131753 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/DisabledAppTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/DisabledAppTab.swift @@ -88,7 +88,7 @@ struct DisabledAppTab: View { var appListView: some View { List(selection: $disabledAppViewModel.selectedAppModels) { ForEach(disabledAppViewModel.appModelList, id: \.self) { app in - BlockAppItemView(with: app) + BlockAppItemView(appModel: app) .tag(app) } .listRowSeparator(.hidden) @@ -170,22 +170,22 @@ private struct ListButton: View { @available(macOS 13.0, *) private struct BlockAppItemView: View { - @StateObject private var appItemViewModel: AppItemViewModel - @EnvironmentObject var disabledAppViewModel: DisabledAppViewModel - init(with appModel: EZAppModel) { - _appItemViewModel = StateObject(wrappedValue: AppItemViewModel(appModel: appModel)) - } + var appModel: EZAppModel + + @State private var appIcon: NSImage = .init() + + @State private var appName = "" var body: some View { HStack(alignment: .center) { - Image(nsImage: appItemViewModel.appIcon ?? NSImage()) + Image(nsImage: appIcon) .resizable() .scaledToFit() .frame(width: 24, height: 24) - Text(appItemViewModel.appName) + Text(appName) Spacer() } @@ -193,20 +193,9 @@ private struct BlockAppItemView: View { .contentShape(Rectangle()) .padding(.vertical, 4) .padding(.leading, 6) - } -} - -@available(macOS 13.0, *) -private class AppItemViewModel: ObservableObject { - @Published var appIcon: NSImage? = nil - - @Published var appName = "" - - var appModel: EZAppModel - - init(appModel: EZAppModel) { - self.appModel = appModel - getAppBundleInfo() + .onAppear { + getAppBundleInfo() + } } func getAppBundleInfo() {