@@ -40,7 +40,10 @@ class TodayViewController: NSViewController, NCWidgetProviding {
40
40
41
41
var maria = Maria . shared
42
42
43
- var timer : Timer !
43
+ var timer : Timer ?
44
+
45
+ var timeToConnectAria = 4
46
+ var countdownTimeToConnectAria = 4
44
47
var authorized : Bool = true
45
48
46
49
func widgetPerformUpdate( _ completionHandler: ( ( NCUpdateResult ) -> Void ) ) {
@@ -67,9 +70,25 @@ class TodayViewController: NSViewController, NCWidgetProviding {
67
70
}
68
71
69
72
func updateListStatus( ) {
70
- if maria. rpc? . status == . connected {
73
+ switch maria. rpc!. status {
74
+ case . disconnected:
75
+ countdownTimeToConnectAria -= 1
76
+ if countdownTimeToConnectAria == 0 {
77
+ maria. rpc? . connect ( )
78
+ timeToConnectAria *= 2
79
+ countdownTimeToConnectAria = timeToConnectAria
80
+ } else {
81
+ let localized = NSLocalizedString ( " aria2.status.disconnected " , comment: " " )
82
+ alertLabel. stringValue = String ( format: localized, countdownTimeToConnectAria)
83
+ }
84
+ case . connected:
85
+ timeToConnectAria = 4
86
+ countdownTimeToConnectAria = 4
87
+
71
88
maria. rpc? . getGlobalStatus ( )
72
89
maria. rpc? . tellActive ( )
90
+ default :
91
+ break
73
92
}
74
93
}
75
94
@@ -120,7 +139,6 @@ class TodayViewController: NSViewController, NCWidgetProviding {
120
139
self . taskListScrollViewHeightConstraint. constant = 0
121
140
case . disconnected:
122
141
self . noTaskAlertLabel. isHidden = true
123
- self . alertLabel. stringValue = NSLocalizedString ( " aria2.status.disconnected " , comment: " " )
124
142
self . taskListScrollViewHeightConstraint. constant = 0
125
143
}
126
144
}
@@ -134,7 +152,7 @@ extension TodayViewController {
134
152
timer = Timer . scheduledTimer ( timeInterval: 1 , target: self , selector: #selector( updateListStatus) , userInfo: nil , repeats: true )
135
153
}
136
154
fileprivate func closeTimer( ) {
137
- timer. invalidate ( )
155
+ timer? . invalidate ( )
138
156
timer = nil
139
157
}
140
158
}
0 commit comments