Skip to content

Commit

Permalink
fix: update app item view model
Browse files Browse the repository at this point in the history
  • Loading branch information
phlpsong committed Jan 19, 2024
1 parent ff36390 commit 75d3b56
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions Easydict/NewApp/View/SettingView/Tabs/DisabledAppTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,37 +170,34 @@ 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()
}
.frame(maxWidth: .infinity)
.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 = ""
Expand All @@ -209,6 +206,7 @@ class AppFetcher: ObservableObject {

init(appModel: EZAppModel) {
self.appModel = appModel
getAppBundleInfo()
}

func getAppBundleInfo() {
Expand Down

0 comments on commit 75d3b56

Please sign in to comment.