diff --git a/Swiftgram/SGAppGroupIdentifier/Sources/SGAppGroupIdentifier.swift b/Swiftgram/SGAppGroupIdentifier/Sources/SGAppGroupIdentifier.swift index cf17a07f94..bf27bae754 100644 --- a/Swiftgram/SGAppGroupIdentifier/Sources/SGAppGroupIdentifier.swift +++ b/Swiftgram/SGAppGroupIdentifier/Sources/SGAppGroupIdentifier.swift @@ -1,6 +1,6 @@ import Foundation -let fallbackBaseBundleId: String = "app.swiftgram.ios" +public let FALLBACK_BASE_BUNDLE_ID: String = "app.swiftgram.ios" public func sgAppGroupIdentifier() -> String { let baseBundleId: String @@ -9,13 +9,13 @@ public func sgAppGroupIdentifier() -> String { if let lastDotRange: Range = bundleId.range(of: ".", options: [.backwards]) { baseBundleId = String(bundleId[.. String { return appGroupPath + "/telegram-data" } -public final class SGLogger { - private let queue = Queue(name: "app.swiftgram.ios.log", qos: .utility) +public class SGLogger { + public let queue = Queue(name: "app.swiftgram.ios.log", qos: .utility) private let maxLength: Int = 2 * 1024 * 1024 private let maxShortLength: Int = 1 * 1024 * 1024 private let maxFiles: Int = 20 - private let rootPath: String - private let basePath: String + public let rootPath: String + public let basePath: String private var file: (ManagedFile, Int)? private var shortFile: (ManagedFile, Int)? @@ -66,59 +66,6 @@ public final class SGLogger { self.basePath = basePath } - public func collectLogs(prefix: String? = nil) -> Signal<[(String, String)], NoError> { - return Signal { subscriber in - self.queue.async { - let logsPath: String - if let prefix = prefix { - logsPath = self.rootPath + prefix - } else { - logsPath = self.basePath - } - - var result: [(Date, String, String)] = [] - if let files = try? FileManager.default.contentsOfDirectory(at: URL(fileURLWithPath: logsPath), includingPropertiesForKeys: [URLResourceKey.creationDateKey], options: []) { - for url in files { - if url.lastPathComponent.hasPrefix("log-") { - if let creationDate = (try? url.resourceValues(forKeys: Set([.creationDateKey])))?.creationDate { - result.append((creationDate, url.lastPathComponent, url.path)) - } - } - } - } - result.sort(by: { $0.0 < $1.0 }) - subscriber.putNext(result.map { ($0.1, $0.2) }) - subscriber.putCompletion() - } - - return EmptyDisposable - } - } - - public func collectLogs(basePath: String) -> Signal<[(String, String)], NoError> { - return Signal { subscriber in - self.queue.async { - let logsPath: String = basePath - - var result: [(Date, String, String)] = [] - if let files = try? FileManager.default.contentsOfDirectory(at: URL(fileURLWithPath: logsPath), includingPropertiesForKeys: [URLResourceKey.creationDateKey], options: []) { - for url in files { - if url.lastPathComponent.hasPrefix("log-") { - if let creationDate = (try? url.resourceValues(forKeys: Set([.creationDateKey])))?.creationDate { - result.append((creationDate, url.lastPathComponent, url.path)) - } - } - } - } - result.sort(by: { $0.0 < $1.0 }) - subscriber.putNext(result.map { ($0.1, $0.2) }) - subscriber.putCompletion() - } - - return EmptyDisposable - } - } - public func log(_ tag: String, _ what: @autoclosure () -> String) { if !self.logToFile && !self.logToConsole { return diff --git a/Swiftgram/SGLoggingComposer/BUILD b/Swiftgram/SGLoggingComposer/BUILD new file mode 100644 index 0000000000..bce950b161 --- /dev/null +++ b/Swiftgram/SGLoggingComposer/BUILD @@ -0,0 +1,19 @@ +load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") + +swift_library( + name = "SGLoggingComposer", + module_name = "SGLoggingComposer", + srcs = glob([ + "Sources/**/*.swift", + ]), + copts = [ + "-warnings-as-errors", + ], + deps = [ + "//Swiftgram/SGLogging:SGLogging", + "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit", + ], + visibility = [ + "//visibility:public", + ], +) \ No newline at end of file diff --git a/Swiftgram/SGLoggingComposer/Sources/SGLoggingComposer.swift b/Swiftgram/SGLoggingComposer/Sources/SGLoggingComposer.swift new file mode 100644 index 0000000000..726f014db1 --- /dev/null +++ b/Swiftgram/SGLoggingComposer/Sources/SGLoggingComposer.swift @@ -0,0 +1,59 @@ +import Foundation +import SGLogging +import SwiftSignalKit + + +extension SGLogger { + public func collectLogs(prefix: String? = nil) -> Signal<[(String, String)], NoError> { + return Signal { subscriber in + self.queue.async { + let logsPath: String + if let prefix = prefix { + logsPath = self.rootPath + prefix + } else { + logsPath = self.basePath + } + + var result: [(Date, String, String)] = [] + if let files = try? FileManager.default.contentsOfDirectory(at: URL(fileURLWithPath: logsPath), includingPropertiesForKeys: [URLResourceKey.creationDateKey], options: []) { + for url in files { + if url.lastPathComponent.hasPrefix("log-") { + if let creationDate = (try? url.resourceValues(forKeys: Set([.creationDateKey])))?.creationDate { + result.append((creationDate, url.lastPathComponent, url.path)) + } + } + } + } + result.sort(by: { $0.0 < $1.0 }) + subscriber.putNext(result.map { ($0.1, $0.2) }) + subscriber.putCompletion() + } + + return EmptyDisposable + } + } + + public func collectLogs(basePath: String) -> Signal<[(String, String)], NoError> { + return Signal { subscriber in + self.queue.async { + let logsPath: String = basePath + + var result: [(Date, String, String)] = [] + if let files = try? FileManager.default.contentsOfDirectory(at: URL(fileURLWithPath: logsPath), includingPropertiesForKeys: [URLResourceKey.creationDateKey], options: []) { + for url in files { + if url.lastPathComponent.hasPrefix("log-") { + if let creationDate = (try? url.resourceValues(forKeys: Set([.creationDateKey])))?.creationDate { + result.append((creationDate, url.lastPathComponent, url.path)) + } + } + } + } + result.sort(by: { $0.0 < $1.0 }) + subscriber.putNext(result.map { ($0.1, $0.2) }) + subscriber.putCompletion() + } + + return EmptyDisposable + } + } +} diff --git a/Swiftgram/SGSettingsUI/Sources/SGSettingsController.swift b/Swiftgram/SGSettingsUI/Sources/SGSettingsController.swift index 4ba0f5ebb9..8431704df1 100644 --- a/Swiftgram/SGSettingsUI/Sources/SGSettingsController.swift +++ b/Swiftgram/SGSettingsUI/Sources/SGSettingsController.swift @@ -182,7 +182,7 @@ private func SGControllerEntries(presentationData: PresentationData, callListSet entries.append(.toggle(id: id.count, section: .stories, settingName: .hideStories, value: SGSettings.hideStories, text: i18n("Settings.Stories.Hide", lang), enabled: true)) entries.append(.toggle(id: id.count, section: .stories, settingName: .disableSwipeToRecordStory, value: SGSimpleSettings.shared.disableSwipeToRecordStory, text: i18n("Settings.Stories.DisableSwipeToRecord", lang), enabled: true)) entries.append(.toggle(id: id.count, section: .stories, settingName: .warnOnStoriesOpen, value: SGSettings.warnOnStoriesOpen, text: i18n("Settings.Stories.WarnBeforeView", lang), enabled: true)) - entries.append(.toggle(id: id.count, section: .stories, settingName: .showRepostToStory, value: SGSimpleSettings.shared.showRepostToStory, text: presentationData.strings.Share_RepostToStory.replacingOccurrences(of: "\n", with: " "), enabled: true)) + entries.append(.toggle(id: id.count, section: .stories, settingName: .showRepostToStory, value: SGSimpleSettings.shared.showRepostToStoryV2, text: presentationData.strings.Share_RepostToStory.replacingOccurrences(of: "\n", with: " "), enabled: true)) if SGSimpleSettings.shared.canUseStealthMode { entries.append(.toggle(id: id.count, section: .stories, settingName: .storyStealthMode, value: SGSimpleSettings.shared.storyStealthMode, text: presentationData.strings.Story_StealthMode_Title, enabled: true)) entries.append(.notice(id: id.count, section: .stories, text: presentationData.strings.Story_StealthMode_ControlText)) @@ -410,7 +410,7 @@ public func sgSettingsController(context: AccountContext/*, focusOnItemTag: Int? case .hideReactions: SGSimpleSettings.shared.hideReactions = value case .showRepostToStory: - SGSimpleSettings.shared.showRepostToStory = value + SGSimpleSettings.shared.showRepostToStoryV2 = value case .contextShowSelectFromUser: SGSimpleSettings.shared.contextShowSelectFromUser = value case .contextShowSaveToCloud: diff --git a/Swiftgram/SGSimpleSettings/BUILD b/Swiftgram/SGSimpleSettings/BUILD index b43e660d31..cd8266c43a 100644 --- a/Swiftgram/SGSimpleSettings/BUILD +++ b/Swiftgram/SGSimpleSettings/BUILD @@ -11,6 +11,7 @@ swift_library( ], deps = [ "//Swiftgram/SGAppGroupIdentifier:SGAppGroupIdentifier", + "//Swiftgram/SGLogging:SGLogging", ], visibility = [ "//visibility:public", diff --git a/Swiftgram/SGSimpleSettings/Sources/SimpleSettings.swift b/Swiftgram/SGSimpleSettings/Sources/SimpleSettings.swift index 74d0471d6c..499ad957f6 100644 --- a/Swiftgram/SGSimpleSettings/Sources/SimpleSettings.swift +++ b/Swiftgram/SGSimpleSettings/Sources/SimpleSettings.swift @@ -1,5 +1,6 @@ import Foundation import SGAppGroupIdentifier +import SGLogging let APP_GROUP_IDENTIFIER = sgAppGroupIdentifier() @@ -9,6 +10,7 @@ public class SGSimpleSettings { private init() { setDefaultValues() + migrate() preCacheValues() } @@ -21,6 +23,19 @@ public class SGSimpleSettings { } } + private func migrate() { + let showRepostToStoryMigrationKey = "migrated_\(Keys.showRepostToStory.rawValue)" + if let groupUserDefaults = UserDefaults(suiteName: APP_GROUP_IDENTIFIER) { + if !groupUserDefaults.bool(forKey: showRepostToStoryMigrationKey) { + self.showRepostToStoryV2 = self.showRepostToStory + groupUserDefaults.set(true, forKey: showRepostToStoryMigrationKey) + SGLogger.shared.log("SGSimpleSettings", "Migrated showRepostToStory. \(self.showRepostToStory) -> \(self.showRepostToStoryV2)") + } + } else { + SGLogger.shared.log("SGSimpleSettings", "Unable to migrate showRepostToStory. Shared UserDefaults suite is not available for '\(APP_GROUP_IDENTIFIER)'.") + } + } + private func preCacheValues() { // let dispatchGroup = DispatchGroup() @@ -82,6 +97,7 @@ public class SGSimpleSettings { case outgoingLanguageTranslation case hideReactions case showRepostToStory + case showRepostToStoryV2 case contextShowSelectFromUser case contextShowSaveToCloud case contextShowRestrict @@ -272,7 +288,8 @@ public class SGSimpleSettings { Keys.legacyNotificationsFix.rawValue: false, Keys.pinnedMessageNotifications.rawValue: PinnedMessageNotificationsSettings.default.rawValue, Keys.mentionsAndRepliesNotifications.rawValue: MentionsAndRepliesNotificationsSettings.default.rawValue, - Keys.status.rawValue: 1 + Keys.status.rawValue: 1, + Keys.showRepostToStoryV2.rawValue: true, ] @UserDefault(key: Keys.hidePhoneInSettings.rawValue) @@ -327,9 +344,13 @@ public class SGSimpleSettings { @UserDefault(key: Keys.hideReactions.rawValue) public var hideReactions: Bool + // @available(*, deprecated, message: "Use showRepostToStoryV2 instead") @UserDefault(key: Keys.showRepostToStory.rawValue) public var showRepostToStory: Bool + @UserDefault(key: Keys.showRepostToStoryV2.rawValue, userDefaults: UserDefaults(suiteName: APP_GROUP_IDENTIFIER) ?? .standard) + public var showRepostToStoryV2: Bool + @UserDefault(key: Keys.contextShowRestrict.rawValue) public var contextShowRestrict: Bool diff --git a/submodules/DebugSettingsUI/BUILD b/submodules/DebugSettingsUI/BUILD index 439190310e..970b8c1883 100644 --- a/submodules/DebugSettingsUI/BUILD +++ b/submodules/DebugSettingsUI/BUILD @@ -3,6 +3,7 @@ load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") sgdeps = [ "//Swiftgram/SGDebugUI:SGDebugUI", "//Swiftgram/SGLogging:SGLogging", + "//Swiftgram/SGLoggingComposer:SGLoggingComposer", "//Swiftgram/SGSimpleSettings:SGSimpleSettings" ] diff --git a/submodules/DebugSettingsUI/Sources/DebugController.swift b/submodules/DebugSettingsUI/Sources/DebugController.swift index d8abb2e1f3..c70c29c1cd 100644 --- a/submodules/DebugSettingsUI/Sources/DebugController.swift +++ b/submodules/DebugSettingsUI/Sources/DebugController.swift @@ -1,5 +1,6 @@ // MARK: Swiftgram import SGLogging +import SGLoggingComposer import SGSimpleSettings import SGDebugUI diff --git a/submodules/ShareController/Sources/SharePeersContainerNode.swift b/submodules/ShareController/Sources/SharePeersContainerNode.swift index 6fd216c858..33f9589384 100644 --- a/submodules/ShareController/Sources/SharePeersContainerNode.swift +++ b/submodules/ShareController/Sources/SharePeersContainerNode.swift @@ -164,7 +164,7 @@ final class SharePeersContainerNode: ASDisplayNode, ShareContentContainerNode { self.peersValue.set(.single(peers)) - let canShareStory = controllerInteraction.shareStory != nil && SGSimpleSettings.shared.showRepostToStory + let canShareStory = controllerInteraction.shareStory != nil && SGSimpleSettings.shared.showRepostToStoryV2 let items: Signal<[SharePeerEntry], NoError> = combineLatest(self.peersValue.get(), self.foundPeers.get(), self.tick.get(), self.themePromise.get()) |> map { [weak controllerInteraction] initialPeers, foundPeers, _, theme -> [SharePeerEntry] in