Skip to content

Commit

Permalink
feat: export app object.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Dec 11, 2024
1 parent beb70b9 commit 6956830
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
3 changes: 2 additions & 1 deletion Example/Example/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ struct ContentView: View {
List {
ForEach(MyAppList.apps(), id: \.appId) { app in
Button(app.name, action: {
MyAppList.openApp(appId: app.appId, appstoreId: app.appstoreId)
app.openApp()
//MyAppList.openApp(appId: app.appId, appstoreId: app.appstoreId)
})
}
}
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import MyAppListKit
List {
ForEach(MyAppList.apps(), id: \.appId) { app in
Button(app.name, action: {
app.openApp()
// or
MyAppList.openApp(appId: app.appId, appstoreId: app.appstoreId)
})
}
Expand All @@ -37,6 +39,11 @@ Button("More Apps by Me") {
// or
MyAppList.openAppsByMe()
}

MyAppList.appDevHub // -> AppData
MyAppList.appDevHub.storeURL // -> URL: macappstore://apps.apple.com/app/id6476452351
MyAppList.appDevHub.openURL() // Open in browser
MyAppList.appDevHub.openApp() // Open the app or its store download page
```

## License
Expand Down
62 changes: 44 additions & 18 deletions Sources/MyAppListKit/MyAppListKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,52 @@ public struct MyAppList {
/// 两个平台都支持
case both
}
public var storeURL: URL {
#if os(macOS)
return URL(string: "macappstore://apps.apple.com/app/id\(appstoreId)")!
#endif
#if os(iOS)
return URL(string: "itms-apps://apps.apple.com/app/id\(appstoreId)")!
#endif
}
public func openURL() {
MyAppList.openURL(url: self.storeURL)
}
public func openApp() {
MyAppList.openApp(appId: appId, appstoreId: appstoreId)
}
}
public static let appDevTutor = AppData(name: "DevTutor for SwiftUI", appId: "com.wangchujiang.SwiftTutorial", appstoreId: "6471227008", platform: .both)
public static let appDevHub = AppData(name: "DevHub", appId: "com.wangchujiang.DevHub", appstoreId: "6476452351", platform: .macOS)
public static let appRightMenuMaster = AppData(name: "RightMenu Master", appId: "com.wangchujiang.rightmenu-master", appstoreId: "6737160756", platform: .macOS)
public static let appCopybookGenerator = AppData(name: "Copybook Generator", appId: "com.wangchujiang.copybook-generator", appstoreId: "6503953628", platform: .macOS)
public static let appCreateCustomSymbols = AppData(name: "Create Custom Symbols", appId: "com.wangchujiang.CreateCustomSymbols", appstoreId: "6476924627", platform: .macOS)
public static let appWebServe = AppData(name: "Web Serve", appId: "com.wangchujiang.serve", appstoreId: "6670167443", platform: .macOS)
public static let appQuickRSS = AppData(name: "Quick RSS", appId: "com.wangchujiang.QuickRSS", appstoreId: "6670696072", platform: .both)
public static let appPasteQuick = AppData(name: "PasteQuick", appId: "com.wangchujiang.paste-quick", appstoreId: "6723903021", platform: .macOS)
public static let appRegexMate = AppData(name: "RegexMate", appId: "com.wangchujiang.RegexMate", appstoreId: "6479819388", platform: .both)
public static let appIconizeFolder = AppData(name: "Iconize Folder", appId: "com.wangchujiang.IconizeFolder", appstoreId: "6478772538", platform: .macOS)
public static let appSymbolScribe = AppData(name: "Symbol Scribe", appId: "com.wangchujiang.SymbolScribe", appstoreId: "6470879005", platform: .macOS)
public static let appPaletteGenius = AppData(name: "Palette Genius", appId: "com.wangchujiang.PaletteGenius", appstoreId: "6472593276", platform: .macOS)
public static let appResumeRevise = AppData(name: "Resume Revise", appId: "com.wangchujiang.ResumeRevise", appstoreId: "6476400184", platform: .macOS)
public static let appTimePassage = AppData(name: "Time Passage", appId: "com.wangchujiang.LifeCountdownTime", appstoreId: "6479194014", platform: .both)
public static let appTextSoundSaver = AppData(name: "TextSound Saver", appId: "com.wangchujiang.TextSoundSaver", appstoreId: "6478511402", platform: .both)
public static let allApps: [AppData] = [
AppData(name: "DevTutor for SwiftUI", appId: "com.wangchujiang.SwiftTutorial", appstoreId: "6471227008", platform: .both),
AppData(name: "DevHub", appId: "com.wangchujiang.DevHub", appstoreId: "6476452351", platform: .macOS),
AppData(name: "RightMenu Master", appId: "com.wangchujiang.rightmenu-master", appstoreId: "6737160756", platform: .macOS),
AppData(name: "Copybook Generator", appId: "com.wangchujiang.copybook-generator", appstoreId: "6503953628", platform: .macOS),
AppData(name: "Create Custom Symbols", appId: "com.wangchujiang.CreateCustomSymbols", appstoreId: "6476924627", platform: .macOS),
AppData(name: "Web Serve", appId: "com.wangchujiang.serve", appstoreId: "6670167443", platform: .macOS),
AppData(name: "Quick RSS", appId: "com.wangchujiang.QuickRSS", appstoreId: "6670696072", platform: .both),
AppData(name: "PasteQuick", appId: "com.wangchujiang.paste-quick", appstoreId: "6723903021", platform: .macOS),
AppData(name: "RegexMate", appId: "com.wangchujiang.RegexMate", appstoreId: "6479819388", platform: .both),
AppData(name: "Iconize Folder", appId: "com.wangchujiang.IconizeFolder", appstoreId: "6478772538", platform: .macOS),
AppData(name: "Symbol Scribe", appId: "com.wangchujiang.SymbolScribe", appstoreId: "6470879005", platform: .macOS),
AppData(name: "Palette Genius", appId: "com.wangchujiang.PaletteGenius", appstoreId: "6472593276", platform: .macOS),
AppData(name: "Resume Revise", appId: "com.wangchujiang.ResumeRevise", appstoreId: "6476400184", platform: .macOS),
AppData(name: "Time Passage", appId: "com.wangchujiang.LifeCountdownTime", appstoreId: "6479194014", platform: .both),
AppData(name: "TextSound Saver", appId: "com.wangchujiang.TextSoundSaver", appstoreId: "6478511402", platform: .both),
appDevTutor,
appDevHub,
appRightMenuMaster,
appCopybookGenerator,
appCreateCustomSymbols,
appWebServe,
appQuickRSS,
appPasteQuick,
appRegexMate,
appIconizeFolder,
appSymbolScribe,
appPaletteGenius,
appResumeRevise,
appTimePassage,
appTextSoundSaver,
]

public static let bundleIdentifier: String = Bundle.main.bundleIdentifier!
Expand Down Expand Up @@ -121,6 +150,3 @@ public struct MyAppList {
#endif
}
}



0 comments on commit 6956830

Please sign in to comment.