Skip to content

Commit

Permalink
poll translation
Browse files Browse the repository at this point in the history
  • Loading branch information
overtake committed May 1, 2024
2 parents 0b9de1f + f98fdfd commit 228d80b
Show file tree
Hide file tree
Showing 50 changed files with 662 additions and 333 deletions.
40 changes: 21 additions & 19 deletions FocusIntents/FocusIntents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,37 @@ import SwiftSignalKit
import InAppSettings
import ApiCredentials

//private let accountManager: AccountManager<TelegramAccountManagerTypes> = {
// let containerUrl = ApiEnvironment.containerURL!
// let rootPath = containerUrl.path
// return AccountManager<TelegramAccountManagerTypes>(basePath: containerUrl.path + "/accounts-metadata", isTemporary: false, isReadOnly: false, useCaches: true, removeDatabaseOnError: true)
//}()



@available(macOS 13, *)
struct FocusFilter: SetFocusFilterIntent {

@Parameter(title: "Use Dark Mode", default: nil)
var alwaysUseDarkMode: Bool?
@Parameter(title: "Use Dark Mode", description: "Automatically enable dark mode.", default: false)
var alwaysUseDarkMode: Bool

@Parameter(title: "Set Unable Status", description: "Set your account status to Unable. This feature requires Telegram Premium.", default: false)
var unableStatus: Bool


// MARK: - Filter information.
static var title: LocalizedStringResource = "Set Appearance"
static var title: LocalizedStringResource = "Set Appearance And Status"

static var description: LocalizedStringResource? = """
Configure Appearance of app in focus mode
"""

/// The dynamic representation that displays after creating a Focus filter.
var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(title: "Appearance",
subtitle: "Dark Mode")
var status: String = ""
if alwaysUseDarkMode {
status += "Dark Mode"
}
if unableStatus {
if status.isEmpty {
status += "Status"
} else {
status += ", Status"
}
}
return DisplayRepresentation(title: "Appearance And Status",
subtitle: LocalizedStringResource(stringLiteral: status))
}


Expand All @@ -50,18 +55,15 @@ struct FocusFilter: SetFocusFilterIntent {
static func suggestedFocusFilters(for context: FocusFilterSuggestionContext) async -> [FocusFilter] {
let workFilter = FocusFilter()
workFilter.alwaysUseDarkMode = true
workFilter.unableStatus = true
return [workFilter]
}

func perform() async throws -> some IntentResult {
let model = AppIntentDataModel(alwaysUseDarkMode: self.alwaysUseDarkMode)
let model = AppIntentDataModel(alwaysUseDarkMode: self.alwaysUseDarkMode, useUnableStatus: self.unableStatus)
if let model = model.encoded() {
UserDefaults(suiteName: ApiEnvironment.intentsBundleId)?.set(model, forKey: AppIntentDataModel.key)
}
return .result()
}
}

extension FocusFilter {

}
46 changes: 41 additions & 5 deletions Telegram-Mac/AccountContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import InAppPurchaseManager
import ApiCredentials

let clown: String = "🤡"

let focusIntentEmoji = "⛔️"


