Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Today Widget auto reconnect to aria2
Browse files Browse the repository at this point in the history
  • Loading branch information
shincurry committed Dec 16, 2016
1 parent 487fdd2 commit aa094b7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
7 changes: 4 additions & 3 deletions Maria Widget/Base.lproj/TodayViewController.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11201" systemVersion="16A319" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11201"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="TodayViewController" customModule="Maria_Widget" customModuleProvider="target">
Expand Down Expand Up @@ -81,7 +82,7 @@
<rect key="frame" x="79" y="73" width="157" height="19"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Please run aria2 first" id="Twu-sf-eXL">
<font key="font" metaFont="system" size="16"/>
<color key="textColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<color key="textColor" red="0.37254901960784315" green="0.37254901960784315" blue="0.37254901960784315" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
Expand Down
2 changes: 1 addition & 1 deletion Maria Widget/Maria.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Cocoa
import Aria2RPC

class Maria {
var rpc: Aria2RPC!
var rpc: Aria2RPC?

static let shared = Maria()

Expand Down
26 changes: 22 additions & 4 deletions Maria Widget/TodayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ class TodayViewController: NSViewController, NCWidgetProviding {

var maria = Maria.shared

var timer: Timer!
var timer: Timer?

var timeToConnectAria = 4
var countdownTimeToConnectAria = 4
var authorized: Bool = true

func widgetPerformUpdate(_ completionHandler: ((NCUpdateResult) -> Void)) {
Expand All @@ -67,9 +70,25 @@ class TodayViewController: NSViewController, NCWidgetProviding {
}

func updateListStatus() {
if maria.rpc?.status == .connected {
switch maria.rpc!.status {
case .disconnected:
countdownTimeToConnectAria -= 1
if countdownTimeToConnectAria == 0 {
maria.rpc?.connect()
timeToConnectAria *= 2
countdownTimeToConnectAria = timeToConnectAria
} else {
let localized = NSLocalizedString("aria2.status.disconnected", comment: "")
alertLabel.stringValue = String(format: localized, countdownTimeToConnectAria)
}
case .connected:
timeToConnectAria = 4
countdownTimeToConnectAria = 4

maria.rpc?.getGlobalStatus()
maria.rpc?.tellActive()
default:
break
}
}

Expand Down Expand Up @@ -120,7 +139,6 @@ class TodayViewController: NSViewController, NCWidgetProviding {
self.taskListScrollViewHeightConstraint.constant = 0
case .disconnected:
self.noTaskAlertLabel.isHidden = true
self.alertLabel.stringValue = NSLocalizedString("aria2.status.disconnected", comment: "")
self.taskListScrollViewHeightConstraint.constant = 0
}
}
Expand All @@ -134,7 +152,7 @@ extension TodayViewController {
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateListStatus), userInfo: nil, repeats: true)
}
fileprivate func closeTimer() {
timer.invalidate()
timer?.invalidate()
timer = nil
}
}
Expand Down

0 comments on commit aa094b7

Please sign in to comment.