-
Notifications
You must be signed in to change notification settings - Fork 3
/
UpdateViewController.swift
71 lines (52 loc) · 1.95 KB
/
UpdateViewController.swift
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// UpdateViewController.swift
// Temperature
//
// Created by Filippo Valle on 23/06/17.
// Copyright © 2017 Filippo Valle. All rights reserved.
//
import Foundation
import Cocoa
class UpdateViewController:NSViewController{
let currentVersionString="2.1.0"
@IBOutlet weak var currentArea: NSTextField!
@IBOutlet weak var newestArea: NSTextField!
@IBAction func UpdateButtunPushed(_ sender: Any) {
UpdateVersions()
}
func UpdateVersions()->Void{
currentArea.stringValue="You are using:"+currentVersionString
let manager=ApiManager(url:"https://filippov-hko4rv9s2jb-apigcp.nimbella.io/api/macosTemperature/getLatestVersion")
manager.Call(method:"")
let semaphore = DispatchSemaphore(value: 0);
manager.FillNSTextFieldWithKey(key: "version", semaphore: semaphore)
_ = semaphore.wait(timeout: .distantFuture)
UpdateLatestString(newVersion: manager.GetLastCallData()) }
func UpdateLatestString(newVersion: String){
newestArea.stringValue = "Version "+newVersion+" is available"
}
@IBAction func DownloadButtonPushed(_ sender: Any) {
if let url = URL(string: "https://sourceforge.net/projects/macos-temperature/files/latest/download") {
let dataFromURL = try? Data(contentsOf: url)
let fileManager = FileManager.default
fileManager.createFile(atPath: "~/Downloads", contents: dataFromURL, attributes: nil)
}
}
func setStyle(){
self.view.window!.title="MacOS Temperature"
self.view.window!.backgroundColor=NSColor.blue
}
override func viewDidAppear() {
super.viewDidAppear()
setStyle()
}
override func viewDidLoad() {
super.viewDidLoad()
UpdateVersions()
}
override var representedObject: Any? {
didSet {
setStyle()
}
}
}