Skip to content

Commit c4ace28

Browse files
committed
Add version update check and change the main file
1 parent 65ede5a commit c4ace28

File tree

3 files changed

+72
-10
lines changed

3 files changed

+72
-10
lines changed

socpowerbuddy_swift.xcodeproj/project.pbxproj

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
3A3DA8AC28E0A76D00BFEFAC /* ArgumentParser in Frameworks */ = {isa = PBXBuildFile; productRef = 3A3DA8AB28E0A76D00BFEFAC /* ArgumentParser */; };
2626
3A8A035528E3F0800027B16E /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A8A035428E3F0800027B16E /* main.swift */; };
2727
3A8A035A28E3F6EE0027B16E /* libIOReport.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AF36E0B28D21A4C00DA3EB3 /* libIOReport.tbd */; };
28-
3A9A722C28D15EBB0021E6F1 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A9A722B28D15EBB0021E6F1 /* main.swift */; };
2928
3A9A723328D15F5C0021E6F1 /* static.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A9A723228D15F5C0021E6F1 /* static.swift */; };
3029
3AC9F1EA28F02E7B008C5D5C /* libncurses.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AC9F1E928F02E6F008C5D5C /* libncurses.tbd */; };
30+
3AECE96B297AEB4000D45A12 /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 3AECE96A297AEB4000D45A12 /* Alamofire */; };
31+
3AECE971297AFCF500D45A12 /* neoasitop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AECE970297AFCF500D45A12 /* neoasitop.swift */; };
3132
3AF36E0C28D21A6B00DA3EB3 /* libIOReport.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AF36E0B28D21A4C00DA3EB3 /* libIOReport.tbd */; };
3233
3AF36E0E28D2ACCC00DA3EB3 /* head.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AF36E0D28D2ACCC00DA3EB3 /* head.swift */; };
3334
/* End PBXBuildFile section */
@@ -73,9 +74,9 @@
7374
3A8A035228E3F0800027B16E /* IOReportDump */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = IOReportDump; sourceTree = BUILT_PRODUCTS_DIR; };
7475
3A8A035428E3F0800027B16E /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
7576
3A9A722828D15EBB0021E6F1 /* socpowerbuddy_swift */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = socpowerbuddy_swift; sourceTree = BUILT_PRODUCTS_DIR; };
76-
3A9A722B28D15EBB0021E6F1 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
7777
3A9A723228D15F5C0021E6F1 /* static.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = static.swift; sourceTree = "<group>"; };
7878
3AC9F1E928F02E6F008C5D5C /* libncurses.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libncurses.tbd; path = usr/lib/libncurses.tbd; sourceTree = SDKROOT; };
79+
3AECE970297AFCF500D45A12 /* neoasitop.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = neoasitop.swift; sourceTree = "<group>"; };
7980
3AF36E0728D216A800DA3EB3 /* socpwrbud.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = socpwrbud.h; sourceTree = "<group>"; };
8081
3AF36E0828D2174A00DA3EB3 /* socpowerbuddy_bridge.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = socpowerbuddy_bridge.h; sourceTree = "<group>"; };
8182
3AF36E0B28D21A4C00DA3EB3 /* libIOReport.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libIOReport.tbd; path = usr/lib/libIOReport.tbd; sourceTree = SDKROOT; };
@@ -96,6 +97,7 @@
9697
buildActionMask = 2147483647;
9798
files = (
9899
3AF36E0C28D21A6B00DA3EB3 /* libIOReport.tbd in Frameworks */,
100+
3AECE96B297AEB4000D45A12 /* Alamofire in Frameworks */,
99101
3A3DA8AC28E0A76D00BFEFAC /* ArgumentParser in Frameworks */,
100102
3AC9F1EA28F02E7B008C5D5C /* libncurses.tbd in Frameworks */,
101103
);
@@ -135,7 +137,7 @@
135137
3A9A722A28D15EBB0021E6F1 /* socpowerbuddy_swift */ = {
136138
isa = PBXGroup;
137139
children = (
138-
3A9A722B28D15EBB0021E6F1 /* main.swift */,
140+
3AECE970297AFCF500D45A12 /* neoasitop.swift */,
139141
3A9A723228D15F5C0021E6F1 /* static.swift */,
140142
3AF36E0728D216A800DA3EB3 /* socpwrbud.h */,
141143
3AF36E0828D2174A00DA3EB3 /* socpowerbuddy_bridge.h */,
@@ -203,6 +205,7 @@
203205
name = socpowerbuddy_swift;
204206
packageProductDependencies = (
205207
3A3DA8AB28E0A76D00BFEFAC /* ArgumentParser */,
208+
3AECE96A297AEB4000D45A12 /* Alamofire */,
206209
);
207210
productName = socpowerbuddy_swift;
208211
productReference = 3A9A722828D15EBB0021E6F1 /* socpowerbuddy_swift */;
@@ -237,6 +240,7 @@
237240
mainGroup = 3A9A721F28D15EBB0021E6F1;
238241
packageReferences = (
239242
3A3DA8A628E09E4500BFEFAC /* XCRemoteSwiftPackageReference "swift-argument-parser" */,
243+
3AECE969297AEB4000D45A12 /* XCRemoteSwiftPackageReference "Alamofire" */,
240244
);
241245
productRefGroup = 3A9A722928D15EBB0021E6F1 /* Products */;
242246
projectDirPath = "";
@@ -264,6 +268,7 @@
264268
3A238E8928D2FBD60033A580 /* sampler.swift in Sources */,
265269
3A238F0128D5CCEF0033A580 /* Repeater.swift in Sources */,
266270
3A238EE928D5BF410033A580 /* Logger.swift in Sources */,
271+
3AECE971297AFCF500D45A12 /* neoasitop.swift in Sources */,
267272
3A3DA88628DEDC5B00BFEFAC /* util.swift in Sources */,
268273
3A238EEB28D5BFC10033A580 /* helper.swift in Sources */,
269274
3A238EF528D5C6710033A580 /* readers.swift in Sources */,
@@ -274,7 +279,6 @@
274279
3A238EF128D5C2AA0033A580 /* extensions.swift in Sources */,
275280
3A238EFD28D5C9B70033A580 /* Module.swift in Sources */,
276281
3A238EE728D5BED50033A580 /* SystemKit.swift in Sources */,
277-
3A9A722C28D15EBB0021E6F1 /* main.swift in Sources */,
278282
3A238EF928D5C8210033A580 /* reader.swift in Sources */,
279283
3A9A723328D15F5C0021E6F1 /* static.swift in Sources */,
280284
3A238EF728D5C6910033A580 /* values.swift in Sources */,
@@ -503,6 +507,14 @@
503507
minimumVersion = 1.0.0;
504508
};
505509
};
510+
3AECE969297AEB4000D45A12 /* XCRemoteSwiftPackageReference "Alamofire" */ = {
511+
isa = XCRemoteSwiftPackageReference;
512+
repositoryURL = "https://github.com/Alamofire/Alamofire.git";
513+
requirement = {
514+
kind = upToNextMajorVersion;
515+
minimumVersion = 5.0.0;
516+
};
517+
};
506518
/* End XCRemoteSwiftPackageReference section */
507519

