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. " )
}
}
2024-05-06 02:23:54 +02:00
final class AccountsAddCloudKitWindowController : NSWindowController {
2020-03-18 21:48:44 +01:00
private weak var hostWindow : NSWindow ?
convenience init ( ) {
self . init ( windowNibName : NSNib . Name ( " AccountsAddCloudKit " ) )
}
override func windowDidLoad ( ) {
super . windowDidLoad ( )
}
// MARK: A P I
2024-05-06 02:23:54 +02:00
func runSheetOnWindow ( _ hostWindow : NSWindow ) async -> NSApplication . ModalResponse {
2020-03-18 21:48:44 +01:00
self . hostWindow = hostWindow
2024-05-06 02:23:54 +02:00
return await hostWindow . beginSheet ( window ! )
2020-03-18 21:48:44 +01:00
}
// 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 )
}
}