minor refactor on getting app name

pull/1023/head
Ryan ZHAO 1 year ago
parent ed24b91199
commit 96832484b3

@ -254,7 +254,7 @@ extension ConversationVC:
title: "giphyWarning".localized(), title: "giphyWarning".localized(),
body: .text( body: .text(
"giphyWarningDescription" "giphyWarningDescription"
.put(key: "app_name", value: Singleton.appContext.appName) .put(key: "app_name", value: Singleton.appName)
.localized() .localized()
), ),
confirmTitle: "theContinue".localized() confirmTitle: "theContinue".localized()
@ -642,7 +642,7 @@ extension ConversationVC:
title: "linkPreviewsEnable".localized(), title: "linkPreviewsEnable".localized(),
body: .text( body: .text(
"linkPreviewsFirstDescription" "linkPreviewsFirstDescription"
.put(key: "app_name", value: Singleton.appContext.appName) .put(key: "app_name", value: Singleton.appName)
.localized() .localized()
), ),
confirmTitle: "enable".localized() confirmTitle: "enable".localized()
@ -2295,7 +2295,7 @@ extension ConversationVC:
let modal: ConfirmationModal = ConfirmationModal( let modal: ConfirmationModal = ConfirmationModal(
targetView: self.view, targetView: self.view,
info: ConfirmationModal.Info( 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."), body: .text("This will ban the selected user from this room. It won't ban them from other rooms."),
confirmTitle: "okay".localized(), confirmTitle: "okay".localized(),
cancelStyle: .alert_text, cancelStyle: .alert_text,
@ -2349,7 +2349,7 @@ extension ConversationVC:
let modal: ConfirmationModal = ConfirmationModal( let modal: ConfirmationModal = ConfirmationModal(
targetView: self.view, targetView: self.view,
info: ConfirmationModal.Info( 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."), 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(), confirmTitle: "okay".localized(),
cancelStyle: .alert_text, cancelStyle: .alert_text,

@ -335,7 +335,7 @@ final class ConversationVC: BaseVC, SessionUtilRespondingViewController, Convers
result.font = UIFont.systemFont(ofSize: 12) result.font = UIFont.systemFont(ofSize: 12)
result.text = (self.viewModel.threadData.threadRequiresApproval == false ? result.text = (self.viewModel.threadData.threadRequiresApproval == false ?
"messageRequestsAcceptDescription" "messageRequestsAcceptDescription"
.put(key: "app_name", value: Singleton.appContext.appName) .put(key: "app_name", value: Singleton.appName)
.localized() : .localized() :
"messageRequestPendingDescription".localized() "messageRequestPendingDescription".localized()
) )

@ -87,7 +87,7 @@ struct OpenGroupInvitationView_SwiftUI: View {
struct OpenGroupInvitationView_SwiftUI_Previews: PreviewProvider { struct OpenGroupInvitationView_SwiftUI_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
OpenGroupInvitationView_SwiftUI( OpenGroupInvitationView_SwiftUI(
name: Singleton.appContext.appName, name: Singleton.appName,
url: "http://open.getsession.org/session?public_key=a03c383cf63c3c4efe67acc52112a6dd734b3a946b9545f488aaa93da7991238", url: "http://open.getsession.org/session?public_key=a03c383cf63c3c4efe67acc52112a6dd734b3a946b9545f488aaa93da7991238",
textColor: .messageBubble_outgoingText, textColor: .messageBubble_outgoingText,
isOutgoing: true isOutgoing: true

@ -404,7 +404,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
/// This **must** be a standard `UIAlertController` instead of a `ConfirmationModal` because we may not /// 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 /// have access to the database when displaying this so can't extract theme information for styling purposes
let alert: UIAlertController = UIAlertController( let alert: UIAlertController = UIAlertController(
title: Singleton.appContext.appName, title: Singleton.appName,
message: error.message, message: error.message,
preferredStyle: .alert preferredStyle: .alert
) )
@ -901,7 +901,7 @@ private enum StartupError: Error {
case .startupTimeout: case .startupTimeout:
return "databaseErrorTimeout" return "databaseErrorTimeout"
.put(key: "app_name", value: Singleton.appContext.appName) .put(key: "app_name", value: Singleton.appName)
.localized() .localized()
} }
} }

@ -137,12 +137,12 @@ public class NotificationPresenter: NotificationsProtocol {
switch previewType { switch previewType {
case .noNameNoPreview: case .noNameNoPreview:
notificationTitle = Singleton.appContext.appName notificationTitle = Singleton.appName
case .nameNoPreview, .nameAndPreview: case .nameNoPreview, .nameAndPreview:
switch thread.variant { switch thread.variant {
case .contact: case .contact:
notificationTitle = (isMessageRequest ? Singleton.appContext.appName : senderName) notificationTitle = (isMessageRequest ? Singleton.appName : senderName)
case .legacyGroup, .group, .community: case .legacyGroup, .group, .community:
notificationTitle = "notificationsIosGroup" notificationTitle = "notificationsIosGroup"
@ -255,7 +255,7 @@ public class NotificationPresenter: NotificationsProtocol {
AppNotificationUserInfoKey.threadVariantRaw: thread.variant.rawValue 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 senderName: String = Profile.displayName(db, id: interaction.authorId, threadVariant: thread.variant)
let notificationBody: String? = { let notificationBody: String? = {
switch messageInfo.state { switch messageInfo.state {
@ -312,7 +312,7 @@ public class NotificationPresenter: NotificationsProtocol {
guard !isMessageRequest else { return } guard !isMessageRequest else { return }
let senderName: String = Profile.displayName(db, id: reaction.authorId, threadVariant: thread.variant) let senderName: String = Profile.displayName(db, id: reaction.authorId, threadVariant: thread.variant)
let notificationTitle = Singleton.appContext.appName let notificationTitle = Singleton.appName
var notificationBody = "emojiReactsHoverName" var notificationBody = "emojiReactsHoverName"
.put(key: "name", value: senderName) .put(key: "name", value: senderName)
.put(key: "emoji", value: reaction.emoji) .put(key: "emoji", value: reaction.emoji)

@ -196,10 +196,26 @@ struct FakeChat: View {
@State var numberOfBubblesShown: Int = 0 @State var numberOfBubblesShown: Int = 0
let chatBubbles: [ChatBubble] = [ let chatBubbles: [ChatBubble] = [
ChatBubble(text: "onboardingBubbleWelcomeToSession".localized() + " 👋", outgoing: false), ChatBubble(
ChatBubble(text: "onboardingBubbleSessionIsEngineered".localized(), outgoing: true), text: "onboardingBubbleWelcomeToSession"
ChatBubble(text: "onboardingBubbleNoPhoneNumber".localized(), outgoing: false), .put(key: "app_name", value: Singleton.appName)
ChatBubble(text: "onboardingBubbleCreatingAnAccountIsEasy".localized() + " 👇", outgoing: true), .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 { var body: some View {

@ -38,7 +38,7 @@ struct PNModeScreen: View {
mode: .slow, mode: .slow,
title: "notificationsSlowMode".localized(), title: "notificationsSlowMode".localized(),
explanation: "notificationsSlowModeDescription" explanation: "notificationsSlowModeDescription"
.put(key: "app_name", value: Singleton.appContext.appName) .put(key: "app_name", value: Singleton.appName)
.localized(), .localized(),
isRecommended: false, isRecommended: false,
accessibility: Accessibility( accessibility: Accessibility(

@ -524,7 +524,7 @@ private final class ScanQRCodePlaceholderVC: UIViewController {
let explanationLabel = UILabel() let explanationLabel = UILabel()
explanationLabel.font = .systemFont(ofSize: Values.smallFontSize) explanationLabel.font = .systemFont(ofSize: Values.smallFontSize)
explanationLabel.text = "cameraGrantAccessQr" explanationLabel.text = "cameraGrantAccessQr"
.put(key: "app_name", value: Singleton.appContext.appName) .put(key: "app_name", value: Singleton.appName)
.localized() .localized()
explanationLabel.themeTextColor = .textPrimary explanationLabel.themeTextColor = .textPrimary
explanationLabel.textAlignment = .center explanationLabel.textAlignment = .center

@ -68,7 +68,7 @@ final class PathVC: BaseVC {
let explanationLabel = UILabel() let explanationLabel = UILabel()
explanationLabel.font = .systemFont(ofSize: Values.smallFontSize) explanationLabel.font = .systemFont(ofSize: Values.smallFontSize)
explanationLabel.text = "onionRoutingPathDescription" explanationLabel.text = "onionRoutingPathDescription"
.put(key: "app_name", value: Singleton.appContext.appName) .put(key: "app_name", value: Singleton.appName)
.localized() .localized()
explanationLabel.themeTextColor = .textSecondary explanationLabel.themeTextColor = .textSecondary
explanationLabel.textAlignment = .center explanationLabel.textAlignment = .center

@ -54,7 +54,7 @@ class HelpViewModel: SessionTableViewModel, NavigatableStateHolder, ObservableTa
id: .report, id: .report,
title: "helpReportABug".localized(), title: "helpReportABug".localized(),
subtitle: "helpReportABugExportLogsDescription" subtitle: "helpReportABugExportLogsDescription"
.put(key: "app_name", value: Singleton.appContext.appName) .put(key: "app_name", value: Singleton.appName)
.localized(), .localized(),
rightAccessory: .highlightingBackgroundLabel( rightAccessory: .highlightingBackgroundLabel(
title: "helpReportABugExportLogs".localized() title: "helpReportABugExportLogs".localized()
@ -69,7 +69,7 @@ class HelpViewModel: SessionTableViewModel, NavigatableStateHolder, ObservableTa
SessionCell.Info( SessionCell.Info(
id: .translate, id: .translate,
title: "helpHelpUsTranslateSession" title: "helpHelpUsTranslateSession"
.put(key: "app_name", value: Singleton.appContext.appName) .put(key: "app_name", value: Singleton.appName)
.localized(), .localized(),
rightAccessory: .icon( rightAccessory: .icon(
UIImage(systemName: "arrow.up.forward.app")? UIImage(systemName: "arrow.up.forward.app")?

@ -109,7 +109,7 @@ class PrivacySettingsViewModel: SessionTableViewModel, NavigationItemSource, Nav
id: .screenLock, id: .screenLock,
title: "lockApp".localized(), title: "lockApp".localized(),
subtitle: "lockAppDescriptionIos" subtitle: "lockAppDescriptionIos"
.put(key: "app_name", value: Singleton.appContext.appName) .put(key: "app_name", value: Singleton.appName)
.localized(), .localized(),
rightAccessory: .toggle( rightAccessory: .toggle(
.boolValue( .boolValue(

@ -294,7 +294,7 @@ private final class ScanQRCodePlaceholderVC : UIViewController {
let explanationLabel = UILabel() let explanationLabel = UILabel()
explanationLabel.font = .systemFont(ofSize: Values.smallFontSize) explanationLabel.font = .systemFont(ofSize: Values.smallFontSize)
explanationLabel.text = "cameraGrantAccessQr" explanationLabel.text = "cameraGrantAccessQr"
.put(key: "app_name", value: Singleton.appContext.appName) .put(key: "app_name", value: Singleton.appName)
.localized() .localized()
explanationLabel.themeTextColor = .textPrimary explanationLabel.themeTextColor = .textPrimary
explanationLabel.textAlignment = .center explanationLabel.textAlignment = .center

@ -425,7 +425,7 @@ class SettingsViewModel: SessionTableViewModel, NavigationItemSource, Navigatabl
title: "sessionInviteAFriend".localized(), title: "sessionInviteAFriend".localized(),
onTap: { onTap: {
let invitation: String = "accountIdShare" 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: "account_id", value: state.profile.id)
.put(key: "download_url", value: "https://getsession.org/") .put(key: "download_url", value: "https://getsession.org/")
.localized() .localized()

@ -44,7 +44,7 @@ struct ScanQRCodeScreen: View {
Text( Text(
"cameraGrantAccessQr" "cameraGrantAccessQr"
.put(key: "app_name", value: Singleton.appContext.appName) .put(key: "app_name", value: Singleton.appName)
.localized() .localized()
) )
.font(.system(size: Values.smallFontSize)) .font(.system(size: Values.smallFontSize))

@ -28,7 +28,7 @@ public enum Permissions {
title: "permissionsRequired".localized(), title: "permissionsRequired".localized(),
body: .text( body: .text(
"cameraGrantAccessDenied" "cameraGrantAccessDenied"
.put(key: "app_name", value: Singleton.appContext.appName) .put(key: "app_name", value: Singleton.appName)
.localized() .localized()
), ),
confirmTitle: "sessionSettings".localized(), confirmTitle: "sessionSettings".localized(),
@ -141,7 +141,7 @@ public enum Permissions {
title: "permissionsRequired".localized(), title: "permissionsRequired".localized(),
body: .text( body: .text(
"permissionsLibrary" "permissionsLibrary"
.put(key: "app_name", value: Singleton.appContext.appName) .put(key: "app_name", value: Singleton.appName)
.localized() .localized()
), ),
confirmTitle: "sessionSettings".localized(), confirmTitle: "sessionSettings".localized(),

@ -73,14 +73,14 @@ public class NSENotificationPresenter: NSObject, NotificationsProtocol {
notificationContent.body = "messageNewYouveGotA".localized() notificationContent.body = "messageNewYouveGotA".localized()
case .noNameNoPreview: case .noNameNoPreview:
notificationContent.title = Singleton.appContext.appName notificationContent.title = Singleton.appName
notificationContent.body = "messageNewYouveGotA".localized() notificationContent.body = "messageNewYouveGotA".localized()
} }
// If it's a message request then overwrite the body to be something generic (only show a notification // 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) // when receiving a new message request if there aren't any others or the user had hidden them)
if isMessageRequest { if isMessageRequest {
notificationContent.title = Singleton.appContext.appName notificationContent.title = Singleton.appName
notificationContent.body = "messageRequestsNew".localized() notificationContent.body = "messageRequestsNew".localized()
} }
@ -159,7 +159,7 @@ public class NSENotificationPresenter: NSObject, NotificationsProtocol {
.map { NSNumber(value: $0) } .map { NSNumber(value: $0) }
.defaulting(to: NSNumber(value: 0)) .defaulting(to: NSNumber(value: 0))
notificationContent.title = Singleton.appContext.appName notificationContent.title = Singleton.appName
notificationContent.body = "" notificationContent.body = ""
let senderName: String = Profile.displayName(db, id: interaction.authorId, threadVariant: thread.variant) 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 } guard !isMessageRequest else { return }
let senderName: String = Profile.displayName(db, id: reaction.authorId, threadVariant: thread.variant) let senderName: String = Profile.displayName(db, id: reaction.authorId, threadVariant: thread.variant)
let notificationTitle = Singleton.appContext.appName let notificationTitle = Singleton.appName
var notificationBody = "emojiReactsHoverName" var notificationBody = "emojiReactsHoverName"
.put(key: "name", value: senderName) .put(key: "name", value: senderName)
.put(key: "emoji", value: reaction.emoji) .put(key: "emoji", value: reaction.emoji)

@ -345,7 +345,7 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
private func handleFailureForVoIP(_ db: Database, for callMessage: CallMessage) { private func handleFailureForVoIP(_ db: Database, for callMessage: CallMessage) {
let notificationContent = UNMutableNotificationContent() let notificationContent = UNMutableNotificationContent()
notificationContent.userInfo = [ NotificationServiceExtension.isFromRemoteKey : true ] notificationContent.userInfo = [ NotificationServiceExtension.isFromRemoteKey : true ]
notificationContent.title = Singleton.appContext.appName notificationContent.title = Singleton.appName
notificationContent.badge = (try? Interaction.fetchUnreadCount(db)) notificationContent.badge = (try? Interaction.fetchUnreadCount(db))
.map { NSNumber(value: $0) } .map { NSNumber(value: $0) }
.defaulting(to: 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)") NSLog("[NotificationServiceExtension] Show generic failure message due to error: \(error)")
Storage.suspendDatabaseAccess() Storage.suspendDatabaseAccess()
content.title = Singleton.appContext.appName content.title = Singleton.appName
content.body = "messageNewYouveGotA".localized() content.body = "messageNewYouveGotA".localized()
let userInfo: [String: Any] = [ NotificationServiceExtension.isFromRemoteKey: true ] let userInfo: [String: Any] = [ NotificationServiceExtension.isFromRemoteKey: true ]
content.userInfo = userInfo content.userInfo = userInfo

@ -36,7 +36,7 @@ final class SAEScreenLockViewController: ScreenLockViewController {
let titleLabel: UILabel = UILabel() let titleLabel: UILabel = UILabel()
titleLabel.font = UIFont.boldSystemFont(ofSize: Values.veryLargeFontSize) titleLabel.font = UIFont.boldSystemFont(ofSize: Values.veryLargeFontSize)
titleLabel.text = "shareToSession" titleLabel.text = "shareToSession"
.put(key: "app_name", value: Singleton.appContext.appName) .put(key: "app_name", value: Singleton.appName)
.localized() .localized()
titleLabel.themeTextColor = .textPrimary titleLabel.themeTextColor = .textPrimary

@ -244,7 +244,7 @@ final class ShareNavController: UINavigationController, ShareViewDelegate {
let modal: ConfirmationModal = ConfirmationModal( let modal: ConfirmationModal = ConfirmationModal(
targetView: self.view, targetView: self.view,
info: ConfirmationModal.Info( info: ConfirmationModal.Info(
title: Singleton.appContext.appName, title: Singleton.appName,
body: .text(error.localizedDescription), body: .text(error.localizedDescription),
cancelTitle: "okay".localized(), cancelTitle: "okay".localized(),
cancelStyle: .alert_text, cancelStyle: .alert_text,

@ -30,7 +30,7 @@ final class ThreadPickerVC: UIViewController, UITableViewDataSource, UITableView
let titleLabel: UILabel = UILabel() let titleLabel: UILabel = UILabel()
titleLabel.font = .boldSystemFont(ofSize: Values.veryLargeFontSize) titleLabel.font = .boldSystemFont(ofSize: Values.veryLargeFontSize)
titleLabel.text = "shareToSession" titleLabel.text = "shareToSession"
.put(key: "app_name", value: Singleton.appContext.appName) .put(key: "app_name", value: Singleton.appName)
.localized() .localized()
titleLabel.themeTextColor = .textPrimary titleLabel.themeTextColor = .textPrimary

@ -12,6 +12,8 @@ public extension Singleton {
static var hasAppContext: Bool { _appContext.wrappedValue != nil } static var hasAppContext: Bool { _appContext.wrappedValue != nil }
static func setup(appContext: AppContext) { _appContext.mutate { $0 = appContext } } static func setup(appContext: AppContext) { _appContext.mutate { $0 = appContext } }
static var appName: String { "Session" } // stringlint:disable
} }
// MARK: - AppContext // MARK: - AppContext
@ -24,7 +26,6 @@ public protocol AppContext: AnyObject {
var reportedApplicationState: UIApplication.State { get } var reportedApplicationState: UIApplication.State { get }
var mainWindow: UIWindow? { get } var mainWindow: UIWindow? { get }
var isRTL: Bool { get } var isRTL: Bool { get }
var appName: String { get }
var frontmostViewController: UIViewController? { get } var frontmostViewController: UIViewController? { get }
func setMainWindow(_ mainWindow: UIWindow) func setMainWindow(_ mainWindow: UIWindow)
@ -49,8 +50,6 @@ public extension AppContext {
var isInBackground: Bool { reportedApplicationState == .background } var isInBackground: Bool { reportedApplicationState == .background }
var isAppForegroundAndActive: Bool { reportedApplicationState == .active } var isAppForegroundAndActive: Bool { reportedApplicationState == .active }
var appName: String { "Session" }
// MARK: - Paths // MARK: - Paths
var appUserDefaults: UserDefaults { var appUserDefaults: UserDefaults {

@ -291,7 +291,7 @@ public class MediaMessageView: UIView {
// If we have no link preview info at this point then assume link previews are disabled // If we have no link preview info at this point then assume link previews are disabled
else { else {
label.text = "linkPreviewsTurnedOffDescription" label.text = "linkPreviewsTurnedOffDescription"
.put(key: "app_name", value: Singleton.appContext.appName) .put(key: "app_name", value: Singleton.appName)
.localized() .localized()
label.themeTextColor = .textPrimary label.themeTextColor = .textPrimary
label.textAlignment = .center label.textAlignment = .center

Loading…
Cancel
Save