Skip to content

Commit 748256f

Browse files
Add manual import for copied App Store links
Ask before adding a copied App Store app, and keep it under Manual Import instead of the installed-app sources.
1 parent 994190b commit 748256f

13 files changed

Lines changed: 710 additions & 32 deletions

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- 支持跟随系统、浅色和深色外观。
1919
- 界面语言支持跟随系统、简体中文和 English,切换后立即生效。
2020
- 支持自建分类、批量管理应用、从右键菜单归类和查看分类成员。
21+
- 复制 App Store 应用链接后回到 AppNotes,可确认导入,并在「手动导入」中与本机应用分开。
2122
- 在顶部菜单栏保留快捷入口,同时在 Dock 显示应用图标。
2223

2324
## 系统要求

‎Resources/en.lproj/Localizable.strings‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"category.system" = "System Apps";
4040
"category.appStore" = "App Store";
4141
"category.downloaded" = "Downloaded";
42+
"category.manual" = "Manual Import";
4243
"library.count" = "%ld apps";
4344
"library.list" = "Applications";
4445
"library.scan" = "Rescan Applications";
@@ -49,6 +50,17 @@
4950
"search.clear" = "Clear Search";
5051
"library.empty" = "No Apps Yet";
5152
"library.empty.help" = "Installed apps will appear here after a scan.";
53+
"import.prompt.title" = "Import This App?";
54+
"import.prompt.message" = "The clipboard has an App Store link for “%@”. It will appear under Manual Import.";
55+
"import.confirm" = "Import";
56+
"import.cancel" = "Not Now";
57+
"import.failed.title" = "Couldn’t Import";
58+
"import.failed.message" = "App Store information couldn’t be loaded. Check your connection, copy the link again, and return to AppNotes.";
59+
"import.remove" = "Remove Import";
60+
"import.empty" = "No Imported Apps";
61+
"import.empty.help" = "Copy an App Store link, then return to AppNotes to import it.";
62+
"import.saveFailed" = "The app couldn’t be saved. Check the available disk space and file permissions, then try again.";
63+
"import.loadFailed" = "Saved imports couldn’t be read. The original file was left unchanged.";
5264
"library.noNotes" = "Your Notes Start Here";
5365
"library.noNotes.help" = "Select an app in All Apps and write your first note.";
5466
"library.browse" = "Browse All Apps";

‎Resources/zh-Hans.lproj/Localizable.strings‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"category.system" = "系统应用";
4040
"category.appStore" = "App Store";
4141
"category.downloaded" = "网络下载";
42+
"category.manual" = "手动导入";
4243
"library.count" = "%ld 个应用";
4344
"library.list" = "应用列表";
4445
"library.scan" = "重新扫描应用";
@@ -49,6 +50,17 @@
4950
"search.clear" = "清除搜索";
5051
"library.empty" = "暂无应用";
5152
"library.empty.help" = "扫描后,已安装的应用会显示在这里。";
53+
"import.prompt.title" = "导入这个应用?";
54+
"import.prompt.message" = "剪贴板中有「%@」的 App Store 链接。导入后,它会出现在「手动导入」里。";
55+
"import.confirm" = "导入";
56+
"import.cancel" = "暂不";
57+
"import.failed.title" = "无法导入";
58+
"import.failed.message" = "暂时无法获取这个 App Store 应用的信息。请检查网络,重新复制链接后再回到 AppNotes。";
59+
"import.remove" = "移除导入";
60+
"import.empty" = "还没有手动导入的应用";
61+
"import.empty.help" = "在 App Store 复制应用链接,回到 AppNotes 后可以选择导入。";
62+
"import.saveFailed" = "应用未能保存。请检查磁盘空间和文件权限后重试。";
63+
"import.loadFailed" = "无法读取已保存的手动导入应用,原文件已保留。";
5264
"library.noNotes" = "从第一条备注开始";
5365
"library.noNotes.help" = "在「所有应用」中选择一个应用,记下它的用途。";
5466
"library.browse" = "浏览所有应用";

