Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add disabled app list tab #340

Merged
merged 21 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -2415,6 +2415,23 @@
}
}
},
"setting.disabled.import_app_error.message" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Unable to add Application"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "无法添加应用"
}
}
}
},
"setting.general.advance.default_tts_service" : {
"localizations" : {
"en" : {
Expand Down
54 changes: 24 additions & 30 deletions Easydict/NewApp/View/SettingView/Tabs/DisabledAppTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class DisabledAppViewModel: ObservableObject {

@Published var isImporting = false

@Published var isShowImportErrorAlert = false

init() {
fetchDisabledApps()
}

func fetchDisabledApps() {
appModelList = EZLocalStorage.shared().selectTextTypeAppModelList
}
Expand Down Expand Up @@ -57,7 +63,7 @@ class DisabledAppViewModel: ObservableObject {

@available(macOS 13.0, *)
struct DisabledAppTab: View {
@ObservedObject var disabledAppViewModel = DisabledAppViewModel()
@StateObject var disabledAppViewModel = DisabledAppViewModel()

var listToolbar: some View {
ListToolbar()
Expand All @@ -71,14 +77,18 @@ struct DisabledAppTab: View {
disabledAppViewModel.newAppURLsSelected(from: urls)
case let .failure(error):
print("fileImporter error: \(error)")
disabledAppViewModel.isShowImportErrorAlert.toggle()
}
}
.alert(isPresented: $disabledAppViewModel.isShowImportErrorAlert) {
Alert(title: Text(""), message: Text("setting.disabled.import_app_error.message"), dismissButton: .default(Text("ok")))
}
}

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 @@ -110,14 +120,11 @@ struct DisabledAppTab: View {
}
.frame(maxWidth: 500)
.environmentObject(disabledAppViewModel)
.onAppear {
disabledAppViewModel.fetchDisabledApps()
}
}
}

@available(macOS 13.0, *)
struct ListToolbar: View {
private struct ListToolbar: View {
@EnvironmentObject private var disabledAppViewModel: DisabledAppViewModel

var body: some View {
Expand All @@ -142,7 +149,7 @@ struct ListToolbar: View {
}

@available(macOS 13.0, *)
struct ListButton: View {
private struct ListButton: View {
var imageName: String
var action: () -> Void

Expand All @@ -162,47 +169,34 @@ struct ListButton: View {
}

@available(macOS 13.0, *)
struct BlockAppItemView: View {
@StateObject private var appFetcher: AppFetcher

private struct BlockAppItemView: View {
@EnvironmentObject var disabledAppViewModel: DisabledAppViewModel

init(with appModel: EZAppModel) {
_appFetcher = StateObject(wrappedValue: AppFetcher(appModel: appModel))
}
var appModel: EZAppModel

@State private var appIcon: NSImage = .init()

@State private var appName = ""

var body: some View {
HStack(alignment: .center) {
Image(nsImage: appFetcher.appIcon ?? NSImage())
Image(nsImage: appIcon)
.resizable()
.scaledToFit()
.frame(width: 24, height: 24)

Text(appFetcher.appName)
Text(appName)

Spacer()
}
.frame(maxWidth: .infinity)
.contentShape(Rectangle())
.padding(.vertical, 4)
.padding(.leading, 6)
.task {
appFetcher.getAppBundleInfo()
.onAppear {
getAppBundleInfo()
}
}
}

@available(macOS 13.0, *)
class AppFetcher: ObservableObject {
@Published var appIcon: NSImage? = nil

@Published var appName = ""

var appModel: EZAppModel

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

func getAppBundleInfo() {
let appBundleId = appModel.appBundleID
Expand Down