508520
/* Begin XCSwiftPackageProductDependency section */
@@ -511,6 +523,11 @@
511523
package = 3A3DA8A628E09E4500BFEFAC /* XCRemoteSwiftPackageReference "swift-argument-parser" */;
512524
productName = ArgumentParser;
513525
};
526+
3AECE96A297AEB4000D45A12 /* Alamofire */ = {
527+
isa = XCSwiftPackageProductDependency;
528+
package = 3AECE969297AEB4000D45A12 /* XCRemoteSwiftPackageReference "Alamofire" */;
529+
productName = Alamofire;
530+
};
514531
/* End XCSwiftPackageProductDependency section */
515532
};
516533
rootObject = 3A9A722028D15EBB0021E6F1 /* Project object */;

socpowerbuddy_swift.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//
2-
// main.swift
2+
// neoasitop.swift
33
// socpowerbuddy_swift
44
//
5-
// Created by Eom SeHwan on 2022/09/14.
5+
// Created by Eom SeHwan on 2023/01/21.
66
//
77

8+
import Alamofire
89
import Foundation
910
import IOKit.graphics
1011
import ArgumentParser
@@ -13,6 +14,9 @@ var iorep = iorep_data()
1314
var sd = static_data()
1415
var cmd = cmd_data()
1516

17+
let cur_ver = "v2.6"
18+
var newVersion = false
19+
1620
struct Neoasitop: ParsableCommand {
1721
@Flag(name: .shortAndLong, help: "Print version information")
1822
var version = false
@@ -28,14 +32,18 @@ struct Neoasitop: ParsableCommand {
2832

2933
func run() throws {
3034
if version {
31-
print("v2.6")
35+
print(cur_ver)
3236
} else {
3337
launch()
38+
if newVersion {
39+
print("New version is released! Please update the NeoAsitop.")
40+
}
3441
}
42+
Neoasitop.exit(withError: ExitCode(EX_OK))
3543
}
3644

3745
func launch() {
38-
46+
3947
print("\nNeoAsitop - Sudoless performance monitoring CLI tool for Apple Silicon")
4048
print("Get help at `https://github.com/op06072/NeoAsitop`")
4149
print("Thanks to all the projects that inspired and referenced.")
@@ -229,7 +237,7 @@ struct Neoasitop: ParsableCommand {
229237
}
230238
del_tbox(tbx: &scr)
231239
print("\nGood Bye")
232-
Neoasitop.exit(withError: ExitCode(EX_OK))
240+
return
233241
default:
234242
autoreleasepool {
235243
scrin = display(monInfo, false, scr, xy, color, bottomPnt) // 정보 출력
@@ -246,4 +254,32 @@ struct Neoasitop: ParsableCommand {
246254
}
247255
}
248256

249-
Neoasitop.main()
257+
@main
258+
enum Executable {
259+
static func main() async throws {
260+
let headers: HTTPHeaders = [
261+
.accept("application/vnd.github+json")
262+
]
263+
let dataTask = AF.request(
264+
"https://api.github.com/repos/op06072/NeoAsitop/releases/latest",
265+
headers: headers
266+
).serializingData()
267+
switch await dataTask.result {
268+
case .success(let value):
269+
let object = try JSONSerialization.jsonObject(with: value, options: []) as? NSDictionary
270+
if object == nil {
271+
Neoasitop.main()
272+
} else if (object!.allKeys as! [String]).contains("tag_name") {
273+
let version = object!.value(forKey: "tag_name") as! String
274+
if version.compare(cur_ver, options: .numeric) == .orderedDescending {
275+
newVersion = true
276+
}
277+
Neoasitop.main()
278+
} else {
279+
Neoasitop.main()
280+
}
281+
case .failure:
282+
Neoasitop.main()
283+
}
284+
}
285+
}

0 commit comments

Comments
 (0)