public struct PremiumConfiguration {
Expand Down Expand Up @@ -923,6 +923,46 @@ final class AccountContext {

actionsDisposable.add(requestApplicationIcons(engine: engine).start())

let focusIntentStatus = someAccountSetings(postbox: account.postbox)
|> distinctUntilChanged(isEqual: {
$0.focusIntentStatusEnabled == $1.focusIntentStatusEnabled &&
$0.focusIntentStatusActive == $1.focusIntentStatusActive
})
|> deliverOnMainQueue

actionsDisposable.add(focusIntentStatus.startStandalone(next: { [weak self] settings in
guard let self else {
return
}
let setStatus:(Int64?)->Void = { [weak self] fileId in
guard let self else {
return
}
if let fileId {
let file = self.inlinePacksContext.load(fileId: fileId) |> deliverOnMainQueue
_ = file.startStandalone(next: { file in
_ = engine.accountData.setEmojiStatus(file: file, expirationDate: nil).start()
})
} else {
_ = engine.accountData.setEmojiStatus(file: nil, expirationDate: nil).start()
}
}
if settings.focusIntentStatusEnabled {
if let fileId = settings.focusIntentStatusActive {
setStatus(fileId)
} else {
_ = (self.diceCache.top_emojies_status |> deliverOnMainQueue).startStandalone(next: { files in
if let file = files.first(where: { $0.customEmojiText == focusIntentEmoji }) {
setStatus(file.fileId.id)
}
})
}
} else if let fileId = settings.focusIntentStatusFallback {
setStatus(fileId)
} else {
setStatus(nil)
}
}))

#endif

Expand All @@ -942,10 +982,6 @@ final class AccountContext {
actionsDisposable.add(autologinToken.start(next: { [weak self] token in
self?.autologinToken = token.autologinToken
}))

(additionalSettings(accountManager: sharedContext.accountManager) |> deliverOnMainQueue).start(next: { value in
NSLog("dark mode in focus = \(value.alwaysDarkMode)")
})
}

@objc private func updateKeyWindow() {
Expand Down
70 changes: 62 additions & 8 deletions Telegram-Mac/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ class AppIntentObserver : NSObject {

private let defaults = UserDefaults(suiteName: ApiEnvironment.intentsBundleId)!

private var current: AppIntentDataModel?

override init() {
super.init()
let modelData = defaults.value(forKey: AppIntentDataModel.keyInternal) as? Data
if let modelData, let model = AppIntentDataModel.decoded(modelData) {
self.current = model
}
defaults.addObserver(self, forKeyPath: AppIntentDataModel.key, options: .new, context: nil)
}

Expand All @@ -60,11 +66,19 @@ class AppIntentObserver : NSObject {

func update() {
let modelData = defaults.value(forKey: AppIntentDataModel.key) as? Data
if let modelData, let model = AppIntentDataModel.decoded(modelData) {
onUpdate?(model)
let model: AppIntentDataModel?
if let modelData, let value = AppIntentDataModel.decoded(modelData) {
model = value
} else {
onUpdate?(nil)
model = nil
}
if let model = model {
defaults.setValue(model.encoded(), forKey: AppIntentDataModel.keyInternal)
}
if model != self.current {
self.onUpdate?(model)
}
self.current = model
}

public static let shared: AppIntentObserver = AppIntentObserver()
Expand Down Expand Up @@ -781,6 +795,43 @@ class AppDelegate: NSResponder, NSApplicationDelegate, NSUserNotificationCenterD
return settings.withUpdatedToDefault(dark: settings.defaultIsDark)
}
}).start()

if let value = value?.useUnableStatus {

_ = (sharedContext.activeAccountsWithInfo |> deliverOnMainQueue |> take(1)).startStandalone(next: { accounts in
for account in accounts.1 {
_ = updateSomeSettingsInteractively(postbox: account.account.postbox, { current in
var current = current
if value {
current.focusIntentStatusFallback = account.peer.emojiStatus?.fileId
}
current.focusIntentStatusEnabled = value
return current
}).startStandalone()
}
})

if value {


/*
let files = context.diceCache.top_emojies_status |> deliverOnMainQueue
_ = files.startStandalone(next: { files in
if let file = files.first(where: { $0.customEmojiText == "⛔️" }) {
_ = context.engine.accountData.setEmojiStatus(file: file, expirationDate: nil).start()
}
})
*/

if let context = self.contextValue?.context {

}


} else {

}
}
}
AppIntentObserver.shared.update()
}
Expand Down Expand Up @@ -1359,13 +1410,16 @@ class AppDelegate: NSResponder, NSApplicationDelegate, NSUserNotificationCenterD
}

