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

Remove AppConstants #24294

Merged
merged 19 commits into from
Mar 24, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Modules/Sources/BuildSettingsKit/BuildSettings+Live.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ extension BuildSettings {
itunesAppID = bundle.infoValue(forKey: "WPItunesAppID")
appURLScheme = bundle.infoValue(forKey: "WPAppURLScheme")
jetpackAppURLScheme = bundle.infoValue(forKey: "WPJetpackAppURLScheme")
about = ProductAboutDetails(
twitterHandle: bundle.infoValue(forKey: "WPProductTwitterHandle"),
twitterURL: bundle.urlValue(forKey: "WPProductTwitterURL"),
blogURL: bundle.urlValue(forKey: "WPProductBlogURL")
)
zendeskSourcePlatform = bundle.infoValue(forKey: "WPZendeskSourcePlatform")
mobileAnnounceAppID = bundle.infoValue(forKey: "WPMobileAnnounceAppID")
authKeychainServiceName = bundle.infoValue(forKey: "WPAuthKeychainServiceName")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these are just hard-coded values which don't have anything to do with build configurations. Maybe we can just have some readonly variables or something? I don't think all these values need to be in the Info.plist files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these are just hard-coded values which don't have anything to do with build configurations

True. However, they do change from WordPress and Jetpack. Maybe we could derive them from brand/WPAppBrand. But then we'd have sort of two places where to place the values: Info.plist and the code switch brand { case ... here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two places where to place the values: Info.plist and the code switch brand { case ... here.

💯. The idea is to specify configuration in data: Info.plist and .xcconfig. It's not always feasible, but you generally shouldn't have to search the codebase to find these values – it should be in configuration files, in data. I used switch brand sparingly.

There are multiple advantages to storing these values in data and not code: easier to find, can be modified without recompiling the app, easier to edit with scripts if needed.

}
}

Expand All @@ -32,6 +40,11 @@ private extension Bundle {
fatalError("unexpected value: \(object) for key: \(key)")
}
}

func urlValue(forKey key: String) -> URL {
let urlWithoutScheme: String = infoValue(forKey: key)
return URL(string: "https://\(urlWithoutScheme)")!
}
}

private extension Bundle {
Expand Down
10 changes: 9 additions & 1 deletion Modules/Sources/BuildSettingsKit/BuildSettings+Preview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ extension BuildSettings {
explatPlatform: "xcpreview",
itunesAppID: "1234567890",
appURLScheme: "xcpreview",
jetpackAppURLScheme: "jetpack"
jetpackAppURLScheme: "jetpack",
about: ProductAboutDetails(
twitterHandle: "@wordpress",
twitterURL: URL(string: "www.example.com")!,
blogURL: URL(string: "www.example.com")!
),
zendeskSourcePlatform: "zen",
mobileAnnounceAppID: "1234567890",
authKeychainServiceName: "public-api.wordpress.com"
)
}

