Skip to content

Commit dcf476e

Browse files
feat: add image resource tools and polish native menus
1 parent 6bf596d commit dcf476e

47 files changed

Lines changed: 2967 additions & 238 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎App/FileMint/AboutPane.swift‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ struct AboutPane: View {
99
var body: some View {
1010
ScrollView {
1111
VStack(alignment: .leading, spacing: 16) {
12-
HStack(spacing: 14) {
12+
VStack(spacing: 12) {
1313
Image(nsImage: NSApplication.shared.applicationIconImage)
14-
.resizable().frame(width: 60, height: 60).accessibilityHidden(true)
14+
.resizable().frame(width: 76, height: 76).accessibilityHidden(true)
1515
VStack(alignment: .leading, spacing: 4) {
16-
Text("FileMint").font(.title2.weight(.semibold))
16+
Text("FileMint").font(.system(size: 27, weight: .semibold))
1717
Text("\(model.text(.version)) \(updater.currentVersion) (\(updater.buildNumber))")
1818
.font(.callout).foregroundStyle(.secondary).textSelection(.enabled)
1919
}
20-
Spacer()
21-
}
20+
}.frame(maxWidth: .infinity).padding(.vertical, 12)
2221
Grid(alignment: .leading, horizontalSpacing: 24, verticalSpacing: 8) {
2322
GridRow {
2423
Text(model.text(.copyright)).foregroundStyle(.secondary)
@@ -36,13 +35,12 @@ struct AboutPane: View {
3635
.fixedSize(horizontal: false, vertical: true)
3736
}
3837
}
39-
}.font(.callout)
38+
}.font(.system(size: 12)).mintSurface()
4039
HStack(spacing: 18) {
4140
Link(model.text(.projectPage), destination: FileMintAbout.projectURL)
4241
Link(model.text(.license), destination: FileMintAbout.licenseURL)
4342
Link(model.text(.privacyPolicy), destination: FileMintAbout.privacyURL)
4443
}.font(.callout)
45-
Divider()
4644
VStack(alignment: .leading, spacing: 10) {
4745
Text(model.text(.updates)).font(.headline)
4846
Text(model.text(updater.statusKey))
@@ -86,7 +84,7 @@ struct AboutPane: View {
8684
Text(model.text(.updateInstallHint)).font(.caption).foregroundStyle(.secondary)
8785
.fixedSize(horizontal: false, vertical: true)
8886
}
89-
}
87+
}.mintSurface()
9088
}.padding(1)
9189
}
9290
}

‎App/FileMint/ContentView.swift‎

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,46 @@ import FileMintCore
33
import SwiftUI
44