func tryApplyAutologinToken(_ url: String) -> String? {
if let context = contextValue?.context {
let config = context.appConfiguration
if let value = AutologinToken.with(appConfiguration: config, autologinToken: context.autologinToken) {
return value.applyTo(url, isTestServer: contextValue?.context.account.testingEnvironment ?? false)
var result: String?
self.enumerateAccountContexts { context in
if context.window == NSApp.keyWindow {
let config = context.appConfiguration
if let value = AutologinToken.with(appConfiguration: config, autologinToken: context.autologinToken) {
result = value.applyTo(url, isTestServer: contextValue?.context.account.testingEnvironment ?? false)
}
}
}
return nil
return result
}

func applicationDidHide(_ notification: Notification) {
Expand Down
23 changes: 8 additions & 15 deletions Telegram-Mac/AppIntentDataModel.swift
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
/*
See LICENSE folder for this sample’s licensing information.
Abstract:
A data model to use for sharing information between the app and its App Intents extension.
*/

import Foundation
@available(macOS 13, *)
public struct AppIntentDataModel: Codable {
public struct AppIntentDataModel: Codable, Equatable {

static let key: String = "appIntentData"

public init(alwaysUseDarkMode: Bool? = nil) {
static let keyInternal: String = "appIntentData_Internal"

public init(alwaysUseDarkMode: Bool = false, useUnableStatus: Bool = false) {
self.alwaysUseDarkMode = alwaysUseDarkMode
self.useUnableStatus = useUnableStatus
}

public let alwaysUseDarkMode: Bool?

public var isFocusFilterEnabled: Bool {
alwaysUseDarkMode == true
}

public let alwaysUseDarkMode: Bool
public let useUnableStatus: Bool

func encoded() -> Data? {
let encoder = JSONEncoder()
do {
Expand Down
12 changes: 6 additions & 6 deletions Telegram-Mac/AppUpdateViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -317,19 +317,19 @@ private final class InternalUpdaterDownloader : SPUDownloaderSession {
self.urlSession(URLSession(), downloadTask: URLSessionDownloadTask(), didFinishDownloadingTo: URL(fileURLWithPath: path))
}
}, error: { [weak self] error in
self?.delegate.downloaderDidFailWithError(NSError(domain: "Failed to download archive. Please try again.", code: 0, userInfo: nil))
self?.delegate.downloaderDidFailWithError(NSError(domain: strings().appUpdateErrorFailedDownload, code: 0, userInfo: nil))
}))
} else {
self.delegate.downloaderDidFailWithError(NSError(domain: "Wrong internal link. Please try again.", code: 0, userInfo: nil))
self.delegate.downloaderDidFailWithError(NSError(domain: strings().appUpdateErrorWrongInternal, code: 0, userInfo: nil))
}

default:
self.delegate.downloaderDidFailWithError(NSError(domain: "Wrong internal link. Please try again.", code: 0, userInfo: nil))
self.delegate.downloaderDidFailWithError(NSError(domain: strings().appUpdateErrorWrongInternal, code: 0, userInfo: nil))
}


} else {
self.delegate.downloaderDidFailWithError(NSError(domain: "No internal link for this version. Please try again.", code: 0, userInfo: nil))
self.delegate.downloaderDidFailWithError(NSError(domain: strings().appUpdateErrorNoInternal, code: 0, userInfo: nil))
}

}
Expand Down Expand Up @@ -370,7 +370,7 @@ private final class InternalUpdateDriver : ExternalUpdateDriver {
appcast.parseAppcastItems(fromXMLData: data, error: nil)
self?.appcastDidFinishLoading(appcast)
}, error: { [weak self] error in
self?.abortUpdateWithError(NSError(domain: "Failed to download updating info. Please try again.", code: 0, userInfo: nil))
self?.abortUpdateWithError(NSError(domain: strings().appUpdateErrorFailedUpdating, code: 0, userInfo: nil))
}))
}

Expand Down Expand Up @@ -485,6 +485,7 @@ private class ExternalUpdateDriver : SUBasicUpdateDriver {
updateState { state in
return state.withUpdatedLoadingState(.failed(error as NSError? ?? NSError(domain: strings().unknownError, code: 0, userInfo: nil)))
}
trySwitchUpdaterBetweenSources()
}

override func abortUpdateWithError(_ error: Error!) {
Expand Down Expand Up @@ -571,7 +572,6 @@ private func resetUpdater() {
default:
driver?.checkForUpdates(at: URL(string: url)!, host: host, domain: updater.host)
}
NSLog("check updates: \(url)")
}


Expand Down
1 change: 0 additions & 1 deletion Telegram-Mac/ChannelEventLogItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,6 @@ private class ServiceEventLogRowView : TableRowView {

override func updateColors() {
super.updateColors()
textView.backgroundColor = backdorColor
messageContent?.updateColors(backdorColor)
}

Expand Down
Loading

0 comments on commit 228d80b

Please sign in to comment.