Skip to content

Commit

Permalink
update versions
Browse files Browse the repository at this point in the history
  • Loading branch information
learning committed Jan 28, 2019
1 parent 51967d7 commit 5fc2bcd
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 16 deletions.
13 changes: 13 additions & 0 deletions data.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@
}
],
"versions": [
{
"npm": "6.5.0",
"url": {
"linux": "https://nodejs.org/download/release/v11.8.0/node-v11.8.0-linux-x64.tar.xz",
"darwin": "https://nodejs.org/download/release/v11.8.0/node-v11.8.0-darwin-x64.tar.xz",
"shasum256": "https://nodejs.org/download/release/v11.8.0/SHASUMS256.txt",
"win": "https://nodejs.org/download/release/v11.8.0/node-v11.8.0-win-x64.7z"
},
"v8": "7.0.276.38",
"version": "11.8.0",
"date": "2019-01-24",
"node-module-version": "67"
},
{
"npm": "6.5.0",
"url": {
Expand Down
24 changes: 13 additions & 11 deletions mac/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -711,19 +711,19 @@
</connections>
</segmentedControl>
</toolbarItem>
<toolbarItem implicitItemIdentifier="383DBE9B-7B43-4574-BC60-B642A3E4B8F8" label="Current Version" paletteLabel="Current Version" id="mYe-hx-4aL">
<toolbarItem implicitItemIdentifier="507EBD12-4645-4D32-A77E-DB5215F3C491" label="Refresh" paletteLabel="Refresh" image="NSRefreshTemplate" sizingBehavior="auto" id="NDs-Eu-f3z">
<nil key="toolTip"/>
<size key="minSize" width="38" height="17"/>
<size key="maxSize" width="204" height="17"/>
<textField key="view" horizontalHuggingPriority="251" verticalHuggingPriority="750" id="sma-bh-gC0">
<rect key="frame" x="0.0" y="14" width="204" height="17"/>
<button key="view" verticalHuggingPriority="750" id="y8A-lY-io1">
<rect key="frame" x="2" y="14" width="44" height="43"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Current Version" id="5Fm-KL-l2e">
<buttonCell key="cell" type="push" bezelStyle="rounded" image="NSRefreshTemplate" imagePosition="only" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Jrw-5R-20b">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<color key="textColor" name="controlDarkShadowColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</buttonCell>
<connections>
<action selector="refresh:" target="B8D-0N-5wS" id="8yW-ai-qWn"/>
</connections>
</button>
</toolbarItem>
<toolbarItem implicitItemIdentifier="B43759D6-47A5-4A0E-9292-1D720BC75B53" label="Loading Indicator" paletteLabel="Loading Indicator" tag="-1" id="b4L-wM-Ge9" userLabel="Loading Indicator">
<nil key="toolTip"/>
Expand All @@ -739,7 +739,7 @@
<toolbarItem reference="H3u-9J-tuD"/>
<toolbarItem reference="b4L-wM-Ge9"/>
<toolbarItem reference="VUM-zR-QcG"/>
<toolbarItem reference="mYe-hx-4aL"/>
<toolbarItem reference="NDs-Eu-f3z"/>
</defaultToolbarItems>
</toolbar>
<connections>
Expand All @@ -748,6 +748,7 @@
</window>
<connections>
<outlet property="loadingIndicator" destination="LVL-Jd-J81" id="gx8-GL-GVl"/>
<outlet property="refreshButton" destination="y8A-lY-io1" id="9Ab-dR-loR"/>
<outlet property="tabControl" destination="DSK-0o-KEh" id="5Cl-Qf-beu"/>
<segue destination="6NC-pZ-gSe" kind="relationship" relationship="window.shadowedContentViewController" id="KNi-gb-cfu"/>
</connections>
Expand Down Expand Up @@ -1229,6 +1230,7 @@
<resources>
<image name="NSActionTemplate" width="14" height="14"/>
<image name="NSListViewTemplate" width="14" height="10"/>
<image name="NSRefreshTemplate" width="11" height="15"/>
<image name="NSRevealFreestandingTemplate" width="14" height="14"/>
</resources>
</document>
13 changes: 12 additions & 1 deletion mac/DownloadViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ class DownloadViewController: NSSplitViewController,

override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(self.refresh(notification:)), name: Notification.Name("refresh-list"), object: nil)

sidebarView.expandItem(rootElement)
self.initStore()

}

/**
Expand Down Expand Up @@ -170,4 +171,14 @@ class DownloadViewController: NSSplitViewController,
print("no row clicked")
}
}

/* ---------- Refresh ---------- */

@objc func refresh(notification: Notification) {
NotificationCenter.default.post(name: NSNotification.Name("show-loading"), object: nil)
self.store?.refresh {
NotificationCenter.default.post(name: NSNotification.Name("hide-loading"), object: nil)
self.tableView.reloadData()
}
}
}
19 changes: 16 additions & 3 deletions mac/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ let VERSION_URL = "https://raw.githubusercontent.com/learning/node-box/master/da
class Store {
static private var store:Store? = nil;

var branches:Array<Branch>;
var versions:Array<Version>;
var branches:Array<Branch> = [];
var versions:Array<Version> = [];

init (data: Dictionary<String, Any>) {
self.updateWith(data: data)
}

init(data: Dictionary<String, Any>) {
func updateWith(data: Dictionary<String, Any>) {
self.branches = (data["branches"] as! Array<Dictionary<String, String>>).map { Branch(data: $0) }
self.versions = (data["versions"] as! Array<Dictionary<String, Any>>).map { Version(data: $0) }
do {
Expand Down Expand Up @@ -62,6 +66,15 @@ class Store {

public func refresh(onSuccess success: @escaping () -> Void) {
// TODO: refresh version list
Store.updateDownloadList {
let data = Store.getData()
if data != nil {
self.updateWith(data: data!)
success()
} else {
NotificationCenter.default.post(name: Notification.Name("alert"), object: "Download error, please try again.")
}
}
}

/**
Expand Down
11 changes: 10 additions & 1 deletion mac/WindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class WindowController: NSWindowController {

@IBOutlet weak var loadingIndicator: NSProgressIndicator!
@IBOutlet weak var tabControl: NSSegmentedControl!

@IBOutlet weak var refreshButton: NSButton!

override func windowDidLoad() {
super.windowDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(self.reopen(notification:)), name: Notification.Name("reopen"), object: nil)
Expand All @@ -23,6 +24,7 @@ class WindowController: NSWindowController {

var frame = self.window?.frame
frame?.size = NSSize(width: 620, height: 350)
refreshButton.isHidden = true
self.window?.setFrame(frame!, display: true)
}

Expand All @@ -32,6 +34,7 @@ class WindowController: NSWindowController {

@objc func changeTab(notification: Notification) {
tabControl.setSelected(true, forSegment: notification.object as! Int)
refreshButton.isHidden = (notification.object as! Int == 0)
}

@objc func reopen(notification: Notification) {
Expand All @@ -42,9 +45,11 @@ class WindowController: NSWindowController {
if notification.name.rawValue == "show-loading" {
self.loadingIndicator.isHidden = false
self.loadingIndicator.startAnimation(self)
self.refreshButton.isEnabled = false
} else {
self.loadingIndicator.isHidden = true
self.loadingIndicator.stopAnimation(self)
self.refreshButton.isEnabled = true
}
}

Expand All @@ -59,4 +64,8 @@ class WindowController: NSWindowController {
print(response)
})
}

@IBAction func refresh(_ sender: Any) {
NotificationCenter.default.post(name: NSNotification.Name("refresh-list"), object: nil)
}
}
Binary file not shown.

0 comments on commit 5fc2bcd

Please sign in to comment.