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

Set Application Category Type #1087

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions PlayCover/AppInstaller/Installer.swift
Expand Up @@ -40,6 +40,7 @@ class Installer {
// If (the option key is held or the install playtools popup settings is true) and its not an export,
// then show the installer dialog
let installPlayTools: Bool
let applicationType = InstallPreferences.shared.defaultAppType

if (Installer.isOptionKeyHeld || InstallPreferences.shared.showInstallPopup) && !export {
installPlayTools = installPlayToolsPopup()
Expand Down Expand Up @@ -81,6 +82,8 @@ class Installer {
try PlayTools.installInIPA(app.executable)
}

app.info.applicationCategoryType = applicationType

if !export {
// -rwxr-xr-x
try app.executable.setBinaryPosixPermissions(0o755)
Expand Down
49 changes: 49 additions & 0 deletions PlayCover/Model/AppInfo.swift
Expand Up @@ -5,6 +5,35 @@

import Foundation

enum LSApplicationCategoryType: String, CaseIterable {
case business = "public.app-category.business"
case developerTools = "public.app-category.developer-tools"
case education = "public.app-category.education"
case entertainment = "public.app-category.entertainment"
case finance = "public.app-category.finance"
case games = "public.app-category.games"
case graphicsDesign = "public.app-category.graphics-design"
case healthcareFitness = "public.app-category.healthcare-fitness"
case lifestyle = "public.app-category.lifestyle"
case medical = "public.app-category.medical"
case music = "public.app-category.music"
case news = "public.app-category.news"
case photography = "public.app-category.photography"
case productivity = "public.app-category.productivity"
case reference = "public.app-category.reference"
case socialNetworking = "public.app-category.social-networking"
case sports = "public.app-category.sports"
case travel = "public.app-category.travel"
case utilities = "public.app-category.utilities"
case video = "public.app-category.video"
case weather = "public.app-category.weather"
case none = "public.app-category.none" // Note: This is not in an official category type

var localizedName: String {
NSLocalizedString(rawValue, comment: "")
}
}

public class AppInfo {
public let url: URL
fileprivate var rawStorage: NSMutableDictionary
Expand Down Expand Up @@ -122,6 +151,26 @@ public class AppInfo {
}
}

var applicationCategoryType: LSApplicationCategoryType {
get {
LSApplicationCategoryType(
rawValue: self[string: "LSApplicationCategoryType"] ?? ""
) ?? LSApplicationCategoryType.none
}
set {
if newValue == .none {
rawStorage.removeObject(forKey: "LSApplicationCategoryType")
} else {
self[string: "LSApplicationCategoryType"] = newValue.rawValue
}
do {
try write()
} catch {
Log.shared.error(error)
}
}
}

var minimumOSVersion: String {
get {
self[string: "MinimumOSVersion"] ?? ""
Expand Down
35 changes: 34 additions & 1 deletion PlayCover/Views/AppSettingsView.swift
Expand Up @@ -90,7 +90,8 @@ struct AppSettingsView: View {
closeView: $closeView,
hasPlayTools: $hasPlayTools,
hasAlias: $hasAlias,
app: viewModel.app)
app: viewModel.app,
applicationCategoryType: viewModel.app.info.applicationCategoryType)
.tabItem {
Text("settings.tab.misc")
}
Expand Down Expand Up @@ -481,9 +482,34 @@ struct MiscView: View {

var app: PlayApp

@State var applicationCategoryType: LSApplicationCategoryType

var body: some View {
ScrollView {
VStack {
HStack {
Text("settings.applicationCategoryType")
Spacer()
Picker("", selection: $applicationCategoryType) {
ForEach(LSApplicationCategoryType.allCases, id: \.rawValue) { value in
Text(value.localizedName)
.tag(value)
}
}
.frame(width: 225)
.onChange(of: applicationCategoryType) { _ in
app.info.applicationCategoryType = applicationCategoryType
Task(priority: .userInitiated) {
JoseMoreville marked this conversation as resolved.
Show resolved Hide resolved
do {
try Shell.signApp(app.executable)
} catch {
Log.shared.error(error)
}
}
}
}
Spacer()
.frame(height: 20)
HStack {
Toggle("settings.toggle.discord", isOn: $settings.settings.discordActivity.enable)
Spacer()
Expand Down Expand Up @@ -579,6 +605,8 @@ struct MiscView: View {
}
}
}
Spacer()
.frame(height: 20)
// swiftlint:disable:next todo
// TODO: Test and remove before 3.0 release
HStack {
Expand Down Expand Up @@ -627,6 +655,11 @@ struct InfoView: View {
Spacer()
Text("\(info.bundleVersion)")
}
HStack {
Text("settings.applicationCategoryType") + Text(":")
Spacer()
Text("\(info.applicationCategoryType.rawValue)")
}
HStack {
Text("settings.info.executableName")
Spacer()
Expand Down
32 changes: 25 additions & 7 deletions PlayCover/Views/Settings/InstallSettings.swift
Expand Up @@ -12,6 +12,8 @@ class InstallPreferences: NSObject, ObservableObject {

@objc @AppStorage("AlwaysInstallPlayTools") var alwaysInstallPlayTools = true

@AppStorage("DefaultAppType") var defaultAppType: LSApplicationCategoryType = .none

@AppStorage("ShowInstallPopup") var showInstallPopup = false
}

Expand All @@ -21,20 +23,36 @@ struct InstallSettings: View {
@ObservedObject var installPreferences = InstallPreferences.shared

var body: some View {
Form {
VStack(alignment: .leading) {
HStack {
Text("settings.applicationCategoryType")
Spacer()
Picker("", selection: installPreferences.$defaultAppType) {
ForEach(LSApplicationCategoryType.allCases, id: \.rawValue) { value in
Text(value.localizedName)
.tag(value)
}
}
.frame(width: 225)
}
Spacer()
.frame(height: 20)
Toggle("preferences.toggle.showInstallPopup", isOn: $installPreferences.showInstallPopup)
GroupBox {
HStack {
VStack(alignment: .leading) {
Toggle("preferences.toggle.alwaysInstallPlayTools",
isOn: $installPreferences.alwaysInstallPlayTools)
VStack {
HStack {
VStack(alignment: .leading) {
Toggle("preferences.toggle.alwaysInstallPlayTools",
isOn: $installPreferences.alwaysInstallPlayTools)
}
Spacer()
}
Spacer()
.frame(height: 20)
}
}.disabled(installPreferences.showInstallPopup)
Spacer()
}
.padding(20)
.frame(width: 350, height: 100, alignment: .center)
.frame(width: 400, height: 200)
}
}
1 change: 1 addition & 0 deletions PlayCover/en.lproj/Localizable.strings
Expand Up @@ -192,6 +192,7 @@
"settings.toggle.introspection" = "Insert Introspection libraries";
"settings.toggle.introspection.help" = "Add the system introspection libraries to the app. Known to fix issues with some apps not starting correctly";

"settings.applicationCategoryType" = "Application Type";
"settings.removePlayTools" = "Remove PlayTools";
"settings.addToLaunchpad" = "Add to Launchpad";
"settings.removeFromLaunchpad" = "Remove from Launchpad";
Expand Down