Skip to content

Commit 474abd4

Browse files
keanmokagio
andauthored
Remove AppConstants (#24294)
* Remove AppConstants.AboutScreen * Remove AppConstants.AppRatings * Remove shareTitle * Replace Settings * Remove AppConstants.Settings * Remove AppConstants.Logout * Replace productTwitterHandle * Replace productTwitterURL * Replace productBlogURL * Replace productBlogDisplayURL * Replace zendeskSourcePlatform * Replace ShareAppName * Remove mobileAnnounceAppId * Replace authKeychainServiceName * Remove AppConstants * Remove `https://` from `Info.plist`s Apparently, Xcode/`xcodebuild` fails to parse it, see how https://buildkite.com/automattic/wordpress-ios/builds/26578/steps?jid=0195bb59-1f1a-40ad-89c9-3964c36cff28#0195bb59-1f1a-40ad-89c9-3964c36cff28/973-5502 failed and notice the build for this commit passes. --------- Co-authored-by: Gio Lodi <[email protected]>
1 parent 961c0d8 commit 474abd4

File tree

14 files changed

+93
-42
lines changed

14 files changed

+93
-42
lines changed

Modules/Sources/BuildSettingsKit/BuildSettings+Live.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ extension BuildSettings {
1414
itunesAppID = bundle.infoValue(forKey: "WPItunesAppID")
1515
appURLScheme = bundle.infoValue(forKey: "WPAppURLScheme")
1616
jetpackAppURLScheme = bundle.infoValue(forKey: "WPJetpackAppURLScheme")
17+
about = ProductAboutDetails(
18+
twitterHandle: bundle.infoValue(forKey: "WPProductTwitterHandle"),
19+
twitterURL: bundle.urlValue(forKey: "WPProductTwitterURL"),
20+
blogURL: bundle.urlValue(forKey: "WPProductBlogURL")
21+
)
22+
zendeskSourcePlatform = bundle.infoValue(forKey: "WPZendeskSourcePlatform")
23+
mobileAnnounceAppID = bundle.infoValue(forKey: "WPMobileAnnounceAppID")
24+
authKeychainServiceName = bundle.infoValue(forKey: "WPAuthKeychainServiceName")
1725
}
1826
}
1927

@@ -32,6 +40,11 @@ private extension Bundle {
3240
fatalError("unexpected value: \(object) for key: \(key)")
3341
}
3442
}
43+
44+
func urlValue(forKey key: String) -> URL {
45+
let urlWithoutScheme: String = infoValue(forKey: key)
46+
return URL(string: "https://\(urlWithoutScheme)")!
47+
}
3548
}
3649

3750
private extension Bundle {

Modules/Sources/BuildSettingsKit/BuildSettings+Preview.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ extension BuildSettings {
1212
explatPlatform: "xcpreview",
1313
itunesAppID: "1234567890",
1414
appURLScheme: "xcpreview",
15-
jetpackAppURLScheme: "jetpack"
15+
jetpackAppURLScheme: "jetpack",
16+
about: ProductAboutDetails(
17+
twitterHandle: "@wordpress",
18+
twitterURL: URL(string: "www.example.com")!,
19+
blogURL: URL(string: "www.example.com")!
20+
),
21+
zendeskSourcePlatform: "zen",
22+
mobileAnnounceAppID: "1234567890",
23+
authKeychainServiceName: "public-api.wordpress.com"
1624
)
1725
}
1826

