2020-03-18 21:48:44 +01:00
//
// A c c o u n t s A d d C l o u d K i t W i n d o w C o n t r o l l e r . s w i f t
// N e t N e w s W i r e
//
// C r e a t e d b y M a u r i c e P a r k e r o n 3 / 1 8 / 2 0 .
// C o p y r i g h t © 2 0 2 0 R a n c h e r o S o f t w a r e . A l l r i g h t s r e s e r v e d .
//
import Foundation
import Account
2021-06-18 02:05:39 +02:00
enum AccountsAddCloudKitWindowControllerError : LocalizedError {
case iCloudDriveMissing
var errorDescription : String ? {
return NSLocalizedString ( " Unable to add iCloud Account. Please make sure you have iCloud and iCloud enabled in System Preferences. " , comment : " Unable to add iCloud Account. " )
}
}
2020-03-18 21:48:44 +01:00
class AccountsAddCloudKitWindowController : NSWindowController {
private weak var hostWindow : NSWindow ?
convenience init ( ) {
self . init ( windowNibName : NSNib . Name ( " AccountsAddCloudKit " ) )
}
override func windowDidLoad ( ) {
super . windowDidLoad ( )
}
// MARK: A P I
func runSheetOnWindow ( _ hostWindow : NSWindow , completion : ( ( NSApplication . ModalResponse ) -> Void ) ? = nil ) {
self . hostWindow = hostWindow
hostWindow . beginSheet ( window ! , completionHandler : completion )
}
// MARK: A c t i o n s
@IBAction func cancel ( _ sender : Any ) {
hostWindow ! . endSheet ( window ! , returnCode : NSApplication . ModalResponse . cancel )
}
@IBAction func create ( _ sender : Any ) {
2021-06-18 02:05:39 +02:00
guard FileManager . default . ubiquityIdentityToken != nil else {
NSApplication . shared . presentError ( AccountsAddCloudKitWindowControllerError . iCloudDriveMissing )
return
}
2020-04-01 23:45:29 +02:00
let _ = AccountManager . shared . createAccount ( type : . cloudKit )
2020-03-18 21:48:44 +01:00
hostWindow ! . endSheet ( window ! , returnCode : NSApplication . ModalResponse . OK )
}
}