Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

iOS: AppIcon plugin (alternate icon sets incl. AppIcon-Halloween in ASSETCATALOG_COMPILER_ALTERNATE_APPICON_NAMES)

Duarte Santosb8c7c16242cc
diff --git a/frontend/ios/App/App.xcodeproj/project.pbxproj b/frontend/ios/App/App.xcodeproj/project.pbxproj
index 9ea68bcde..75fd11c22 100644
--- a/frontend/ios/App/App.xcodeproj/project.pbxproj
+++ b/frontend/ios/App/App.xcodeproj/project.pbxproj
@@ -17,6 +17,7 @@
50B271D11FEDC1A000F3C39B /* public in Resources */ = {isa = PBXBuildFile; fileRef = 50B271D01FEDC1A000F3C39B /* public */; };
A084ECDBA7D38E1E42DFC39D /* Pods_App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AF277DCFFFF123FFC6DF26C7 /* Pods_App.framework */; };
AA0100000000000000000002 /* PrintPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA0100000000000000000001 /* PrintPlugin.swift */; };
+ AA0900000000000000000002 /* AppIconPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA0900000000000000000001 /* AppIconPlugin.swift */; };
AA0200000000000000000002 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA0200000000000000000001 /* MainViewController.swift */; };
AA0200000000000000000004 /* RestAlertPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA0200000000000000000003 /* RestAlertPlugin.swift */; };
AA0200000000000000000006 /* RestTone.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA0200000000000000000005 /* RestTone.swift */; };
@@ -43,6 +44,7 @@
504EC3041FED79650016851F /* App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = App.app; sourceTree = BUILT_PRODUCTS_DIR; };
504EC3071FED79650016851F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
AA0000000000000000000001 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
+ AA0900000000000000000001 /* AppIconPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppIconPlugin.swift; sourceTree = "<group>"; };
AA0100000000000000000001 /* PrintPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrintPlugin.swift; sourceTree = "<group>"; };
504EC30C1FED79650016851F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
504EC30E1FED79650016851F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -118,6 +120,7 @@
504EC3071FED79650016851F /* AppDelegate.swift */,
AA0000000000000000000001 /* SceneDelegate.swift */,
AA0100000000000000000001 /* PrintPlugin.swift */,
+ AA0900000000000000000001 /* AppIconPlugin.swift */,
AA0200000000000000000001 /* MainViewController.swift */,
AA0200000000000000000003 /* RestAlertPlugin.swift */,
AA0200000000000000000005 /* RestTone.swift */,
@@ -275,6 +278,7 @@
504EC3081FED79650016851F /* AppDelegate.swift in Sources */,
AA0000000000000000000002 /* SceneDelegate.swift in Sources */,
AA0100000000000000000002 /* PrintPlugin.swift in Sources */,
+ AA0900000000000000000002 /* AppIconPlugin.swift in Sources */,
AA0200000000000000000002 /* MainViewController.swift in Sources */,
AA0200000000000000000004 /* RestAlertPlugin.swift in Sources */,
AA0200000000000000000006 /* RestTone.swift in Sources */,
@@ -428,6 +432,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = FC68EB0AF532CFC21C3344DD /* Pods-App.debug.xcconfig */;
buildSettings = {
+ ASSETCATALOG_COMPILER_ALTERNATE_APPICON_NAMES = "AppIcon-Light AppIcon-Mono AppIcon-Neon AppIcon-Sky AppIcon-Orange AppIcon-Pink AppIcon-Violet AppIcon-Halloween";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_STYLE = Automatic;
@@ -456,6 +461,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = AF51FD2D460BCFE21FA515B2 /* Pods-App.release.xcconfig */;
buildSettings = {
+ ASSETCATALOG_COMPILER_ALTERNATE_APPICON_NAMES = "AppIcon-Light AppIcon-Mono AppIcon-Neon AppIcon-Sky AppIcon-Orange AppIcon-Pink AppIcon-Violet AppIcon-Halloween";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_STYLE = Automatic;
diff --git a/frontend/ios/App/App/AppIconPlugin.swift b/frontend/ios/App/App/AppIconPlugin.swift
new file mode 100644
index 000000000..6c20e9a44
--- /dev/null
+++ b/frontend/ios/App/App/AppIconPlugin.swift
@@ -0,0 +1,82 @@
+import Foundation
+import Capacitor
+import UIKit
+
+/**
+ * The home-screen icon (Settings → Look & Home → App icon, lib/app-icon.js). The alternate icons
+ * are AppIcon sets in Assets.xcassets, named in ASSETCATALOG_COMPILER_ALTERNATE_APPICON_NAMES so
+ * the asset compiler writes their sizes and CFBundleAlternateIcons into the built Info.plist. The
+ * ids and set names are the ones in src/lib/app-icon-variants.js (scripts/app-icons.mjs).
+ *
+ * iOS confirms the switch with its own alert ("You have changed the icon for openGym"); an app
+ * cannot leave it out.
+ *
+ * Usage from JS:
+ * const AppIcon = registerPlugin('AppIcon')
+ * await AppIcon.getIcon() // { supported: true, name: 'default' }
+ * await AppIcon.setIcon({ name: 'sky' }) // { name: 'sky' }
+ */
+@objc(AppIconPlugin)
+public class AppIconPlugin: CAPPlugin, CAPBridgedPlugin {
+ public let identifier = "AppIconPlugin"
+ public let jsName = "AppIcon"
+ public let pluginMethods: [CAPPluginMethod] = [
+ CAPPluginMethod(name: "getIcon", returnType: CAPPluginReturnPromise),
+ CAPPluginMethod(name: "setIcon", returnType: CAPPluginReturnPromise),
+ ]
+
+ /// Icon id → alternate icon name; the original is the primary icon (nil).
+ static let icons: [String: String] = [
+ "light": "AppIcon-Light",
+ "mono": "AppIcon-Mono",
+ "neon": "AppIcon-Neon",
+ "sky": "AppIcon-Sky",
+ "orange": "AppIcon-Orange",
+ "pink": "AppIcon-Pink",
+ "violet": "AppIcon-Violet",
+ "halloween": "AppIcon-Halloween",
+ ]
+
+ static func id(for iconName: String?) -> String {
+ guard let iconName = iconName else { return "default" }
+ return icons.first(where: { $0.value == iconName })?.key ?? "default"
+ }
+
+ @objc func getIcon(_ call: CAPPluginCall) {
+ // UIApplication is main-thread only; plugin calls arrive on a background queue.
+ DispatchQueue.main.async {
+ let app = UIApplication.shared
+ call.resolve([
+ "supported": app.supportsAlternateIcons,
+ "name": AppIconPlugin.id(for: app.alternateIconName),
+ ])
+ }
+ }
+
+ @objc func setIcon(_ call: CAPPluginCall) {
+ guard let name = call.getString("name"), name == "default" || AppIconPlugin.icons[name] != nil else {
+ call.reject("unknown icon")
+ return
+ }
+ let target = name == "default" ? nil : AppIconPlugin.icons[name]
+ DispatchQueue.main.async {
+ let app = UIApplication.shared
+ guard app.supportsAlternateIcons else {
+ call.reject("alternate icons are not supported")
+ return
+ }
+ // Setting the icon already in use would still show the system alert.
+ if app.alternateIconName == target {
+ call.resolve(["name": name])
+ return
+ }
+ app.setAlternateIconName(target) { error in
+ if let error = error {
+ call.reject(error.localizedDescription)
+ } else {
+ call.resolve(["name": name])
+ }
+ }
+ }
+ }
+}
diff --git a/frontend/ios/App/App/MainViewController.swift b/frontend/ios/App/App/MainViewController.swift
index c37a3b27b..ea6592bff 100644
--- a/frontend/ios/App/App/MainViewController.swift
+++ b/frontend/ios/App/App/MainViewController.swift
@@ -29,6 +29,7 @@ class MainViewController: CAPBridgeViewController {
bridge?.registerPluginInstance(AppleHealthPlugin())
bridge?.registerPluginInstance(WidgetBridgePlugin())
bridge?.registerPluginInstance(LiveActivityPlugin())
+ bridge?.registerPluginInstance(AppIconPlugin())
WidgetPreview.runIfAsked()
// After loadView has finished: the view is the web view only once it has.
if ProcessInfo.processInfo.arguments.contains(MainViewController.pendingProbeArgument) {