55
struct ContentView: View {
6+
var launchResourceTool: (ResourceTool) -> Void = { FileOperationCoordinator.shared.chooseImages(for: $0) }
67
@EnvironmentObject private var model: PreferencesModel
78
@EnvironmentObject private var updater: UpdateModel
89
@FocusState private var focusedPane: PreferencesModel.Pane?
910

1011
var body: some View {
1112
HStack(spacing: 0) {
1213
sidebar
13-
Divider()
14+
Rectangle().fill(FileMintStyle.line).frame(width: 0.7)
1415
VStack(alignment: .leading, spacing: 0) {
16+
HStack(spacing: 10) {
17+
Text(model.selectedPane.groupTitle(model.preferences.language))
18+
Text("/").foregroundStyle(.tertiary)
19+
Text(model.text(model.selectedPane.title))
20+
Spacer()
21+
Image(systemName: model.selectedPane.symbol).foregroundStyle(.tertiary)
22+
}.font(.system(size: 11)).foregroundStyle(.secondary)
23+
.padding(.horizontal, 30).frame(height: 48)
24+
Rectangle().fill(FileMintStyle.line).frame(height: 0.7)
1525
VStack(alignment: .leading, spacing: 7) {
16-
Text(model.text(model.selectedPane.title)).font(.system(size: 25, weight: .bold))
26+
Text(model.text(model.selectedPane.title)).font(.system(size: 25, weight: .semibold))
1727
.accessibilityAddTraits(.isHeader)
18-
Text(model.text(model.selectedPane.subtitle))
19-
.font(.callout).foregroundStyle(.secondary)
28+
Text(model.selectedPane.subtitleText(model.preferences.language))
29+
.font(.system(size: 12)).foregroundStyle(.secondary)
2030
.fixedSize(horizontal: false, vertical: true)
21-
}.padding(28)
22-
Divider().padding(.horizontal, 28)
23-
page.padding(28).frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
31+
}.frame(maxWidth: .infinity, alignment: .leading).padding(.horizontal, 30).padding(.top, 28).padding(.bottom, 23)
32+
page.padding(.horizontal, 30).frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
2433
if let error = model.lastError {
2534
Text(error).foregroundStyle(.red).font(.callout).textSelection(.enabled)
2635
.padding([.horizontal, .bottom], 28)
2736
}
28-
}.background(Color(nsColor: .windowBackgroundColor))
37+
HStack(spacing: 6) {
38+
Label(InterfaceText.localOnly.text(model.preferences.language), systemImage: "checkmark.shield")
39+
Spacer()
40+
Text("FileMint \(updater.currentVersion)").foregroundStyle(.tertiary)
41+
}.font(.system(size: 10)).foregroundStyle(.secondary).padding(.horizontal, 30).padding(.vertical, 18)
42+
}.background(FileMintStyle.background)
2943
}
30-
.frame(minWidth: 840, minHeight: 600)
44+
.frame(minWidth: 840, minHeight: 600).tint(FileMintStyle.accent)
45+
.ignoresSafeArea(.container, edges: .top)
3146
.onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { _ in
3247
model.refreshStatus()
3348
}
@@ -39,22 +54,21 @@ struct ContentView: View {
3954
Image(nsImage: NSApplication.shared.applicationIconImage)
4055
.resizable().frame(width: 40, height: 40).accessibilityHidden(true)
4156
VStack(alignment: .leading, spacing: 3) {
42-
Text("FileMint").font(.headline)
43-
Text(model.text(.settingsLabel)).font(.caption).foregroundStyle(.secondary)
57+
Text("FileMint").font(.system(size: 18, weight: .semibold))
58+
Text(model.text(.productTagline)).font(.system(size: 10)).foregroundStyle(.secondary)
4459
}
45-
}.padding(.horizontal, 20).padding(.top, 24).padding(.bottom, 20)
60+
}.padding(.horizontal, 20).padding(.top, 54).padding(.bottom, 28)
4661
ScrollView {
4762
VStack(spacing: 5) {
4863
ForEach(PreferencesModel.Pane.allCases) { pane in
49-
if pane == .general || pane == .fileTools {
50-
Text(model.text(pane == .general ? .basicSettings : .extensions))
51-
.font(.caption).foregroundStyle(.secondary)
64+
if pane == .fileTypes || pane == .fileTools || pane == .general {
65+
Text(pane.groupTitle(model.preferences.language))
66+
.font(.system(size: 10, weight: .medium)).foregroundStyle(.secondary)
5267
.frame(maxWidth: .infinity, alignment: .leading)
53-
.padding(.horizontal, 12).padding(.top, pane == .general ? 0 : 14)
68+
.padding(.horizontal, 12).padding(.top, pane == .fileTypes ? 0 : 20)
5469
.padding(.bottom, 4)
5570
.accessibilityAddTraits(.isHeader)
5671
}
57-
if pane == .about { Divider().padding(.vertical, 8) }
5872
SettingsSidebarButton(title: model.text(pane.title), symbol: pane.symbol,
5973
isSelected: model.selectedPane == pane,
6074
isFocused: focusedPane == pane) {
@@ -95,12 +109,16 @@ struct ContentView: View {
95109
Spacer()
96110
Text("⌘N").foregroundStyle(.secondary)
97111
}.padding(.vertical, 3)
98-
}.keyboardShortcut("n").controlSize(.large)
99-
Divider()
100-
Text(model.text(.sourceAvailable)).font(.caption2).foregroundStyle(.secondary)
101-
Text("FileMint \(updater.currentVersion)").font(.caption2).foregroundStyle(.tertiary)
112+
}.keyboardShortcut("n").buttonStyle(MintButtonStyle())
113+
Button { model.selectedPane = .folders } label: {
114+
HStack(spacing: 6) {
115+
Circle().fill(model.extensionEnabled ? FileMintStyle.accent : Color.secondary).frame(width: 5, height: 5)
116+
Text((model.extensionEnabled ? InterfaceText.enabledFinder : .disabledFinder).text(model.preferences.language))
117+
.font(.system(size: 10)).foregroundStyle(.secondary)
118+
}
119+
}.buttonStyle(.plain)
102120
}.padding(16)
103-
}.frame(width: 208).background(.regularMaterial)
121+
}.frame(width: 202).background(.regularMaterial)
104122
}
105123

