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 2 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
13 changes: 7 additions & 6 deletions Easydict/NewApp/View/SettingView/SettingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ struct SettingView: View {

func resizeWindowFrame() {
guard let window else { return }

// Disable zoom button, ref: https://stackoverflow.com/a/66039864/8378840
window.standardWindowButton(.zoomButton)?.isEnabled = false

let originalFrame = window.frame
let newSize = switch selection {
case .general, .privacy, .about, .disabled:
CGSize(width: 500, height: 520)
case .service:
// Keep the settings page windows all the same width to avoid strange animations.
let maxWidth = 650
let height = switch selection {
case .general:
maxWidth
case .service, .disabled:
500
case .privacy:
320
Expand Down
24 changes: 13 additions & 11 deletions Easydict/NewApp/View/SettingView/Tabs/DisabledAppTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Combine
import SwiftUI

class DisabledAppViewModel: ObservableObject {
private class DisabledAppViewModel: ObservableObject {
@Published var appModelList: [EZAppModel] = []
@Published var selectedAppModels: Set<EZAppModel> = []
@Published var isImporting = false
Expand Down Expand Up @@ -60,7 +60,7 @@ class DisabledAppViewModel: ObservableObject {

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

var listToolbar: some View {
ListToolbar()
Expand Down Expand Up @@ -133,15 +133,16 @@ private struct ListToolbar: View {
VStack(spacing: 0) {
Divider()
HStack(spacing: 0) {
ListButton(imageName: "plus", enabled: true) {
ListButton(systemName: "plus") {
disabledAppViewModel.isImporting.toggle()
}
Divider().padding(.vertical, 1)
let isNoSelectedApps = disabledAppViewModel.selectedAppModels.isEmpty
ListButton(imageName: "minus", enabled: !isNoSelectedApps) {
.environment(\.isEnabled, true)
Divider()
.padding(.vertical, 1)
ListButton(systemName: "minus") {
disabledAppViewModel.removeDisabledApp()
}
.disabled(isNoSelectedApps)
.environment(\.isEnabled, !disabledAppViewModel.selectedAppModels.isEmpty)
Spacer()
}
.padding(2)
Expand All @@ -153,24 +154,25 @@ private struct ListToolbar: View {

@available(macOS 13.0, *)
private struct ListButton: View {
var imageName: String
var enabled: Bool
@Environment(\.isEnabled) private var isEnabled: Bool
var systemName: String
var action: () -> Void

var body: some View {
Button(action: {
action()
}) {
Image(systemName: imageName)
Image(systemName: systemName)
.resizable()
.scaledToFit()
.frame(width: 10, height: 10)
.padding(.horizontal, 8)
.contentShape(Rectangle())
.foregroundStyle(enabled ? Color(.secondaryLabelColor) : Color(.tertiaryLabelColor))
.foregroundStyle(isEnabled ? Color(.secondaryLabelColor) : Color(.tertiaryLabelColor))
.font(.system(size: 14, weight: .semibold))
}
.buttonStyle(BorderlessButtonStyle())
.disabled(isEnabled)
}
}

Expand Down