Skip to content

Commit

Permalink
fix: remove item view model
Browse files Browse the repository at this point in the history
  • Loading branch information
phlpsong committed Jan 19, 2024
1 parent 75d3b56 commit ceb5e36
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions Easydict/NewApp/View/SettingView/Tabs/DisabledAppTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -170,43 +170,32 @@ 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()
}
.frame(maxWidth: .infinity)
.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() {
Expand Down

0 comments on commit ceb5e36

Please sign in to comment.