106124
@ViewBuilder private var page: some View {
@@ -110,6 +128,7 @@ struct ContentView: View {
110128
case .fileTypes: TypesPane()
111129
case .folders: FoldersPane()
112130
case .fileTools: FileToolsPane()
131+
case .resourceTools: ResourceToolsPane(launchTool: launchResourceTool)
113132
case .about: AboutPane()
114133
}
115134
}
@@ -124,23 +143,22 @@ private struct SettingsSidebarButton: View {
124143
@State private var isHovered = false
125144
@Environment(\.colorScheme) private var colorScheme
126145

127-
private var mint: Color { Color(nsColor: .systemMint) }
146+
private var mint: Color { FileMintStyle.accent }
128147

129148
var body: some View {
130149
Button(action: action) {
131150
HStack(spacing: 10) {
132151
Image(systemName: symbol).font(.system(size: 16, weight: .medium))
133152
.frame(width: 20)
134153
.foregroundStyle(isSelected ? mint : Color.secondary)
135-
Text(title).font(.system(size: 13, weight: isSelected ? .semibold : .regular))
136-
.foregroundStyle(.primary)
154+
Text(title).font(.system(size: 12, weight: isSelected ? .medium : .regular))
155+
.foregroundStyle(isSelected ? FileMintStyle.strong : Color.secondary)
137156
Spacer(minLength: 0)
138157
}
139-
.padding(.horizontal, 12).frame(height: 40)
158+
.padding(.horizontal, 11).frame(height: 36)
140159
.background {
141160
RoundedRectangle(cornerRadius: 8, style: .continuous)
142-
.fill(isSelected ? mint.opacity(colorScheme == .dark ? 0.17 : 0.13)
143-
: Color.primary.opacity(isHovered ? 0.045 : 0))
161+
.fill(isSelected ? FileMintStyle.selection : isHovered ? FileMintStyle.soft : Color.clear)
144162
}
145163
.overlay {
146164
RoundedRectangle(cornerRadius: 8, style: .continuous)
@@ -166,13 +184,33 @@ private struct SidebarFocusEffect: ViewModifier {
166184
}
167185

168186
extension PreferencesModel.Pane {
187+
func groupTitle(_ language: AppLanguage) -> String {
188+
switch self {
189+
case .fileTypes, .creation: InterfaceText.fileCreation.text(language)
190+
case .fileTools, .resourceTools: FileMintStrings.text(.extensions, language: language)
191+
default: InterfaceText.preferences.text(language)
192+
}
193+
}
194+
195+
func subtitleText(_ language: AppLanguage) -> String {
196+
switch self {
197+
case .general: InterfaceText.generalSubtitle.text(language)
198+
case .creation: InterfaceText.creationSubtitle.text(language)
199+
case .fileTypes: InterfaceText.typesSubtitle.text(language)
200+
case .folders: InterfaceText.foldersSubtitle.text(language)
201+
case .fileTools: InterfaceText.filesSubtitle.text(language)
202+
case .resourceTools: InterfaceText.resourceSubtitle.text(language)
203+
case .about: FileMintStrings.text(.productTagline, language: language)
204+
}
205+
}
169206
var title: FileMintTextKey {
170207
switch self {
171208
case .general: .general
172209
case .creation: .creationSettings
173210
case .fileTypes: .templatesAndTypes
174211
case .folders: .finderAndFolders
175212
case .fileTools: .fileTools
213+
case .resourceTools: .resourceTools
176214
case .about: .about
177215
}
178216
}
@@ -184,6 +222,7 @@ extension PreferencesModel.Pane {
184222
case .fileTypes: .fileTypeHint
185223
case .folders: .finderFoldersHint
186224
case .fileTools: .fileToolsHint
225+
case .resourceTools: .resourceToolsHint
187226
case .about: .productTagline
188227
}
189228
}
@@ -195,6 +234,7 @@ extension PreferencesModel.Pane {
195234
case .fileTypes: "doc.on.doc"
196235
case .folders: "folder"
197236
case .fileTools: "wrench.and.screwdriver"
237+
case .resourceTools: "photo.on.rectangle"
198238
case .about: "info.circle"
199239
}
200240
}

‎App/FileMint/DesignSystem.swift‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import AppKit
2+
import SwiftUI
3+
import FileMintCore
4+
5+
enum FileMintStyle {
6+
static func adaptive(_ light: UInt32, _ dark: UInt32) -> NSColor {
7+
NSColor(name: nil) { appearance in
8+
let value = appearance.bestMatch(from: [.aqua, .darkAqua]) == .darkAqua ? dark : light
9+
return NSColor(srgbRed: CGFloat((value >> 16) & 255) / 255,
10+
green: CGFloat((value >> 8) & 255) / 255, blue: CGFloat(value & 255) / 255, alpha: 1)
11+
}
12+
}
13+
static let backgroundNS = adaptive(0xFBFBFA, 0x202221)
14+
static let accentNS = adaptive(0x3A8067, 0x98CBB0)
15+
static let background = Color(nsColor: backgroundNS)
16+
static let surface = Color(nsColor: adaptive(0xFFFFFF, 0x2B302D))
17+
static let soft = Color(nsColor: adaptive(0xF1F3EF, 0x252B27))
18+
static let line = Color(nsColor: adaptive(0xE3E7E1, 0x3A413C))
19+
static let accent = Color(nsColor: accentNS)
20+
static let selection = Color(nsColor: adaptive(0xE1ECE4, 0x354B3E))
21+
static let strong = Color(nsColor: adaptive(0x244D3B, 0xA9D2B6))
22+
static let onStrong = Color(nsColor: adaptive(0xFFFFFF, 0x1C3325))
23+
static let radius: CGFloat = 12
24+
}
25+
26+
struct MintButtonStyle: ButtonStyle {
27+
var primary = false
28+
@Environment(\.isEnabled) private var enabled
29+
func makeBody(configuration: Configuration) -> some View {
30+
configuration.label.font(.system(size: 12, weight: primary ? .medium : .regular))
31+
.padding(.horizontal, 13).padding(.vertical, 8)
32+
.foregroundStyle(primary ? FileMintStyle.onStrong : Color.primary)
33+
.background(primary ? FileMintStyle.strong : FileMintStyle.surface, in: RoundedRectangle(cornerRadius: 7))
34+
.overlay(RoundedRectangle(cornerRadius: 7).strokeBorder(primary ? Color.clear : FileMintStyle.line, lineWidth: 0.7))
35+
.opacity(enabled ? (configuration.isPressed ? 0.75 : 1) : 0.4)
36+
}
37+
}
38+
39+
extension View {
40+
func mintSurface(padding: CGFloat = 17) -> some View {
41+
self.padding(padding).frame(maxWidth: .infinity, alignment: .leading)
42+
.background(FileMintStyle.surface, in: RoundedRectangle(cornerRadius: FileMintStyle.radius))
43+
.overlay(RoundedRectangle(cornerRadius: FileMintStyle.radius).strokeBorder(FileMintStyle.line, lineWidth: 0.7))
44+
}
45+
}
46+
47+
struct PreferenceRow<Control: View>: View {
48+
let title: String
49+
var detail: String? = nil
50+
@ViewBuilder var control: Control
51+
var body: some View {
52+
HStack(spacing: 18) {
53+
VStack(alignment: .leading, spacing: 5) {
54+
Text(title).font(.system(size: 13))
55+
if let detail { Text(detail).font(.system(size: 11)).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true) }
56+
}.frame(maxWidth: .infinity, alignment: .leading)
57+
control
58+
}.padding(.vertical, 2)
59+
}
60+
}
61+
62+
enum InterfaceText {
63+
case fileCreation, preferences, localOnly, useTools, menuSettings, finderTip, preview, original
64+
case parameters, keepOriginal, previewMissing, allImages, outputSize, start, more, chooseImages
65+
case resourceSubtitle, generalSubtitle, creationSubtitle, typesSubtitle, foldersSubtitle, filesSubtitle
66+
case interface, enabledFinder, disabledFinder, selectedImages, textResult, reduceWithoutUpscale
67+
case busy, pixelWidth, pixelHeight, fitting, inFinder, launchHint, menuBarHint, menuEnabled, prepared
68+
func text(_ language: AppLanguage) -> String {
69+
let pair: (String, String) = switch self {
70+
case .fileCreation: ("File Creation", "文件创建")
71+
case .preferences: ("Preferences", "偏好设置")
72+
case .localOnly: ("Processed on your Mac", "只在你的 Mac 上处理")
73+
case .useTools: ("Use Tools", "使用工具")
74+
case .menuSettings: ("Finder Menu Settings", "Finder 菜单设置")
75+
case .finderTip: ("Select images in Finder and choose Resource Tools from the context menu.", "也可以在 Finder 中选中图片,右键选择「资源工具」直接开始。")
76+
case .preview: ("Preview", "预览")
77+
case .original: ("Original", "原图")
78+
case .parameters: ("Options", "处理参数")
79+
case .keepOriginal: ("Originals stay unchanged", "原文件始终保留")
80+
case .previewMissing: ("Preview unavailable", "暂时无法预览")
81+
case .allImages: ("Images", "图片列表")
82+
case .outputSize: ("Output dimensions", "输出尺寸")
83+
case .start: ("Process images", "处理图片")
84+
case .more: ("Details and limits", "更多说明与限制")
85+
case .chooseImages: ("Choose images to process", "选择要处理的图片")
86+
case .resourceSubtitle: ("From selected images to finished work.", "从选中图片,到完成处理。")
87+
case .generalSubtitle: ("Quietly at work, just the way you like.", "按你的习惯,安静地工作。")
88+
case .creationSubtitle: ("A few thoughtful details for every new file.", "照顾每一次新建的小细节。")
89+
case .typesSubtitle: ("Keep your everyday starting points close.", "把常用的起点,留在手边。")
90+
case .foldersSubtitle: ("You decide where FileMint can work.", "你决定 FileMint 可以在哪里工作。")
91+
case .filesSubtitle: ("Just the tools you need in the context menu.", "让右键菜单,恰好够用。")
92+
case .interface: ("Interface", "界面")
93+
case .enabledFinder: ("Finder extension enabled", "Finder 扩展已启用")
94+
case .disabledFinder: ("Set up Finder extension", "设置 Finder 扩展")
95+
case .selectedImages: ("Selected images", "选中的图片")
96+
case .textResult: ("Recognized text", "识别结果")
97+
case .reduceWithoutUpscale: ("Keeps proportions. Never enlarges the original.", "保持比例,不放大原图。")
98+
case .busy: ("Finish or close the current operation first.", "请先完成或关闭当前操作。")
99+
case .pixelWidth: ("Common width (px)", "统一宽度(像素)")
100+
case .pixelHeight: ("Common height (px)", "统一高度(像素)")
101+
case .fitting: ("Centered on a transparent square", "居中适配透明方形")
102+
case .inFinder: ("Show in Finder", "在 Finder 中显示")
103+
case .launchHint: ("Ready for Finder actions after login.", "登录后即可使用 Finder 右键功能。")
104+
case .menuBarHint: ("Quick access to creation and settings.", "随时新建文件,快速打开设置。")
105+
case .menuEnabled: ("Show Resource Tools in Finder", "在 Finder 中显示资源工具")
106+
case .prepared: ("Ready when you are.", "准备好了,随手新建。")
107+
}
108+
return language.resolved() == .chinese ? pair.1 : pair.0
109+
}
110+
}

0 commit comments

Comments
 (0)