mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Notifications (#275)
This commit is contained in:
@@ -26,13 +26,15 @@ final class ElementSettings: ObservableObject {
|
||||
case enableAnalytics
|
||||
case isIdentifiedForAnalytics
|
||||
case slidingSyncProxyBaseURLString
|
||||
case enableInAppNotifications
|
||||
case pusherProfileTag
|
||||
}
|
||||
|
||||
static let shared = ElementSettings()
|
||||
|
||||
/// UserDefaults to be used on reads and writes.
|
||||
static var store: UserDefaults {
|
||||
guard let userDefaults = UserDefaults(suiteName: ElementInfoPlist.appGroupIdentifier) else {
|
||||
guard let userDefaults = UserDefaults(suiteName: InfoPlistReader.target.appGroupIdentifier) else {
|
||||
fatalError("Fail to load shared UserDefaults")
|
||||
}
|
||||
return userDefaults
|
||||
@@ -63,9 +65,18 @@ final class ElementSettings: ObservableObject {
|
||||
|
||||
@AppStorage(UserDefaultsKeys.timelineStyle.rawValue, store: store)
|
||||
var timelineStyle = BuildSettings.defaultRoomTimelineStyle
|
||||
|
||||
|
||||
// MARK: - Client
|
||||
|
||||
|
||||
@AppStorage(UserDefaultsKeys.slidingSyncProxyBaseURLString.rawValue, store: store)
|
||||
var slidingSyncProxyBaseURLString = BuildSettings.defaultSlidingSyncProxyBaseURLString
|
||||
|
||||
// MARK: - Notifications
|
||||
|
||||
@AppStorage(UserDefaultsKeys.enableInAppNotifications.rawValue, store: store)
|
||||
var enableInAppNotifications = true
|
||||
|
||||
@AppStorage(UserDefaultsKeys.pusherProfileTag.rawValue, store: store)
|
||||
/// Tag describing which set of device specific rules a pusher executes.
|
||||
var pusherProfileTag: String?
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension FileManager {
|
||||
func directoryExists(at url: URL) -> Bool {
|
||||
var isDirectory: ObjCBool = false
|
||||
guard fileExists(atPath: url.path(), isDirectory: &isDirectory) else {
|
||||
return false
|
||||
}
|
||||
return isDirectory.boolValue
|
||||
}
|
||||
|
||||
func createDirectoryIfNeeded(at url: URL, withIntermediateDirectories: Bool = true) throws {
|
||||
guard !directoryExists(at: url) else {
|
||||
return
|
||||
}
|
||||
try createDirectory(at: url, withIntermediateDirectories: withIntermediateDirectories)
|
||||
}
|
||||
}
|
||||
@@ -23,4 +23,10 @@ extension ImageCache {
|
||||
result.diskStorage.config.sizeLimit = 1
|
||||
return result
|
||||
}
|
||||
|
||||
static var onlyOnDisk: ImageCache {
|
||||
let result = ImageCache.default
|
||||
result.memoryStorage.config.totalCostLimit = 1
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,6 @@ extension UIDevice {
|
||||
}
|
||||
|
||||
var initialDisplayName: String {
|
||||
ElementL10n.defaultSessionDisplayName(ElementInfoPlist.cfBundleDisplayName)
|
||||
ElementL10n.defaultSessionDisplayName(InfoPlistReader.target.bundleDisplayName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,4 +24,33 @@ extension URL {
|
||||
|
||||
self = url
|
||||
}
|
||||
|
||||
/// The URL of the primary app group container.
|
||||
static var appGroupContainerDirectory: URL {
|
||||
guard let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: InfoPlistReader.target.appGroupIdentifier) else {
|
||||
fatalError("Should always be able to retrieve the container directory")
|
||||
}
|
||||
return url
|
||||
}
|
||||
|
||||
/// The base directory where all session data is stored.
|
||||
static var sessionsBaseDirectory: URL {
|
||||
let url = cacheBaseDirectory
|
||||
.appendingPathComponent("Sessions", isDirectory: true)
|
||||
|
||||
try? FileManager.default.createDirectoryIfNeeded(at: url)
|
||||
|
||||
return url
|
||||
}
|
||||
|
||||
/// The base directory where all cache is stored.
|
||||
static var cacheBaseDirectory: URL {
|
||||
let url = appGroupContainerDirectory
|
||||
.appendingPathComponent("Library", isDirectory: true)
|
||||
.appendingPathComponent("Caches", isDirectory: true)
|
||||
|
||||
try? FileManager.default.createDirectoryIfNeeded(at: url)
|
||||
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct InfoPlistReader {
|
||||
private enum Keys {
|
||||
static let appGroupIdentifier = "appGroupIdentifier"
|
||||
static let baseBundleIdentifier = "baseBundleIdentifier"
|
||||
static let bundleShortVersion = "CFBundleShortVersionString"
|
||||
static let bundleDisplayName = "CFBundleDisplayName"
|
||||
}
|
||||
|
||||
/// Info.plist reader on the current target
|
||||
static let target = InfoPlistReader(bundle: .main)
|
||||
|
||||
private let bundle: Bundle
|
||||
|
||||
/// Initializer
|
||||
/// - Parameter bundle: bundle to read values from
|
||||
init(bundle: Bundle) {
|
||||
self.bundle = bundle
|
||||
}
|
||||
|
||||
/// App group identifier set in Info.plist of the target
|
||||
var appGroupIdentifier: String {
|
||||
infoPlistStringValue(forKey: Keys.appGroupIdentifier)
|
||||
}
|
||||
|
||||
/// Base bundle identifier set in Info.plist of the target
|
||||
var baseBundleIdentifier: String {
|
||||
infoPlistStringValue(forKey: Keys.baseBundleIdentifier)
|
||||
}
|
||||
|
||||
/// Bundle executable of the target
|
||||
var bundleExecutable: String {
|
||||
infoPlistStringValue(forKey: kCFBundleExecutableKey as String)
|
||||
}
|
||||
|
||||
/// Bundle identifier of the target
|
||||
var bundleIdentifier: String {
|
||||
infoPlistStringValue(forKey: kCFBundleIdentifierKey as String)
|
||||
}
|
||||
|
||||
/// Bundle short version string of the target
|
||||
var bundleShortVersionString: String {
|
||||
infoPlistStringValue(forKey: Keys.bundleShortVersion)
|
||||
}
|
||||
|
||||
/// Bundle version of the target
|
||||
var bundleVersion: String {
|
||||
infoPlistStringValue(forKey: kCFBundleVersionKey as String)
|
||||
}
|
||||
|
||||
/// Bundle display name of the target
|
||||
var bundleDisplayName: String {
|
||||
infoPlistStringValue(forKey: Keys.bundleDisplayName)
|
||||
}
|
||||
|
||||
private func infoPlistStringValue(forKey key: String) -> String {
|
||||
guard let result = bundle.object(forInfoDictionaryKey: key) as? String else {
|
||||
fatalError("Add \(key) into your target's Info.plst")
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -150,9 +150,9 @@ class MXLogger {
|
||||
MXLogger.logCrashes(false)
|
||||
|
||||
// Extract running app information
|
||||
let app = ElementInfoPlist.cfBundleExecutable
|
||||
let appId = ElementInfoPlist.cfBundleIdentifier
|
||||
let appVersion = "\(ElementInfoPlist.cfBundleShortVersionString) (r\(ElementInfoPlist.cfBundleVersion))"
|
||||
let app = InfoPlistReader.target.bundleExecutable
|
||||
let appId = InfoPlistReader.target.bundleIdentifier
|
||||
let appVersion = "\(InfoPlistReader.target.bundleShortVersionString) (r\(InfoPlistReader.target.bundleVersion))"
|
||||
|
||||
// Build the crash log
|
||||
let model = UIDevice.current.model
|
||||
@@ -269,7 +269,7 @@ class MXLogger {
|
||||
|
||||
/// The folder where logs are stored
|
||||
private static var logsFolderURL: URL {
|
||||
FileManager.default.appGroupContainerURL ?? URL.documentsDirectory
|
||||
.appGroupContainerDirectory
|
||||
}
|
||||
|
||||
/// If `self.redirectNSLog(toFiles:numberOfFiles:)` is called with a lower numberOfFiles we need to do some cleanup.
|
||||
|
||||
@@ -27,8 +27,8 @@ final class UserAgentBuilder {
|
||||
}
|
||||
|
||||
private class func makeUserAgent() -> String? {
|
||||
let clientName = ElementInfoPlist.cfBundleDisplayName
|
||||
let clientVersion = ElementInfoPlist.cfBundleShortVersionString
|
||||
let clientName = InfoPlistReader.target.bundleDisplayName
|
||||
let clientVersion = InfoPlistReader.target.bundleShortVersionString
|
||||
|
||||
#if os(iOS)
|
||||
return String(
|
||||
|
||||
Reference in New Issue
Block a user