From 96832484b3786cc93f79f9f762d26d211f3ecbb9 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO <> Date: Mon, 6 May 2024 13:09:02 +1000 Subject: [PATCH] minor refactor on getting app name --- .../ConversationVC+Interaction.swift | 8 +++---- Session/Conversations/ConversationVC.swift | 2 +- .../OpenGroupInvitationView_SwiftUI.swift | 2 +- Session/Meta/AppDelegate.swift | 4 ++-- Session/Notifications/AppNotifications.swift | 8 +++---- Session/Onboarding/LandingScreen.swift | 24 +++++++++++++++---- Session/Onboarding/PNModeScreen.swift | 2 +- Session/Open Groups/JoinOpenGroupVC.swift | 2 +- Session/Path/PathVC.swift | 2 +- Session/Settings/HelpViewModel.swift | 4 ++-- .../Settings/PrivacySettingsViewModel.swift | 2 +- Session/Settings/QRCodeVC.swift | 2 +- Session/Settings/SettingsViewModel.swift | 2 +- Session/Shared/ScanQRCodeScreen.swift | 2 +- Session/Utilities/Permissions.swift | 4 ++-- .../NSENotificationPresenter.swift | 8 +++---- .../NotificationServiceExtension.swift | 4 ++-- .../SAEScreenLockViewController.swift | 2 +- .../ShareNavController.swift | 2 +- SessionShareExtension/ThreadPickerVC.swift | 2 +- SessionUtilitiesKit/General/AppContext.swift | 5 ++-- .../MediaMessageView.swift | 2 +- 22 files changed, 55 insertions(+), 40 deletions(-) diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 405aef5b6..f631bd891 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -254,7 +254,7 @@ extension ConversationVC: title: "giphyWarning".localized(), body: .text( "giphyWarningDescription" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .localized() ), confirmTitle: "theContinue".localized() @@ -642,7 +642,7 @@ extension ConversationVC: title: "linkPreviewsEnable".localized(), body: .text( "linkPreviewsFirstDescription" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .localized() ), confirmTitle: "enable".localized() @@ -2295,7 +2295,7 @@ extension ConversationVC: let modal: ConfirmationModal = ConfirmationModal( targetView: self.view, info: ConfirmationModal.Info( - title: Singleton.appContext.appName, + title: Singleton.appName, body: .text("This will ban the selected user from this room. It won't ban them from other rooms."), confirmTitle: "okay".localized(), cancelStyle: .alert_text, @@ -2349,7 +2349,7 @@ extension ConversationVC: let modal: ConfirmationModal = ConfirmationModal( targetView: self.view, info: ConfirmationModal.Info( - title: Singleton.appContext.appName, + title: Singleton.appName, body: .text("This will ban the selected user from this room and delete all messages sent by them. It won't ban them from other rooms or delete the messages they sent there."), confirmTitle: "okay".localized(), cancelStyle: .alert_text, diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index 7e154fd56..c362b3819 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -335,7 +335,7 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers result.font = UIFont.systemFont(ofSize: 12) result.text = (self.viewModel.threadData.threadRequiresApproval == false ? "messageRequestsAcceptDescription" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .localized() : "messageRequestPendingDescription".localized() ) diff --git a/Session/Conversations/Message Cells/Content Views/SwiftUI/OpenGroupInvitationView_SwiftUI.swift b/Session/Conversations/Message Cells/Content Views/SwiftUI/OpenGroupInvitationView_SwiftUI.swift index b4efa0b7d..265b9ec2a 100644 --- a/Session/Conversations/Message Cells/Content Views/SwiftUI/OpenGroupInvitationView_SwiftUI.swift +++ b/Session/Conversations/Message Cells/Content Views/SwiftUI/OpenGroupInvitationView_SwiftUI.swift @@ -87,7 +87,7 @@ struct OpenGroupInvitationView_SwiftUI: View { struct OpenGroupInvitationView_SwiftUI_Previews: PreviewProvider { static var previews: some View { OpenGroupInvitationView_SwiftUI( - name: Singleton.appContext.appName, + name: Singleton.appName, url: "http://open.getsession.org/session?public_key=a03c383cf63c3c4efe67acc52112a6dd734b3a946b9545f488aaa93da7991238", textColor: .messageBubble_outgoingText, isOutgoing: true diff --git a/Session/Meta/AppDelegate.swift b/Session/Meta/AppDelegate.swift index 5248bf732..fa39c0f72 100644 --- a/Session/Meta/AppDelegate.swift +++ b/Session/Meta/AppDelegate.swift @@ -404,7 +404,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD /// This **must** be a standard `UIAlertController` instead of a `ConfirmationModal` because we may not /// have access to the database when displaying this so can't extract theme information for styling purposes let alert: UIAlertController = UIAlertController( - title: Singleton.appContext.appName, + title: Singleton.appName, message: error.message, preferredStyle: .alert ) @@ -901,7 +901,7 @@ private enum StartupError: Error { case .startupTimeout: return "databaseErrorTimeout" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .localized() } } diff --git a/Session/Notifications/AppNotifications.swift b/Session/Notifications/AppNotifications.swift index 6c82f22cc..7d82567a1 100644 --- a/Session/Notifications/AppNotifications.swift +++ b/Session/Notifications/AppNotifications.swift @@ -137,12 +137,12 @@ public class NotificationPresenter: NotificationsProtocol { switch previewType { case .noNameNoPreview: - notificationTitle = Singleton.appContext.appName + notificationTitle = Singleton.appName case .nameNoPreview, .nameAndPreview: switch thread.variant { case .contact: - notificationTitle = (isMessageRequest ? Singleton.appContext.appName : senderName) + notificationTitle = (isMessageRequest ? Singleton.appName : senderName) case .legacyGroup, .group, .community: notificationTitle = "notificationsIosGroup" @@ -255,7 +255,7 @@ public class NotificationPresenter: NotificationsProtocol { AppNotificationUserInfoKey.threadVariantRaw: thread.variant.rawValue ] - let notificationTitle: String = Singleton.appContext.appName + let notificationTitle: String = Singleton.appName let senderName: String = Profile.displayName(db, id: interaction.authorId, threadVariant: thread.variant) let notificationBody: String? = { switch messageInfo.state { @@ -312,7 +312,7 @@ public class NotificationPresenter: NotificationsProtocol { guard !isMessageRequest else { return } let senderName: String = Profile.displayName(db, id: reaction.authorId, threadVariant: thread.variant) - let notificationTitle = Singleton.appContext.appName + let notificationTitle = Singleton.appName var notificationBody = "emojiReactsHoverName" .put(key: "name", value: senderName) .put(key: "emoji", value: reaction.emoji) diff --git a/Session/Onboarding/LandingScreen.swift b/Session/Onboarding/LandingScreen.swift index d61da0c7b..7e9f971ad 100644 --- a/Session/Onboarding/LandingScreen.swift +++ b/Session/Onboarding/LandingScreen.swift @@ -196,10 +196,26 @@ struct FakeChat: View { @State var numberOfBubblesShown: Int = 0 let chatBubbles: [ChatBubble] = [ - ChatBubble(text: "onboardingBubbleWelcomeToSession".localized() + " 👋", outgoing: false), - ChatBubble(text: "onboardingBubbleSessionIsEngineered".localized(), outgoing: true), - ChatBubble(text: "onboardingBubbleNoPhoneNumber".localized(), outgoing: false), - ChatBubble(text: "onboardingBubbleCreatingAnAccountIsEasy".localized() + " 👇", outgoing: true), + ChatBubble( + text: "onboardingBubbleWelcomeToSession" + .put(key: "app_name", value: Singleton.appName) + .localized() + " 👋", + outgoing: false + ), + ChatBubble( + text: "onboardingBubbleSessionIsEngineered" + .put(key: "app_name", value: Singleton.appName) + .localized(), + outgoing: true + ), + ChatBubble( + text: "onboardingBubbleNoPhoneNumber".localized(), + outgoing: false + ), + ChatBubble( + text: "onboardingBubbleCreatingAnAccountIsEasy".localized() + " 👇", + outgoing: true + ) ] var body: some View { diff --git a/Session/Onboarding/PNModeScreen.swift b/Session/Onboarding/PNModeScreen.swift index 5a495bdce..fbe700fd9 100644 --- a/Session/Onboarding/PNModeScreen.swift +++ b/Session/Onboarding/PNModeScreen.swift @@ -38,7 +38,7 @@ struct PNModeScreen: View { mode: .slow, title: "notificationsSlowMode".localized(), explanation: "notificationsSlowModeDescription" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .localized(), isRecommended: false, accessibility: Accessibility( diff --git a/Session/Open Groups/JoinOpenGroupVC.swift b/Session/Open Groups/JoinOpenGroupVC.swift index cb1937ce7..03d3b3535 100644 --- a/Session/Open Groups/JoinOpenGroupVC.swift +++ b/Session/Open Groups/JoinOpenGroupVC.swift @@ -524,7 +524,7 @@ private final class ScanQRCodePlaceholderVC: UIViewController { let explanationLabel = UILabel() explanationLabel.font = .systemFont(ofSize: Values.smallFontSize) explanationLabel.text = "cameraGrantAccessQr" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .localized() explanationLabel.themeTextColor = .textPrimary explanationLabel.textAlignment = .center diff --git a/Session/Path/PathVC.swift b/Session/Path/PathVC.swift index 1ff6b109c..8f75d7606 100644 --- a/Session/Path/PathVC.swift +++ b/Session/Path/PathVC.swift @@ -68,7 +68,7 @@ final class PathVC: BaseVC { let explanationLabel = UILabel() explanationLabel.font = .systemFont(ofSize: Values.smallFontSize) explanationLabel.text = "onionRoutingPathDescription" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .localized() explanationLabel.themeTextColor = .textSecondary explanationLabel.textAlignment = .center diff --git a/Session/Settings/HelpViewModel.swift b/Session/Settings/HelpViewModel.swift index 1e27a77ca..11fdb5c02 100644 --- a/Session/Settings/HelpViewModel.swift +++ b/Session/Settings/HelpViewModel.swift @@ -54,7 +54,7 @@ class HelpViewModel: SessionTableViewModel, NavigatableStateHolder, ObservableTa id: .report, title: "helpReportABug".localized(), subtitle: "helpReportABugExportLogsDescription" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .localized(), rightAccessory: .highlightingBackgroundLabel( title: "helpReportABugExportLogs".localized() @@ -69,7 +69,7 @@ class HelpViewModel: SessionTableViewModel, NavigatableStateHolder, ObservableTa SessionCell.Info( id: .translate, title: "helpHelpUsTranslateSession" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .localized(), rightAccessory: .icon( UIImage(systemName: "arrow.up.forward.app")? diff --git a/Session/Settings/PrivacySettingsViewModel.swift b/Session/Settings/PrivacySettingsViewModel.swift index 7da091d08..7851af1a7 100644 --- a/Session/Settings/PrivacySettingsViewModel.swift +++ b/Session/Settings/PrivacySettingsViewModel.swift @@ -109,7 +109,7 @@ class PrivacySettingsViewModel: SessionTableViewModel, NavigationItemSource, Nav id: .screenLock, title: "lockApp".localized(), subtitle: "lockAppDescriptionIos" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .localized(), rightAccessory: .toggle( .boolValue( diff --git a/Session/Settings/QRCodeVC.swift b/Session/Settings/QRCodeVC.swift index bffc082fb..f4a61b65a 100644 --- a/Session/Settings/QRCodeVC.swift +++ b/Session/Settings/QRCodeVC.swift @@ -294,7 +294,7 @@ private final class ScanQRCodePlaceholderVC : UIViewController { let explanationLabel = UILabel() explanationLabel.font = .systemFont(ofSize: Values.smallFontSize) explanationLabel.text = "cameraGrantAccessQr" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .localized() explanationLabel.themeTextColor = .textPrimary explanationLabel.textAlignment = .center diff --git a/Session/Settings/SettingsViewModel.swift b/Session/Settings/SettingsViewModel.swift index c90748b1a..a4a71fb0d 100644 --- a/Session/Settings/SettingsViewModel.swift +++ b/Session/Settings/SettingsViewModel.swift @@ -425,7 +425,7 @@ class SettingsViewModel: SessionTableViewModel, NavigationItemSource, Navigatabl title: "sessionInviteAFriend".localized(), onTap: { let invitation: String = "accountIdShare" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .put(key: "account_id", value: state.profile.id) .put(key: "download_url", value: "https://getsession.org/") .localized() diff --git a/Session/Shared/ScanQRCodeScreen.swift b/Session/Shared/ScanQRCodeScreen.swift index f74fa2c4d..375809108 100644 --- a/Session/Shared/ScanQRCodeScreen.swift +++ b/Session/Shared/ScanQRCodeScreen.swift @@ -44,7 +44,7 @@ struct ScanQRCodeScreen: View { Text( "cameraGrantAccessQr" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .localized() ) .font(.system(size: Values.smallFontSize)) diff --git a/Session/Utilities/Permissions.swift b/Session/Utilities/Permissions.swift index aaf5eccd4..983c29503 100644 --- a/Session/Utilities/Permissions.swift +++ b/Session/Utilities/Permissions.swift @@ -28,7 +28,7 @@ public enum Permissions { title: "permissionsRequired".localized(), body: .text( "cameraGrantAccessDenied" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .localized() ), confirmTitle: "sessionSettings".localized(), @@ -141,7 +141,7 @@ public enum Permissions { title: "permissionsRequired".localized(), body: .text( "permissionsLibrary" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .localized() ), confirmTitle: "sessionSettings".localized(), diff --git a/SessionNotificationServiceExtension/NSENotificationPresenter.swift b/SessionNotificationServiceExtension/NSENotificationPresenter.swift index 43f4b0904..49ece9262 100644 --- a/SessionNotificationServiceExtension/NSENotificationPresenter.swift +++ b/SessionNotificationServiceExtension/NSENotificationPresenter.swift @@ -73,14 +73,14 @@ public class NSENotificationPresenter: NSObject, NotificationsProtocol { notificationContent.body = "messageNewYouveGotA".localized() case .noNameNoPreview: - notificationContent.title = Singleton.appContext.appName + notificationContent.title = Singleton.appName notificationContent.body = "messageNewYouveGotA".localized() } // If it's a message request then overwrite the body to be something generic (only show a notification // when receiving a new message request if there aren't any others or the user had hidden them) if isMessageRequest { - notificationContent.title = Singleton.appContext.appName + notificationContent.title = Singleton.appName notificationContent.body = "messageRequestsNew".localized() } @@ -159,7 +159,7 @@ public class NSENotificationPresenter: NSObject, NotificationsProtocol { .map { NSNumber(value: $0) } .defaulting(to: NSNumber(value: 0)) - notificationContent.title = Singleton.appContext.appName + notificationContent.title = Singleton.appName notificationContent.body = "" let senderName: String = Profile.displayName(db, id: interaction.authorId, threadVariant: thread.variant) @@ -190,7 +190,7 @@ public class NSENotificationPresenter: NSObject, NotificationsProtocol { guard !isMessageRequest else { return } let senderName: String = Profile.displayName(db, id: reaction.authorId, threadVariant: thread.variant) - let notificationTitle = Singleton.appContext.appName + let notificationTitle = Singleton.appName var notificationBody = "emojiReactsHoverName" .put(key: "name", value: senderName) .put(key: "emoji", value: reaction.emoji) diff --git a/SessionNotificationServiceExtension/NotificationServiceExtension.swift b/SessionNotificationServiceExtension/NotificationServiceExtension.swift index 27a51d60d..8978c0c64 100644 --- a/SessionNotificationServiceExtension/NotificationServiceExtension.swift +++ b/SessionNotificationServiceExtension/NotificationServiceExtension.swift @@ -345,7 +345,7 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension private func handleFailureForVoIP(_ db: Database, for callMessage: CallMessage) { let notificationContent = UNMutableNotificationContent() notificationContent.userInfo = [ NotificationServiceExtension.isFromRemoteKey : true ] - notificationContent.title = Singleton.appContext.appName + notificationContent.title = Singleton.appName notificationContent.badge = (try? Interaction.fetchUnreadCount(db)) .map { NSNumber(value: $0) } .defaulting(to: NSNumber(value: 0)) @@ -378,7 +378,7 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension NSLog("[NotificationServiceExtension] Show generic failure message due to error: \(error)") Storage.suspendDatabaseAccess() - content.title = Singleton.appContext.appName + content.title = Singleton.appName content.body = "messageNewYouveGotA".localized() let userInfo: [String: Any] = [ NotificationServiceExtension.isFromRemoteKey: true ] content.userInfo = userInfo diff --git a/SessionShareExtension/SAEScreenLockViewController.swift b/SessionShareExtension/SAEScreenLockViewController.swift index b33318edb..cea04820b 100644 --- a/SessionShareExtension/SAEScreenLockViewController.swift +++ b/SessionShareExtension/SAEScreenLockViewController.swift @@ -36,7 +36,7 @@ final class SAEScreenLockViewController: ScreenLockViewController { let titleLabel: UILabel = UILabel() titleLabel.font = UIFont.boldSystemFont(ofSize: Values.veryLargeFontSize) titleLabel.text = "shareToSession" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .localized() titleLabel.themeTextColor = .textPrimary diff --git a/SessionShareExtension/ShareNavController.swift b/SessionShareExtension/ShareNavController.swift index 2264a5a3d..4e992be25 100644 --- a/SessionShareExtension/ShareNavController.swift +++ b/SessionShareExtension/ShareNavController.swift @@ -244,7 +244,7 @@ final class ShareNavController: UINavigationController, ShareViewDelegate { let modal: ConfirmationModal = ConfirmationModal( targetView: self.view, info: ConfirmationModal.Info( - title: Singleton.appContext.appName, + title: Singleton.appName, body: .text(error.localizedDescription), cancelTitle: "okay".localized(), cancelStyle: .alert_text, diff --git a/SessionShareExtension/ThreadPickerVC.swift b/SessionShareExtension/ThreadPickerVC.swift index 6c7258ddc..2870a9ecf 100644 --- a/SessionShareExtension/ThreadPickerVC.swift +++ b/SessionShareExtension/ThreadPickerVC.swift @@ -30,7 +30,7 @@ final class ThreadPickerVC: UIViewController, UITableViewDataSource, UITableView let titleLabel: UILabel = UILabel() titleLabel.font = .boldSystemFont(ofSize: Values.veryLargeFontSize) titleLabel.text = "shareToSession" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .localized() titleLabel.themeTextColor = .textPrimary diff --git a/SessionUtilitiesKit/General/AppContext.swift b/SessionUtilitiesKit/General/AppContext.swift index d0c1c3895..eef17abc2 100644 --- a/SessionUtilitiesKit/General/AppContext.swift +++ b/SessionUtilitiesKit/General/AppContext.swift @@ -12,6 +12,8 @@ public extension Singleton { static var hasAppContext: Bool { _appContext.wrappedValue != nil } static func setup(appContext: AppContext) { _appContext.mutate { $0 = appContext } } + + static var appName: String { "Session" } // stringlint:disable } // MARK: - AppContext @@ -24,7 +26,6 @@ public protocol AppContext: AnyObject { var reportedApplicationState: UIApplication.State { get } var mainWindow: UIWindow? { get } var isRTL: Bool { get } - var appName: String { get } var frontmostViewController: UIViewController? { get } func setMainWindow(_ mainWindow: UIWindow) @@ -49,8 +50,6 @@ public extension AppContext { var isInBackground: Bool { reportedApplicationState == .background } var isAppForegroundAndActive: Bool { reportedApplicationState == .active } - var appName: String { "Session" } - // MARK: - Paths var appUserDefaults: UserDefaults { diff --git a/SignalUtilitiesKit/Media Viewing & Editing/MediaMessageView.swift b/SignalUtilitiesKit/Media Viewing & Editing/MediaMessageView.swift index 0b5aca165..ef898eb66 100644 --- a/SignalUtilitiesKit/Media Viewing & Editing/MediaMessageView.swift +++ b/SignalUtilitiesKit/Media Viewing & Editing/MediaMessageView.swift @@ -291,7 +291,7 @@ public class MediaMessageView: UIView { // If we have no link preview info at this point then assume link previews are disabled else { label.text = "linkPreviewsTurnedOffDescription" - .put(key: "app_name", value: Singleton.appContext.appName) + .put(key: "app_name", value: Singleton.appName) .localized() label.themeTextColor = .textPrimary label.textAlignment = .center