Skip to content

Commit

Permalink
OPT updating menu and some code
Browse files Browse the repository at this point in the history
  • Loading branch information
ConradSun committed May 12, 2024
1 parent 31c0834 commit cadf990
Show file tree
Hide file tree
Showing 26 changed files with 263 additions and 864 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
.DS_Store
xcuserdata/

Package/*.app
Package/*.pkg
Package/*
Binary file modified Docs/nuwa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions NuwaClient/Alert.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21225" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21225"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22689"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down
11 changes: 10 additions & 1 deletion NuwaClient/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,61 @@
{
"images" : [
{
"filename" : "icon_16x16.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"filename" : "[email protected]",
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"filename" : "icon_32x32.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"filename" : "[email protected]",
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"filename" : "icon_128x128.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"filename" : "[email protected]",
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"filename" : "icon_256x256.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"filename" : "[email protected]",
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"filename" : "icon_512x512.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"filename" : "nuwa.png",
"filename" : "icon_512x512@2x.png",
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
158 changes: 118 additions & 40 deletions NuwaClient/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion NuwaClient/KextManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ extension KextManager {

func processNotifyEvent(_ event: inout NuwaKextEvent) {
var nuwaEvent = NuwaEventInfo()
var data = Data()

switch event.eventType {
case kActionNotifyProcessCreate:
Expand Down
2 changes: 1 addition & 1 deletion NuwaClient/ViewManager/GraphView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class GraphView: NSView {

func addPointToLine(_ yValue: CGFloat, index: Int) {
var point = NSPoint()
var rate = yValue > 100 ? 1.0 : yValue / 100.0
let rate = yValue > 100 ? 1.0 : yValue / 100.0
point.y = rate * frame.size.height

if freqPointsArray[index].last!.x >= frame.size.width {
Expand Down
126 changes: 126 additions & 0 deletions NuwaClient/ViewManager/UpdateViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//
// UpdateViewController.swift
// NuwaClient
//
// Created by ConradSun on 2024/5/12.
//

import Cocoa

class UpdateViewController: NSViewController {
@IBOutlet weak var iconImageView: NSImageView!
@IBOutlet weak var launchProgressIndicator: NSProgressIndicator!

private var updateCheckTask: Process?
private var checkResultPipe: Pipe?
private var checkInfoWindow: NSAlert?

override func viewDidLoad() {
super.viewDidLoad()

let icon = NSImage(named: "AppIcon")
icon?.size = NSMakeSize(80, 80)
iconImageView.image = icon

launchProgressIndicator.isIndeterminate = true
launchProgressIndicator.style = .bar
launchProgressIndicator.startAnimation(nil)

checkInfoWindow = NSAlert()
checkInfoWindow?.alertStyle = .informational

DispatchQueue.global().async { [self] in
var latestVersion = String()
let currentVersion = Bundle.main.object(forInfoDictionaryKey: VersionInfoKey) as! String

initCheckTask()
if let checkResult = launchCheckTask() {
let contentList = checkResult.split(separator: "\r\n")
for contentItem in contentList {
if contentItem.contains("location") {
let tag = contentItem.split(separator: "/").last!
if tag.first == "v" {
Logger(.Info, "The latest version is \(tag).")
latestVersion = tag.dropFirst().lowercased()
}
}
}
}

DispatchQueue.main.async { [self] in
setupInfoWindow(latestVersion: latestVersion, currentVersion: currentVersion)
view.window?.close()
let resp = checkInfoWindow?.runModal()
if resp == .alertSecondButtonReturn {
let downloadAddr = URL(string: PackageURL)
NSWorkspace.shared.open(downloadAddr!)
}
}
}
}

override func viewDidDisappear() {
super.viewDidDisappear()
updateCheckTask?.terminate()
}

private func initCheckTask() {
updateCheckTask = Process()
checkResultPipe = Pipe()
updateCheckTask?.arguments = ["-I", ReleaseURL]
updateCheckTask?.standardOutput = checkResultPipe

if #available(macOS 10.13, *) {
updateCheckTask?.executableURL = URL(fileURLWithPath: "/usr/bin/curl")
} else {
updateCheckTask?.launchPath = "/usr/bin/curl"
}
}

private func setupInfoWindow(latestVersion: String, currentVersion: String) {
if latestVersion.isEmpty {
checkInfoWindow?.alertStyle = .critical
checkInfoWindow?.messageText = "Error"
checkInfoWindow?.informativeText = "Failed to get latest info for NuwaStone."
} else if latestVersion == currentVersion {
checkInfoWindow?.messageText = "You're up-to-date!"
checkInfoWindow?.informativeText = "NuwaStone \(currentVersion) is the latest version."
} else {
checkInfoWindow?.messageText = "You're out-of-date!"
checkInfoWindow?.informativeText = "Newer version \(latestVersion) is currently avaliable."
checkInfoWindow?.addButton(withTitle: "Ignore")
checkInfoWindow?.addButton(withTitle: "Update")
}
}

private func launchCheckTask() -> String? {
var output = Data()

if #available(macOS 10.13, *) {
try? updateCheckTask?.run()
} else {
updateCheckTask?.launch()
}

if #available(macOS 10.15.4, *) {
guard let value = try? checkResultPipe?.fileHandleForReading.readToEnd() else {
return nil
}
output = value
} else {
guard let value = checkResultPipe?.fileHandleForReading.readDataToEndOfFile() else {
return nil
}
output = value
}

guard let result = String(data: output, encoding: .utf8) else {
return nil
}
return result
}

@IBAction func cancelButtonClicked(_ sender: NSButton) {
view.window?.close()
}
}
42 changes: 0 additions & 42 deletions NuwaClient/ViewManager/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,48 +155,6 @@ class ViewController: NSViewController {
refreshDisplayedEvents()
}

@IBAction func updateMenuItemSelected(_ sender: NSMenuItem) {
var latestVersion = String()
let currentVersion = Bundle.main.object(forInfoDictionaryKey: VersionInfoKey) as! String

let infoView = NSAlert()
infoView.alertStyle = .informational

guard let result = launchTask(path: "/usr/bin/curl", args: ["-I", ReleaseURL]) else {
return
}

let contentList = result.split(separator: "\r\n")
for contentItem in contentList {
if contentItem.contains("location") {
let tag = contentItem.split(separator: "/").last!
if tag.first == "v" {
Logger(.Info, "The latest version is \(tag).")
latestVersion = tag.dropFirst().lowercased()
}
}
}

if latestVersion.isEmpty {
infoView.alertStyle = .critical
infoView.messageText = "Error"
infoView.informativeText = "Failed to get latest info for NuwaStone."
} else if latestVersion == currentVersion {
infoView.messageText = "You're up-to-date!"
infoView.informativeText = "NuwaStone \(currentVersion) is the latest version."
} else {
infoView.messageText = "You're out-of-date!"
infoView.informativeText = "Newer version \(latestVersion) is currently avaliable."
infoView.addButton(withTitle: "Ignore")
infoView.addButton(withTitle: "Update")
}
let resp = infoView.runModal()
if resp == .alertSecondButtonReturn {
let downloadAddr = URL(string: PackageURL)
NSWorkspace.shared.open(downloadAddr!)
}
}

@IBAction func startMenuItemSelected(_ sender: NSMenuItem) {
controlButtonClicked(controlButton)
}
Expand Down
2 changes: 1 addition & 1 deletion NuwaService/XPCConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class XPCConnection: NSObject {
handler(false)
} as? DaemonXPCProtocol

proxy!.connectResponse(handler)
proxy?.connectResponse(handler)
handler(true)
}
}
4 changes: 4 additions & 0 deletions NuwaStone.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
3A01FEED28D8452100A1F30F /* ListManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3A01FEEB28D8452100A1F30F /* ListManager.cpp */; };
3A01FEEE28D8452100A1F30F /* ListManager.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3A01FEEC28D8452100A1F30F /* ListManager.hpp */; };
3A01FEF128D86E3200A1F30F /* XPCServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A6088F228A4A84500061A42 /* XPCServer.swift */; };
3A221D862BF07FF800E24836 /* UpdateViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A221D852BF07FF800E24836 /* UpdateViewController.swift */; };
3A2305CB28ADD96E00F85A82 /* AlertWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A2305C928ADD96E00F85A82 /* AlertWindowController.swift */; };
3A2305CC28ADD96E00F85A82 /* Alert.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3A2305CA28ADD96E00F85A82 /* Alert.xib */; };
3A2305CE28AE257F00F85A82 /* XPCServerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A2305CD28AE257F00F85A82 /* XPCServerDelegate.swift */; };
Expand Down Expand Up @@ -124,6 +125,7 @@
/* Begin PBXFileReference section */
3A01FEEB28D8452100A1F30F /* ListManager.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ListManager.cpp; sourceTree = "<group>"; };
3A01FEEC28D8452100A1F30F /* ListManager.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ListManager.hpp; sourceTree = "<group>"; };
3A221D852BF07FF800E24836 /* UpdateViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateViewController.swift; sourceTree = "<group>"; };
3A2305C928ADD96E00F85A82 /* AlertWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertWindowController.swift; sourceTree = "<group>"; };
3A2305CA28ADD96E00F85A82 /* Alert.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = Alert.xib; sourceTree = "<group>"; };
3A2305CD28AE257F00F85A82 /* XPCServerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XPCServerDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -238,6 +240,7 @@
3AAA18962887BC4000C1BDAF /* EventViewDelegate.swift */,
3A2305C928ADD96E00F85A82 /* AlertWindowController.swift */,
3AFFBBB928D725C5001D421C /* PrefsViewController.swift */,
3A221D852BF07FF800E24836 /* UpdateViewController.swift */,
);
path = ViewManager;
sourceTree = "<group>";
Expand Down Expand Up @@ -662,6 +665,7 @@
3A2305CB28ADD96E00F85A82 /* AlertWindowController.swift in Sources */,
3ABAFF832879C0D900928C22 /* AppDelegate.swift in Sources */,
3AED3F5B288953FD00FCA79A /* GraphView.swift in Sources */,
3A221D862BF07FF800E24836 /* UpdateViewController.swift in Sources */,
3A01FEF128D86E3200A1F30F /* XPCServer.swift in Sources */,
3AAA18972887BC4000C1BDAF /* EventViewDelegate.swift in Sources */,
3AA1B8D52A0CEB01001F0FC5 /* DeviceInfo.swift in Sources */,
Expand Down
Binary file not shown.
Loading

0 comments on commit cadf990

Please sign in to comment.