-
Notifications
You must be signed in to change notification settings - Fork 398
Expand file tree
/
Copy pathMenuItemView.swift
More file actions
52 lines (37 loc) · 1.11 KB
/
MenuItemView.swift
File metadata and controls
52 lines (37 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// MenuItemView.swift
// Postgres
//
// Created by Chris on 09/08/2016.
// This code is released under the terms of the PostgreSQL License.
//
import Cocoa
class MenuItemViewController: NSViewController {
@objc dynamic var server: Server!
@objc dynamic private(set) var errorIconVisible = false
@objc dynamic private(set) var errorTooltip = ""
convenience init?(_ server: Server) {
self.init(nibName: "MenuItemView", bundle: nil)
self.server = server
}
@IBAction func serverAction(_ sender: AnyObject?) {
if !server.running {
server.start(serverActionCompleted)
} else {
server.stop(serverActionCompleted)
}
}
private func serverActionCompleted(result: Result<Void, Error>) {
if case let .failure(error) = result {
self.errorIconVisible = true
self.errorTooltip = error.localizedDescription
} else {
self.errorIconVisible = false
self.errorTooltip = ""
}
DistributedNotificationCenter.default().post(name: Server.StatusChangedNotification, object: nil)
}
}
class MenuItemView: NSView {
// This subclass is only needed to detect menu items with custom views
}