aboutsummaryrefslogblamecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS/ImportPanelPresenter.swift
blob: 67b074c9efa5dc0f5c43feb7ef63879dec55d408 (plain) (tree)
1
2
3
4
5
6
7
8
9
                               
                                                             



                            

                                                                                                 
                                     
                                                     
                                                    
                                                


                                                                                  
                                                                              
                                                                                                                                                      
             


         
// SPDX-License-Identifier: MIT
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.

import Cocoa

class ImportPanelPresenter {
    static func presentImportPanel(tunnelsManager: TunnelsManager, sourceVC: NSViewController?) {
        guard let window = sourceVC?.view.window else { return }
        let openPanel = NSOpenPanel()
        openPanel.prompt = tr("macSheetButtonImport")
        openPanel.allowedFileTypes = ["conf", "zip"]
        openPanel.allowsMultipleSelection = true
        openPanel.beginSheetModal(for: window) { [weak tunnelsManager] response in
            guard let tunnelsManager = tunnelsManager else { return }
            guard response == .OK else { return }
            AppStorePrivacyNotice.show(from: sourceVC, into: tunnelsManager) {
                TunnelImporter.importFromFile(urls: openPanel.urls, into: tunnelsManager, sourceVC: sourceVC, errorPresenterType: ErrorPresenter.self)
            }
        }
    }
}