‎Sources/Components.swift‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,28 @@ struct AppIcon: View {
3838
let app: AppEntry
3939
let size: CGFloat
4040
var body: some View {
41-
Image(nsImage: IconCache.icon(for: app.path))
42-
.resizable().interpolation(.high).frame(width: size, height: size)
41+
artwork
42+
.frame(width: size, height: size)
4343
.accessibilityHidden(true)
4444
}
45+
46+
@ViewBuilder private var artwork: some View {
47+
if app.origin == .manual, let url = URL.web(app.artworkURL) {
48+
AsyncImage(url: url) { phase in
49+
switch phase {
50+
case .success(let image):
51+
image.resizable().interpolation(.high)
52+
default:
53+
Image(systemName: "app.fill")
54+
.font(.system(size: size * 0.62))
55+
.foregroundStyle(.secondary)
56+
.frame(width: size, height: size)
57+
}
58+
}
59+
} else {
60+
Image(nsImage: IconCache.icon(for: app.path)).resizable().interpolation(.high)
61+
}
62+
}
4563
}
4664

4765
struct IconButtonChrome: ViewModifier {
@@ -279,6 +297,16 @@ extension AppEntry {
279297
|| (bundleID ?? "").localizedCaseInsensitiveContains(query)
280298
|| note.localizedCaseInsensitiveContains(query)
281299
}
282-
func open() { NSWorkspace.shared.open(URL(fileURLWithPath: path)) }
283-
func reveal() { NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: path)]) }
300+
func open() {
301+
if origin == .manual, let id = appStoreID,
302+
let url = URL(string: "https://apps.apple.com/\(storeCountryCode)/app/id\(id)") {
303+
NSWorkspace.shared.open(url)
304+
return
305+
}
306+
NSWorkspace.shared.open(URL(fileURLWithPath: path))
307+
}
308+
func reveal() {
309+
guard origin != .manual else { return }
310+
NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: path)])
311+
}
284312
}

