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(),
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,

@ -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()
)

@ -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

@ -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()
}
}

@ -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)

@ -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 {

@ -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(

@ -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

@ -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

@ -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")?

@ -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(

@ -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

@ -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()

@ -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))

@ -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(),

@ -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)

@ -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

@ -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

@ -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,

@ -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

@ -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 {

@ -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

Loading…
Cancel
Save