Add delete from disk

This commit is contained in:
Maurice Parker 2019-05-01 19:22:07 -05:00
parent ea906de576
commit f5523dd610
3 changed files with 22 additions and 3 deletions

View File

@ -110,6 +110,22 @@ public final class AccountManager: UnreadCountProvider {
return account
}
public func deleteAccount(_ account: Account) {
accountsDictionary.removeValue(forKey: account.accountID)
do {
try FileManager.default.removeItem(atPath: account.dataFolder)
}
catch {
assertionFailure("Could not create folder for OnMyMac account.")
abort()
}
NotificationCenter.default.post(name: .AccountsDidChangeNotification, object: self)
}
public func existingAccount(with accountID: String) -> Account? {
return accountsDictionary[accountID]

View File

@ -53,7 +53,7 @@ Aw
</string>
</buttonCell>
<connections>
<action selector="create:" target="-2" id="Kjr-mt-Yp3"/>
<action selector="delete:" target="-2" id="5zX-jC-oWO"/>
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="v9D-u4-Ucr">

View File

@ -39,8 +39,11 @@ class AccountsDeleteWindowController: NSWindowController {
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.cancel)
}
@IBAction func create(_ sender: Any) {
@IBAction func delete(_ sender: Any) {
guard let account = account else {
return
}
AccountManager.shared.deleteAccount(account)
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK)
}