‎Sources/DetailView.swift‎

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ struct DetailView: View {
1010
@ObservedObject var suggestionStore = SuggestionStore.shared
1111
@ObservedObject var detailsStore = AppDetailsStore.shared
1212
@ObservedObject var categoryStore = CustomCategoryStore.shared
13+
@ObservedObject var imports = ManualImportStore.shared
14+
@ObservedObject var library = AppLibrary.shared
1315
var onCreateCategory: () -> Void = {}
1416
@State private var tab = "overview"
1517
@State private var local = LocalAppDetails()
@@ -84,15 +86,13 @@ struct DetailView: View {
8486
}
8587
ViewThatFits(in: .horizontal) {
8688
HStack(spacing: 8) {
87-
openButton
88-
if let details { Link(preferences.text("info.appStore"), destination: details.storeURL) }
89-
Button(preferences.text("detail.reveal"), action: app.reveal)
89+
if app.origin != .manual { openButton }
90+
headerActions
9091
}
9192
HStack(spacing: 8) {
92-
openButton
93+
if app.origin != .manual { openButton }
9394
Menu {
94-
if let details { Link(preferences.text("info.appStore"), destination: details.storeURL) }
95-
Button(preferences.text("detail.reveal"), action: app.reveal)
95+
headerActions
9696
} label: {
9797
Label(preferences.text("info.more"), systemImage: "ellipsis")
9898
}
@@ -111,6 +111,29 @@ struct DetailView: View {
111111
.padding(24)
112112
}
113113

114+
@ViewBuilder private var headerActions: some View {
115+
if let destination = storeDestination {
116+
Link(preferences.text(app.origin == .manual ? "info.viewStore" : "info.appStore"), destination: destination)
117+
}
118+
if app.origin == .manual {
119+
Button(preferences.text("import.remove"), action: removeImport)
120+
} else {
121+
Button(preferences.text("detail.reveal"), action: app.reveal)
122+
}
123+
}
124+
125+
private var storeDestination: URL? {
126+
if let details { return details.storeURL }
127+
guard app.origin == .manual, let id = app.appStoreID else { return nil }
128+
return URL(string: "https://apps.apple.com/\(app.storeCountryCode)/app/id\(id)")
129+
}
130+
131+
private func removeImport() {
132+
guard let id = app.appStoreID else { return }
133+
imports.remove(id)
134+
library.reloadImports()
135+
}
136+
114137
private var openButton: some View {
115138
Button(action: app.open) {
116139
Label(preferences.text("detail.open"), systemImage: "arrow.up.forward")
@@ -180,6 +203,10 @@ struct DetailView: View {
180203
.help(preferences.text("info.fetchedAt"))
181204
}
182205
.transition(.opacity)
206+
} else if app.origin == .manual && !loading {
207+
Label(preferences.text("category.manual"), systemImage: "square.and.arrow.down")
208+
.font(.caption).foregroundStyle(.secondary)
209+
.transition(.opacity)
183210
} else {
184211
Label(preferences.text(loading ? "info.loading" : "info.localSource"),
185212
systemImage: loading ? "arrow.triangle.2.circlepath" : "desktopcomputer")
@@ -404,7 +431,11 @@ struct AppInformationCard: View {
404431
}
405432
add("info.appID", (listing?.trackId ?? app.appStoreID).map(String.init))
406433
add("detail.bundle", app.bundleID ?? listing?.bundleId)
407-
add("info.installedVersion", app.version)
434+
if app.origin == .manual {
435+
if listing?.version == nil { add("info.storeVersion", app.version) }
436+
} else {
437+
add("info.installedVersion", app.version)
438+
}
408439
add("info.storeVersion", listing?.version)
409440
add("info.price", price)
410441
if let size = listing?.fileSizeBytes.flatMap(Int64.init), size >= 0 {
@@ -450,9 +481,12 @@ struct AppInformationCard: View {
450481
}
451482

452483
private var copyText: String {
453-
(values.map { preferences.text($0.key) + ": " + $0.value }
454-
+ requirements.map { $0.platform + ": " + $0.text }
455-
+ [preferences.text("detail.location") + ": " + app.path]).joined(separator: "\n")
484+
var lines = values.map { preferences.text($0.key) + ": " + $0.value }
485+
+ requirements.map { $0.platform + ": " + $0.text }
486+
if app.origin != .manual {
487+
lines.append(preferences.text("detail.location") + ": " + app.path)
488+
}
489+
return lines.joined(separator: "\n")
456490
}
457491

458492
var body: some View {
@@ -462,7 +496,9 @@ struct AppInformationCard: View {
462496
VStack(spacing: 0) {
463497
ForEach(values) { item in
464498
infoRow(preferences.text(item.key), value: item.value)
465-
Divider().opacity(0.65)
499+
if item.id != values.last?.id || hasInformationFooter {
500+
Divider().opacity(0.65)
501+
}
466502
}
467503
if !requirements.isEmpty {
468504
VStack(alignment: .leading, spacing: 12) {
@@ -476,17 +512,25 @@ struct AppInformationCard: View {
476512
}
477513
}
478514
.frame(maxWidth: .infinity, alignment: .leading).padding(.vertical, 13)
479-
Divider().opacity(0.65)
515+
if app.origin != .manual || (local.copyright?.isEmpty == false) {
516+
Divider().opacity(0.65)
517+
}
518+
}
519+
if app.origin != .manual {
520+
infoRow(preferences.text("detail.location"), value: app.path)
480521
}
481-
infoRow(preferences.text("detail.location"), value: app.path)
482522
if let copyright = local.copyright, !copyright.isEmpty {
483-
Divider().opacity(0.65)
523+
if app.origin != .manual { Divider().opacity(0.65) }
484524
infoRow(preferences.text("info.copyright"), value: copyright)
485525
}
486526
}
487527
}
488528
}
489529

530+
private var hasInformationFooter: Bool {
531+
!requirements.isEmpty || app.origin != .manual || local.copyright?.isEmpty == false
532+
}
533+
490534
private func infoRow(_ title: String, value: String) -> some View {
491535
HStack(alignment: .firstTextBaseline, spacing: 16) {
492536
Text(title).foregroundStyle(.secondary).frame(width: 108, alignment: .leading)

0 commit comments

Comments
 (0)