~handlerug/TelegramSwift

42528cfbd9f68d3bdf8b22d4903c252d1b1e745c — handlerug 3 years ago ed10636
Accounts menu bar menu
M Telegram-Mac/AppDelegate.swift => Telegram-Mac/AppDelegate.swift +3 -1
@@ 50,6 50,8 @@ class AppDelegate: NSResponder, NSApplicationDelegate, NSUserNotificationCenterD
        }
    }
    
    @IBOutlet weak var accountsMenu: MMMenu!
    
    override init() {
        super.init()
        NSAppleEventManager.shared().setEventHandler(self, andSelector: #selector(handleURLEvent(_: with:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))


@@ 386,7 388,7 @@ class AppDelegate: NSResponder, NSApplicationDelegate, NSUserNotificationCenterD
            
            let networkArguments = NetworkInitializationArguments(apiId: ApiEnvironment.apiId, apiHash: ApiEnvironment.apiHash, languagesCategory: ApiEnvironment.language, appVersion: ApiEnvironment.version, voipMaxLayer: CallBridge.voipMaxLayer(), voipVersions: [CallBridge.voipVersion()], appData: .single(ApiEnvironment.appData), autolockDeadine: .single(nil), encryptionProvider: OpenSSLEncryptionProvider())
            
            let sharedContext = SharedAccountContext(accountManager: accountManager, networkArguments: networkArguments, rootPath: rootPath, encryptionParameters: encryptionParameters, displayUpgradeProgress: displayUpgrade)
            let sharedContext = SharedAccountContext(accountManager: accountManager, networkArguments: networkArguments, rootPath: rootPath, encryptionParameters: encryptionParameters, displayUpgradeProgress: displayUpgrade, accountsMenu: self.accountsMenu)
            
            
            let rawAccounts = sharedContext.activeAccounts

M Telegram-Mac/Base.lproj/MainMenu.xib => Telegram-Mac/Base.lproj/MainMenu.xib +6 -1
@@ 15,6 15,7 @@
        <customObject id="-3" userLabel="Application" customClass="NSObject"/>
        <customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="Telegram" customModuleProvider="target">
            <connections>
                <outlet property="accountsMenu" destination="tFr-qT-lkd" id="6xa-ey-0VL"/>
                <outlet property="checkForUpdates" destination="xey-M7-XVy" id="7ii-1E-tIe"/>
                <outlet property="preferences" destination="BOF-NM-1cW" id="iiN-GN-soF"/>
                <outlet property="showQuickSwitcher" destination="sZh-ct-GQS" id="loY-ub-t4u"/>


@@ 264,6 265,10 @@
                        </items>
                    </menu>
                </menuItem>
                <menuItem title="Accounts" identifier="BNe-Pr-iCL" id="BNe-Pr-iCL" customClass="MMMenuItem" customModule="Telegram" customModuleProvider="target">
                    <modifierMask key="keyEquivalentModifierMask"/>
                    <menu key="submenu" title="Accounts" identifier="tFr-qT-lkd" id="tFr-qT-lkd" customClass="MMMenu" customModule="Telegram" customModuleProvider="target"/>
                </menuItem>
                <menuItem title="Window" identifier="aUF-d1-5bR" id="aUF-d1-5bR" customClass="MMMenuItem" customModule="Telegram" customModuleProvider="target">
                    <modifierMask key="keyEquivalentModifierMask"/>
                    <menu key="submenu" title="Window" systemMenu="window" identifier="Td7-aD-5lo" id="Td7-aD-5lo" customClass="MMMenu" customModule="Telegram" customModuleProvider="target">


@@ 302,7 307,7 @@
            <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
            <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
            <rect key="contentRect" x="335" y="390" width="480" height="360"/>
            <rect key="screenRect" x="0.0" y="0.0" width="2048" height="1129"/>
            <rect key="screenRect" x="0.0" y="0.0" width="2048" height="1152"/>
            <view key="contentView" wantsLayer="YES" id="EiT-Mj-1SZ">
                <rect key="frame" x="0.0" y="0.0" width="480" height="360"/>
                <autoresizingMask key="autoresizingMask"/>

M Telegram-Mac/SharedAccountContext.swift => Telegram-Mac/SharedAccountContext.swift +49 -2
@@ 90,6 90,7 @@ class SharedAccountContext {
    let layoutHandler:ValuePromise<SplitViewState> = ValuePromise(ignoreRepeated:true)

    private var statusItem: NSStatusItem?
    private var accountsMenu: NSMenu?

    
    func updateStatusBarImage(_ image: NSImage?) -> Void {


@@ 167,15 168,60 @@ class SharedAccountContext {
            }
        }
    }
    
    private func updateAccountsMenuBarMenu() {
        guard let menu = self.accountsMenu, let activeAccountsInfoValue = activeAccountsInfoValue else {
            return
        }
        menu.removeAllItems()
        
//        var activeAccountsInfoValue = activeAccountsInfoValue
//        for (i, value) in activeAccountsInfoValue.accounts.enumerated() {
//            if value.account.id == activeAccountsInfoValue.primary {
//                activeAccountsInfoValue.accounts.swapAt(i, 0)
//                break
//            }
//        }
        for account in activeAccountsInfoValue.accounts {
            let state: NSControl.StateValue?
            if account.account.id == activeAccountsInfoValue.primary {
                state = .on
            } else {
                state = nil
            }
            let image: NSImage?
            if let cgImage = self.accountPhotos[account.account.peerId] {
                image = NSImage(cgImage: cgImage, size: NSMakeSize(24, 24))
            } else {
                image = nil
            }
            
            menu.addItem(ContextMenuItem(account.peer.displayTitle, handler: {
                self.switchToAccount(id: account.account.id, action: nil)
            }, image: image, state: state))
        }
        
        if activeAccountsInfoValue.accounts.count < 3 {
            menu.addItem(ContextSeparatorItem())

            menu.addItem(ContextMenuItem(L10n.accountSettingsAddAccount, handler: {
                let testingEnvironment = NSApp.currentEvent?.modifierFlags.contains(.command) == true
                NSApp.activate(ignoringOtherApps: true)
                mainWindow.makeKeyAndOrderFront(nil)
                self.beginNewAuth(testingEnvironment: testingEnvironment)
            }))
        }
    }

    private let layoutDisposable = MetaDisposable()
    private let displayUpgradeProgress: (Float?) -> Void
    

    
    init(accountManager: AccountManager, networkArguments: NetworkInitializationArguments, rootPath: String, encryptionParameters: ValueBoxEncryptionParameters, displayUpgradeProgress: @escaping(Float?) -> Void) {
    init(accountManager: AccountManager, networkArguments: NetworkInitializationArguments, rootPath: String, encryptionParameters: ValueBoxEncryptionParameters, displayUpgradeProgress: @escaping(Float?) -> Void, accountsMenu: NSMenu? = nil) {
        self.accountManager = accountManager
        self.displayUpgradeProgress = displayUpgradeProgress
        self.accountsMenu = accountsMenu
        #if !SHARE
        self.accountManager.mediaBox.fetchCachedResourceRepresentation = { (resource, representation) -> Signal<CachedMediaResourceRepresentationResult, NoError> in
            return fetchCachedSharedResourceRepresentation(accountManager: accountManager, resource: resource, representation: representation)


@@ 456,7 502,7 @@ class SharedAccountContext {
        
        let signal = self.activeAccountsWithInfoPromise.get() |> mapToSignal { (primary, accounts) -> Signal<(primary: AccountRecordId?, accounts: [AccountWithInfo], [PeerId : CGImage]), NoError> in
            let photos:[Signal<(PeerId, CGImage?), NoError>] = accounts.map { info in
                return peerAvatarImage(account: info.account, photo: .peer(info.peer, info.peer.smallProfileImage, info.peer.displayLetters, nil), displayDimensions: NSMakeSize(32, 32)) |> map {
                return peerAvatarImage(account: info.account, photo: .peer(info.peer, info.peer.smallProfileImage, info.peer.displayLetters, nil), displayDimensions: NSMakeSize(48, 48)) |> map {
                    (info.account.peerId, $0.0)
                }
            }


@@ 481,6 527,7 @@ class SharedAccountContext {
            self.activeAccountsInfoValue = (primary, accounts)
            self.accountPhotos = photos
            self.updateStatusBarMenuItem()
            self.updateAccountsMenuBarMenu()
            
            #if !SHARE
            spotlights.removeAll()

M Telegram-Mac/en.lproj/Localizable.strings => Telegram-Mac/en.lproj/Localizable.strings +0 -0