Expand Down
10 changes: 10 additions & 0 deletions Modules/Sources/BuildSettingsKit/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ public struct BuildSettings: Sendable {
public var itunesAppID: String
public var appURLScheme: String
public var jetpackAppURLScheme: String
public var about: ProductAboutDetails
public var zendeskSourcePlatform: String
public var mobileAnnounceAppID: String
public var authKeychainServiceName: String

public struct ProductAboutDetails: Sendable {
public var twitterHandle: String
public var twitterURL: URL
public var blogURL: URL
}

public static var current: BuildSettings {
switch BuildSettingsEnvironment.current {
Expand Down
5 changes: 5 additions & 0 deletions WordPress/Classes/Models/WPAccount+AccountSettings.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import BuildSettingsKit

extension WPAccount {
enum VerificationStatus: String {
Expand Down Expand Up @@ -33,4 +34,8 @@ extension WPAccount {
var needsEmailVerification: Bool {
return verificationStatus == .unverified
}

@objc class var authKeychainServiceName: String {
BuildSettings.current.authKeychainServiceName
}
}
5 changes: 0 additions & 5 deletions WordPress/Classes/Models/WPAccount.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,4 @@ + (void)migrateAuthKeyForUsername:(NSString *)username
});
}

+ (NSString *)authKeychainServiceName
{
return [AppConstants authKeychainServiceName];
}

@end
3 changes: 2 additions & 1 deletion WordPress/Classes/Services/CredentialsService.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import BuildSettingsKit
import SFHFKeychainUtils

protocol CredentialsProvider {
Expand All @@ -18,6 +19,6 @@ class CredentialsService {
}

func getOAuthToken(site: JetpackSiteRef) -> String? {
return provider.getPassword(username: site.username, service: AppConstants.authKeychainServiceName)
return provider.getPassword(username: site.username, service: BuildSettings.current.authKeychainServiceName)
}
}
2 changes: 1 addition & 1 deletion WordPress/Classes/Utility/KeychainTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class KeychainTools: NSObject {
static fileprivate func serviceForItem(_ item: String) -> String? {
switch item {
case "wordpress.com":
return AppConstants.authKeychainServiceName
return BuildSettings.current.authKeychainServiceName
case "*", "all":
return nil
default:
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Utility/ZendeskUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ private extension ZendeskUtils {
static let profileNameKey = "name"
static let userDefaultsZendeskUnreadNotifications = "wp_zendesk_unread_notifications"
static let nameFieldCharacterLimit = 50
static let sourcePlatform = AppConstants.zendeskSourcePlatform
static var sourcePlatform = BuildSettings.current.zendeskSourcePlatform
static let gutenbergIsDefault = "mobile_gutenberg_is_default"
static let mobileSelfHosted = "selected_site_self_hosted"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import UIKit
import BuildSettingsKit
import WordPressUI
import UIKit
import WordPressKit
import WordPressShared
import AutomatticAbout
import SwiftUI
Expand Down Expand Up @@ -43,13 +43,13 @@ class AppAboutScreenConfiguration: AboutScreenConfiguration {
}),
AboutItem(title: TextContent.share, action: { [weak self] context in
self?.tracker.buttonPressed(.share)
self?.sharePresenter.present(for: AppConstants.shareAppName, in: context.viewController, source: .about, sourceView: context.sourceView)
self?.sharePresenter.present(for: BuildSettings.current.shareAppName, in: context.viewController, source: .about, sourceView: context.sourceView)
}),
AboutItem(title: TextContent.twitter, subtitle: AppConstants.productTwitterHandle, cellStyle: .value1, action: { [weak self] context in
AboutItem(title: TextContent.twitter, subtitle: BuildSettings.current.about.twitterHandle, cellStyle: .value1, action: { [weak self] context in
self?.tracker.buttonPressed(.twitter)
self?.webViewPresenter.presentInNavigationControlller(url: Links.twitter, context: context)
}),
AboutItem(title: Strings.current.blogName, subtitle: AppConstants.productBlogDisplayURL, cellStyle: .value1, action: { [weak self] context in
AboutItem(title: Strings.current.blogName, subtitle: productBlogDisplayURL, cellStyle: .value1, action: { [weak self] context in
self?.tracker.buttonPressed(.blog)
self?.webViewPresenter.presentInNavigationControlller(url: Links.blog, context: context)
})
Expand Down Expand Up @@ -93,6 +93,11 @@ class AppAboutScreenConfiguration: AboutScreenConfiguration {
self.sharePresenter = sharePresenter
}

private var productBlogDisplayURL: String {
let blogURL = BuildSettings.current.about.blogURL
return [blogURL.host, blogURL.path].compactMap { $0 }.joined()
}

private enum TextContent {
static let rateUs = NSLocalizedString("Rate Us", comment: "Title for button allowing users to rate the app in the App Store")
static let share = NSLocalizedString("Share with Friends", comment: "Title for button allowing users to share information about the app with friends, such as via Messages")
Expand All @@ -103,8 +108,8 @@ class AppAboutScreenConfiguration: AboutScreenConfiguration {
}

private enum Links {
static let twitter = URL(string: AppConstants.productTwitterURL)!
static let blog = URL(string: AppConstants.productBlogURL)!
static let twitter = BuildSettings.current.about.twitterURL
static let blog = BuildSettings.current.about.blogURL
static let workWithUs = URL(string: Strings.current.workWithUsURL)!
static let automattic = URL(string: "https://automattic.com")!
}
Expand Down Expand Up @@ -168,6 +173,15 @@ class LegalAndMoreSubmenuConfiguration: AboutScreenConfiguration {
}
}

extension BuildSettings {
var shareAppName: ShareAppName {
switch brand {
case .wordpress: .wordpress
case .jetpack: .jetpack
}
}
}

private struct Strings {
var blogName: String
var workWithUs: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class MeViewController: UITableViewController {
return
}

self.sharePresenter.present(for: AppConstants.shareAppName, in: self, source: .me, sourceView: selectedCell)
self.sharePresenter.present(for: BuildSettings.current.shareAppName, in: self, source: .me, sourceView: selectedCell)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import BuildSettingsKit
import WordPressFlux
import WordPressKit

Expand Down Expand Up @@ -170,7 +171,7 @@ private extension CachedAnnouncementsStore {
}

enum Identifiers {
static let appId = AppConstants.mobileAnnounceAppId
static let appId = BuildSettings.current.mobileAnnounceAppID
static var appVersion: String {
Bundle.main.shortVersionString() ?? ""
}
Expand Down
16 changes: 14 additions & 2 deletions WordPress/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@
<string>${WP_BUILD_CONFIGURATION}</string>
<key>WPAppURLScheme</key>
<string>${WP_APP_URL_SCHEME}</string>
<key>WPJetpackAppURLScheme</key>
<string>${WP_JETPACK_APP_URL_SCHEME}</string>
<key>WPJetpackAppURLScheme</key>
<string>${WP_JETPACK_APP_URL_SCHEME}</string>
<key>WPProductTwitterHandle</key>
<string>@WordPressiOS</string>
<key>WPProductTwitterURL</key>
<string>twitter.com/WordPressiOS</string>
<key>WPProductBlogURL</key>
<string>wordpress.org/news/</string>
<key>WPZendeskSourcePlatform</key>
<string>mobile_-_ios</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be mobile_-_wp_ios? Is there a reason why we do not identify the app?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<key>WPMobileAnnounceAppID</key>
<string>2</string>
<key>WPAuthKeychainServiceName</key>
<string>public-api.wordpress.com</string>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>org.wordpress.bgtask.weeklyroundup</string>
Expand Down
16 changes: 14 additions & 2 deletions WordPress/Jetpack/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@
<string>${WP_BUILD_CONFIGURATION}</string>
<key>WPAppURLScheme</key>
<string>${WP_APP_URL_SCHEME}</string>
<key>WPJetpackAppURLScheme</key>
<string>${WP_JETPACK_APP_URL_SCHEME}</string>
<key>WPJetpackAppURLScheme</key>
<string>${WP_JETPACK_APP_URL_SCHEME}</string>
<key>WPProductTwitterHandle</key>
<string>@jetpack</string>
<key>WPProductTwitterURL</key>
<string>twitter.com/jetpack</string>
<key>WPProductBlogURL</key>
<string>jetpack.com/blog</string>
<key>WPZendeskSourcePlatform</key>
<string>mobile_-_jp_ios</string>
<key>WPMobileAnnounceAppID</key>
<string>6</string>
<key>WPAuthKeychainServiceName</key>
<string>jetpack.public-api.wordpress.com</string>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>org.wordpress.bgtask.weeklyroundup</string>
Expand Down
20 changes: 0 additions & 20 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,6 @@
FA4ADADA1C509FE400F858D7 /* SiteManagementServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA4ADAD91C509FE400F858D7 /* SiteManagementServiceTests.swift */; };
FA6C32C02BF255FA00BBDDB4 /* AppUpdateCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6C32BF2BF255FA00BBDDB4 /* AppUpdateCoordinatorTests.swift */; };
FA6C32C72BF2588C00BBDDB4 /* app-store-lookup-response.json in Resources */ = {isa = PBXBuildFile; fileRef = FA6C32C62BF2588C00BBDDB4 /* app-store-lookup-response.json */; };
FAADE42626159AFE00BF29FE /* AppConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAADE3F02615996E00BF29FE /* AppConstants.swift */; };
FAB4F32724EDE12A00F259BA /* FollowCommentsServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB4F32624EDE12A00F259BA /* FollowCommentsServiceTests.swift */; };
FABB1FC12602FC2C00C8785C /* defaultPostTemplate.html in Resources */ = {isa = PBXBuildFile; fileRef = A01C55470E25E0D000D411F2 /* defaultPostTemplate.html */; };
FABB1FC32602FC2C00C8785C /* defaultPostTemplate_old.html in Resources */ = {isa = PBXBuildFile; fileRef = 2FAE97040E33B21600CA8540 /* defaultPostTemplate_old.html */; };
Expand Down Expand Up @@ -2812,7 +2811,6 @@
FA4ADAD91C509FE400F858D7 /* SiteManagementServiceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SiteManagementServiceTests.swift; sourceTree = "<group>"; };
FA6C32BF2BF255FA00BBDDB4 /* AppUpdateCoordinatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppUpdateCoordinatorTests.swift; sourceTree = "<group>"; };
FA6C32C62BF2588C00BBDDB4 /* app-store-lookup-response.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "app-store-lookup-response.json"; sourceTree = "<group>"; };
FAADE3F02615996E00BF29FE /* AppConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppConstants.swift; sourceTree = "<group>"; };
FAB4F32624EDE12A00F259BA /* FollowCommentsServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowCommentsServiceTests.swift; sourceTree = "<group>"; };
FABB26522602FC2C00C8785C /* Jetpack.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Jetpack.app; sourceTree = BUILT_PRODUCTS_DIR; };
FABB26872602FCCA00C8785C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2883,13 +2881,6 @@
);
target = FF27168E1CAAC87A0006E2D4 /* WordPressUITests */;
};
24CE68B52CD3375300C7B37D /* Exceptions for "Classes" folder in "Jetpack" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
"Utility/App Configuration/AppConstants.swift",
);
target = FABB1F8F2602FC2C00C8785C /* Jetpack */;
};
24CE68BB2CD3375300C7B37D /* Exceptions for "Classes" folder in "JetpackUITests" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
Expand All @@ -2909,7 +2900,6 @@
isa = PBXFileSystemSynchronizedRootGroup;
exceptions = (
24CE68B42CD3375300C7B37D /* Exceptions for "Classes" folder in "WordPressUITests" target */,
24CE68B52CD3375300C7B37D /* Exceptions for "Classes" folder in "Jetpack" target */,
24CE68BB2CD3375300C7B37D /* Exceptions for "Classes" folder in "JetpackUITests" target */,
);
path = Classes;
Expand Down Expand Up @@ -6096,14 +6086,6 @@
path = Logging;
sourceTree = "<group>";
};
FA25FB8C2609B9CB0005E08F /* App Configuration */ = {
isa = PBXGroup;
children = (
FAADE3F02615996E00BF29FE /* AppConstants.swift */,
);
name = "App Configuration";
sourceTree = "<group>";
};
FA6C32BE2BF255BB00BBDDB4 /* AppUpdate */ = {
isa = PBXGroup;
children = (
Expand All @@ -6128,7 +6110,6 @@
24B54FAE2624F8430041B18E /* JetpackRelease-Alpha.entitlements */,
FABB28482603068B00C8785C /* Resources */,
FABB268A2602FCD400C8785C /* Supporting Files */,
FA25FB8C2609B9CB0005E08F /* App Configuration */,
);
path = Jetpack;
sourceTree = "<group>";
Expand Down Expand Up @@ -8457,7 +8438,6 @@
files = (
24351255264DCA08009BB2B6 /* Secrets.swift in Sources */,
FABB23A32602FC2C00C8785C /* Sites.intentdefinition in Sources */,
FAADE42626159AFE00BF29FE /* AppConstants.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down