Modules/Sources/BuildSettingsKit/BuildSettings.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ public struct BuildSettings: Sendable {
2222
public var itunesAppID: String
2323
public var appURLScheme: String
2424
public var jetpackAppURLScheme: String
25+
public var about: ProductAboutDetails
26+
public var zendeskSourcePlatform: String
27+
public var mobileAnnounceAppID: String
28+
public var authKeychainServiceName: String
29+
30+
public struct ProductAboutDetails: Sendable {
31+
public var twitterHandle: String
32+
public var twitterURL: URL
33+
public var blogURL: URL
34+
}
2535

2636
public static var current: BuildSettings {
2737
switch BuildSettingsEnvironment.current {

WordPress/Classes/Models/WPAccount+AccountSettings.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import BuildSettingsKit
23

34
extension WPAccount {
45
enum VerificationStatus: String {
@@ -33,4 +34,8 @@ extension WPAccount {
3334
var needsEmailVerification: Bool {
3435
return verificationStatus == .unverified
3536
}
37+
38+
@objc class var authKeychainServiceName: String {
39+
BuildSettings.current.authKeychainServiceName
40+
}
3641
}

WordPress/Classes/Models/WPAccount.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,4 @@ + (void)migrateAuthKeyForUsername:(NSString *)username
155155
});
156156
}
157157

158-
+ (NSString *)authKeychainServiceName
159-
{
160-
return [AppConstants authKeychainServiceName];
161-
}
162-
163158
@end

WordPress/Classes/Services/CredentialsService.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import BuildSettingsKit
12
import SFHFKeychainUtils
23

34
protocol CredentialsProvider {
@@ -18,6 +19,6 @@ class CredentialsService {
1819
}
1920

2021
func getOAuthToken(site: JetpackSiteRef) -> String? {
21-
return provider.getPassword(username: site.username, service: AppConstants.authKeychainServiceName)
22+
return provider.getPassword(username: site.username, service: BuildSettings.current.authKeychainServiceName)
2223
}
2324
}

WordPress/Classes/Utility/KeychainTools.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final class KeychainTools: NSObject {
4343
static fileprivate func serviceForItem(_ item: String) -> String? {
4444
switch item {
4545
case "wordpress.com":
46-
return AppConstants.authKeychainServiceName
46+
return BuildSettings.current.authKeychainServiceName
4747
case "*", "all":
4848
return nil
4949
default:

WordPress/Classes/Utility/ZendeskUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ private extension ZendeskUtils {
11181118
static let profileNameKey = "name"
11191119
static let userDefaultsZendeskUnreadNotifications = "wp_zendesk_unread_notifications"
11201120
static let nameFieldCharacterLimit = 50
1121-
static let sourcePlatform = AppConstants.zendeskSourcePlatform
1121+
static var sourcePlatform = BuildSettings.current.zendeskSourcePlatform
11221122
static let gutenbergIsDefault = "mobile_gutenberg_is_default"
11231123
static let mobileSelfHosted = "selected_site_self_hosted"
11241124

WordPress/Classes/ViewRelated/Me/App Settings/About/AppAboutScreenConfiguration.swift

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import Foundation
1+
import UIKit
22
import BuildSettingsKit
33
import WordPressUI
4-
import UIKit
4+
import WordPressKit
55
import WordPressShared
66
import AutomatticAbout
77
import SwiftUI
@@ -43,13 +43,13 @@ class AppAboutScreenConfiguration: AboutScreenConfiguration {
4343
}),
4444
AboutItem(title: TextContent.share, action: { [weak self] context in
4545
self?.tracker.buttonPressed(.share)
46-
self?.sharePresenter.present(for: AppConstants.shareAppName, in: context.viewController, source: .about, sourceView: context.sourceView)
46+
self?.sharePresenter.present(for: BuildSettings.current.shareAppName, in: context.viewController, source: .about, sourceView: context.sourceView)
4747
}),
48-
AboutItem(title: TextContent.twitter, subtitle: AppConstants.productTwitterHandle, cellStyle: .value1, action: { [weak self] context in
48+
AboutItem(title: TextContent.twitter, subtitle: BuildSettings.current.about.twitterHandle, cellStyle: .value1, action: { [weak self] context in
4949
self?.tracker.buttonPressed(.twitter)
5050
self?.webViewPresenter.presentInNavigationControlller(url: Links.twitter, context: context)
5151
}),
52-
AboutItem(title: Strings.current.blogName, subtitle: AppConstants.productBlogDisplayURL, cellStyle: .value1, action: { [weak self] context in
52+
AboutItem(title: Strings.current.blogName, subtitle: productBlogDisplayURL, cellStyle: .value1, action: { [weak self] context in
5353
self?.tracker.buttonPressed(.blog)
5454
self?.webViewPresenter.presentInNavigationControlller(url: Links.blog, context: context)
5555
})
@@ -93,6 +93,11 @@ class AppAboutScreenConfiguration: AboutScreenConfiguration {
9393
self.sharePresenter = sharePresenter
9494
}
9595

96+
private var productBlogDisplayURL: String {
97+
let blogURL = BuildSettings.current.about.blogURL
98+
return [blogURL.host, blogURL.path].compactMap { $0 }.joined()
99+
}
100+
96101
private enum TextContent {
97102
static let rateUs = NSLocalizedString("Rate Us", comment: "Title for button allowing users to rate the app in the App Store")
98103
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")
@@ -103,8 +108,8 @@ class AppAboutScreenConfiguration: AboutScreenConfiguration {
103108
}
104109

105110
private enum Links {
106-
static let twitter = URL(string: AppConstants.productTwitterURL)!
107-
static let blog = URL(string: AppConstants.productBlogURL)!
111+
static let twitter = BuildSettings.current.about.twitterURL
112+
static let blog = BuildSettings.current.about.blogURL
108113
static let workWithUs = URL(string: Strings.current.workWithUsURL)!
109114
static let automattic = URL(string: "https://automattic.com")!
110115
}
@@ -168,6 +173,15 @@ class LegalAndMoreSubmenuConfiguration: AboutScreenConfiguration {
168173
}
169174
}
170175

176+
extension BuildSettings {
177+
var shareAppName: ShareAppName {
178+
switch brand {
179+
case .wordpress: .wordpress
180+
case .jetpack: .jetpack
181+
}
182+
}
183+
}
184+
171185
private struct Strings {
172186
var blogName: String
173187
var workWithUs: String

WordPress/Classes/ViewRelated/Me/Me Main/MeViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ class MeViewController: UITableViewController {
329329
return
330330
}
331331

332-
self.sharePresenter.present(for: AppConstants.shareAppName, in: self, source: .me, sourceView: selectedCell)
332+
self.sharePresenter.present(for: BuildSettings.current.shareAppName, in: self, source: .me, sourceView: selectedCell)
333333
}
334334
}
335335

0 commit comments

Comments
 (0)