diff --git a/Menubar RunCat.xcodeproj/project.pbxproj b/Menubar RunCat.xcodeproj/project.pbxproj index aac83e8..7705874 100644 --- a/Menubar RunCat.xcodeproj/project.pbxproj +++ b/Menubar RunCat.xcodeproj/project.pbxproj @@ -3,21 +3,21 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 56; objects = { /* Begin PBXBuildFile section */ + 1C0ADF322A175F0B00867AB3 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C0ADF312A175F0B00867AB3 /* main.swift */; }; 1CEF10A022F922DB00DAD355 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CEF109F22F922DB00DAD355 /* AppDelegate.swift */; }; 1CEF10A422F922DD00DAD355 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1CEF10A322F922DD00DAD355 /* Assets.xcassets */; }; - 1CEF10A722F922DD00DAD355 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1CEF10A522F922DD00DAD355 /* Main.storyboard */; }; 1CEF10B022F9342600DAD355 /* CPU.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CEF10AF22F9342600DAD355 /* CPU.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 1C0ADF312A175F0B00867AB3 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; 1CEF109C22F922DB00DAD355 /* Menubar RunCat.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Menubar RunCat.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 1CEF109F22F922DB00DAD355 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 1CEF10A322F922DD00DAD355 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 1CEF10A622F922DD00DAD355 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 1CEF10A822F922DD00DAD355 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 1CEF10A922F922DD00DAD355 /* Menubar_RunCat.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Menubar_RunCat.entitlements; sourceTree = ""; }; 1CEF10AF22F9342600DAD355 /* CPU.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CPU.swift; sourceTree = ""; }; @@ -53,10 +53,10 @@ 1CEF109E22F922DB00DAD355 /* Menubar RunCat */ = { isa = PBXGroup; children = ( + 1C0ADF312A175F0B00867AB3 /* main.swift */, 1CEF109F22F922DB00DAD355 /* AppDelegate.swift */, 1CEF10AF22F9342600DAD355 /* CPU.swift */, 1CEF10A322F922DD00DAD355 /* Assets.xcassets */, - 1CEF10A522F922DD00DAD355 /* Main.storyboard */, 1CEF10A822F922DD00DAD355 /* Info.plist */, 1CEF10A922F922DD00DAD355 /* Menubar_RunCat.entitlements */, ); @@ -89,8 +89,9 @@ 1CEF109422F922DB00DAD355 /* Project object */ = { isa = PBXProject; attributes = { + BuildIndependentTargetsInParallel = YES; LastSwiftUpdateCheck = 1030; - LastUpgradeCheck = 1200; + LastUpgradeCheck = 1430; ORGANIZATIONNAME = "Takuto Nakamura"; TargetAttributes = { 1CEF109B22F922DB00DAD355 = { @@ -99,7 +100,7 @@ }; }; buildConfigurationList = 1CEF109722F922DB00DAD355 /* Build configuration list for PBXProject "Menubar RunCat" */; - compatibilityVersion = "Xcode 9.3"; + compatibilityVersion = "Xcode 14.0"; developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( @@ -122,7 +123,6 @@ buildActionMask = 2147483647; files = ( 1CEF10A422F922DD00DAD355 /* Assets.xcassets in Resources */, - 1CEF10A722F922DD00DAD355 /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -135,22 +135,12 @@ files = ( 1CEF10B022F9342600DAD355 /* CPU.swift in Sources */, 1CEF10A022F922DB00DAD355 /* AppDelegate.swift in Sources */, + 1C0ADF322A175F0B00867AB3 /* main.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ -/* Begin PBXVariantGroup section */ - 1CEF10A522F922DD00DAD355 /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 1CEF10A622F922DD00DAD355 /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - /* Begin XCBuildConfiguration section */ 1CEF10AA22F922DD00DAD355 /* Debug */ = { isa = XCBuildConfiguration; @@ -187,6 +177,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "Mac Developer"; COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -204,7 +195,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -249,6 +240,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "Mac Developer"; COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -260,7 +252,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.14; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = macosx; @@ -275,15 +267,23 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = "Menubar RunCat/Menubar_RunCat.entitlements"; CODE_SIGN_IDENTITY = "-"; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1.0.0; + DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = VJ5N2X84K8; + GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Menubar RunCat/Info.plist"; + INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; + INFOPLIST_KEY_LSUIElement = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2019 Takuto Nakamura. All rights reserved."; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; + MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = "com.kyome.menubar-runcat"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; @@ -296,15 +296,23 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = "Menubar RunCat/Menubar_RunCat.entitlements"; CODE_SIGN_IDENTITY = "-"; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1.0.0; + DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = VJ5N2X84K8; + GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = "Menubar RunCat/Info.plist"; + INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; + INFOPLIST_KEY_LSUIElement = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2019 Takuto Nakamura. All rights reserved."; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/../Frameworks", ); - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; + MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = "com.kyome.menubar-runcat"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; diff --git a/Menubar RunCat.xcodeproj/project.xcworkspace/xcuserdata/takuto.xcuserdatad/UserInterfaceState.xcuserstate b/Menubar RunCat.xcodeproj/project.xcworkspace/xcuserdata/takuto.xcuserdatad/UserInterfaceState.xcuserstate index 320d1c8..9783433 100644 Binary files a/Menubar RunCat.xcodeproj/project.xcworkspace/xcuserdata/takuto.xcuserdatad/UserInterfaceState.xcuserstate and b/Menubar RunCat.xcodeproj/project.xcworkspace/xcuserdata/takuto.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Menubar RunCat/AppDelegate.swift b/Menubar RunCat/AppDelegate.swift index 3c9b609..c55d781 100644 --- a/Menubar RunCat/AppDelegate.swift +++ b/Menubar RunCat/AppDelegate.swift @@ -1,95 +1,129 @@ -// -// AppDelegate.swift -// Menubar RunCat -// -// Created by Takuto Nakamura on 2019/08/06. -// Copyright © 2019 Takuto Nakamura. All rights reserved. -// +/* + AppDelegate.swift + Menubar RunCat + + Created by Takuto Nakamura on 2019/08/06. + Copyright © 2019 Takuto Nakamura. All rights reserved. +*/ import Cocoa -@NSApplicationMain -class AppDelegate: NSObject, NSApplicationDelegate { - - @IBOutlet weak var menu: NSMenu! - - private let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) - private let nc = NSWorkspace.shared.notificationCenter - private var frames = [NSImage]() - private var cnt: Int = 0 - private var isRunning: Bool = false +final class AppDelegate: NSObject, NSApplicationDelegate { + private lazy var statusItem: NSStatusItem = { + return NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) + }() + private let menu = NSMenu() + private lazy var frames: [NSImage] = { + return (0 ..< 5).map { n in + let image = NSImage(named: "cat_page\(n)")! + image.size = NSSize(width: 28, height: 18) + return image + } + }() + private var index: Int = 0 private var interval: Double = 1.0 private let cpu = CPU() + private var usage: CPUInfo = CPU.default private var cpuTimer: Timer? = nil - private var usage: (value: Double, description: String) = (0.0, "") + private var runnerTimer: Timer? = nil private var isShowUsage: Bool = false - - func applicationDidFinishLaunching(_ aNotification: Notification) { - for i in (0 ..< 5) { - frames.append(NSImage(imageLiteralResourceName: "cat_page\(i)")) - } - statusItem.menu = menu - statusItem.button?.imagePosition = .imageRight - statusItem.button?.image = frames[cnt] - cnt = (cnt + 1) % frames.count - + + func applicationDidFinishLaunching(_ notification: Notification) { + setupStatusItem() startRunning() } - func applicationWillTerminate(_ aNotification: Notification) { + func applicationWillTerminate(_ notification: Notification) { stopRunning() } - - func setNotifications() { - nc.addObserver(self, selector: #selector(AppDelegate.receiveSleepNote), - name: NSWorkspace.willSleepNotification, object: nil) - nc.addObserver(self, selector: #selector(AppDelegate.receiveWakeNote), - name: NSWorkspace.didWakeNotification, object: nil) - } - - @objc func receiveSleepNote() { - stopRunning() - } - - @objc func receiveWakeNote() { - startRunning() - } - - func startRunning() { - cpuTimer = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true, block: { (t) in - self.usage = self.cpu.usageCPU() - self.interval = 0.02 * (100 - max(0.0, min(99.0, self.usage.value))) / 6 - self.statusItem.button?.title = self.isShowUsage ? self.usage.description : "" - }) - cpuTimer?.fire() - isRunning = true - animate() - } - - func stopRunning() { - isRunning = false - cpuTimer?.invalidate() - } - func animate() { - statusItem.button?.image = frames[cnt] - cnt = (cnt + 1) % frames.count - if !isRunning { return } - DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + interval) { - self.animate() - } - } - - @IBAction func toggleShowUsage(_ sender: NSMenuItem) { - isShowUsage = sender.state == .off - sender.state = isShowUsage ? .on : .off + private func updateUsageDescription() { statusItem.button?.title = isShowUsage ? usage.description : "" } - - @IBAction func showAbout(_ sender: Any) { + + @objc func toggleShowUsage(_ sender: NSMenuItem) { + isShowUsage = (sender.state == .off) + sender.state = isShowUsage ? .on : .off + updateUsageDescription() + } + + @objc func openAbout(_ sender: Any?) { NSApp.activate(ignoringOtherApps: true) NSApp.orderFrontStandardAboutPanel(nil) } -} + @objc func terminateApp(_ sender: Any?) { + NSApp.terminate(nil) + } + private func setupStatusItem() { + statusItem.button?.imagePosition = .imageTrailing + statusItem.button?.image = frames.first + if #available(macOS 10.15, *) { + let font = NSFont.monospacedSystemFont(ofSize: 11, weight: .regular) + statusItem.button?.font = font + } else { + let font = NSFont.monospacedDigitSystemFont(ofSize: 11, weight: .regular) + statusItem.button?.font = font + } + menu.addItem(withTitle: "Show CPU Usage", + action: #selector(toggleShowUsage(_:)), + keyEquivalent: "") + menu.addItem(NSMenuItem.separator()) + menu.addItem(withTitle: "About Menubar RunCat", + action: #selector(openAbout(_:)), + keyEquivalent: "") + menu.addItem(withTitle: "Quit Menubar RunCat", + action: #selector(terminateApp(_:)), + keyEquivalent: "") + statusItem.menu = menu + } + + @objc func receiveSleep(_ notification: NSNotification) { + stopRunning() + } + + @objc func receiveWakeUp(_ notification: NSNotification) { + startRunning() + } + + private func setNotifications() { + NSWorkspace.shared.notificationCenter + .addObserver(self, selector: #selector(receiveSleep(_:)), + name: NSWorkspace.willSleepNotification, + object: nil) + NSWorkspace.shared.notificationCenter + .addObserver(self, selector: #selector(receiveWakeUp(_:)), + name: NSWorkspace.didWakeNotification, + object: nil) + } + + private func updateUsage() { + usage = cpu.currentUsage() + interval = 0.2 / max(1.0, min(20.0, self.usage.value / 5.0)) + updateUsageDescription() + runnerTimer?.invalidate() + runnerTimer = Timer(timeInterval: self.interval, repeats: true, block: { [weak self] _ in + self?.next() + }) + RunLoop.main.add(runnerTimer!, forMode: .common) + } + + private func next() { + index = (index + 1) % frames.count + statusItem.button?.image = frames[index] + } + + private func startRunning() { + cpuTimer = Timer(timeInterval: 5.0, repeats: true, block: { [weak self] _ in + self?.updateUsage() + }) + RunLoop.main.add(cpuTimer!, forMode: .common) + cpuTimer?.fire() + } + + private func stopRunning() { + runnerTimer?.invalidate() + cpuTimer?.invalidate() + } +} diff --git a/Menubar RunCat/Assets.xcassets/Contents.json b/Menubar RunCat/Assets.xcassets/Contents.json index da4a164..73c0059 100644 --- a/Menubar RunCat/Assets.xcassets/Contents.json +++ b/Menubar RunCat/Assets.xcassets/Contents.json @@ -1,6 +1,6 @@ { "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } -} \ No newline at end of file +} diff --git a/Menubar RunCat/Assets.xcassets/cat_page0.imageset/Contents.json b/Menubar RunCat/Assets.xcassets/cat_page0.imageset/Contents.json index 9fcf337..a8bc829 100644 --- a/Menubar RunCat/Assets.xcassets/cat_page0.imageset/Contents.json +++ b/Menubar RunCat/Assets.xcassets/cat_page0.imageset/Contents.json @@ -1,20 +1,15 @@ { "images" : [ { - "idiom" : "mac", - "scale" : "1x" - }, - { - "idiom" : "mac", "filename" : "cat0.png", - "scale" : "2x" + "idiom" : "mac" } ], "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 }, "properties" : { "template-rendering-intent" : "template" } -} \ No newline at end of file +} diff --git a/Menubar RunCat/Assets.xcassets/cat_page1.imageset/Contents.json b/Menubar RunCat/Assets.xcassets/cat_page1.imageset/Contents.json index 2bf94cd..b50e0f6 100644 --- a/Menubar RunCat/Assets.xcassets/cat_page1.imageset/Contents.json +++ b/Menubar RunCat/Assets.xcassets/cat_page1.imageset/Contents.json @@ -1,20 +1,15 @@ { "images" : [ { - "idiom" : "mac", - "scale" : "1x" - }, - { - "idiom" : "mac", "filename" : "cat1.png", - "scale" : "2x" + "idiom" : "mac" } ], "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 }, "properties" : { "template-rendering-intent" : "template" } -} \ No newline at end of file +} diff --git a/Menubar RunCat/Assets.xcassets/cat_page2.imageset/Contents.json b/Menubar RunCat/Assets.xcassets/cat_page2.imageset/Contents.json index 364dd19..e02e97c 100644 --- a/Menubar RunCat/Assets.xcassets/cat_page2.imageset/Contents.json +++ b/Menubar RunCat/Assets.xcassets/cat_page2.imageset/Contents.json @@ -1,20 +1,15 @@ { "images" : [ { - "idiom" : "mac", - "scale" : "1x" - }, - { - "idiom" : "mac", "filename" : "cat2.png", - "scale" : "2x" + "idiom" : "mac" } ], "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 }, "properties" : { "template-rendering-intent" : "template" } -} \ No newline at end of file +} diff --git a/Menubar RunCat/Assets.xcassets/cat_page3.imageset/Contents.json b/Menubar RunCat/Assets.xcassets/cat_page3.imageset/Contents.json index af127ff..d53d294 100644 --- a/Menubar RunCat/Assets.xcassets/cat_page3.imageset/Contents.json +++ b/Menubar RunCat/Assets.xcassets/cat_page3.imageset/Contents.json @@ -1,20 +1,15 @@ { "images" : [ { - "idiom" : "mac", - "scale" : "1x" - }, - { - "idiom" : "mac", "filename" : "cat3.png", - "scale" : "2x" + "idiom" : "mac" } ], "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 }, "properties" : { "template-rendering-intent" : "template" } -} \ No newline at end of file +} diff --git a/Menubar RunCat/Assets.xcassets/cat_page4.imageset/Contents.json b/Menubar RunCat/Assets.xcassets/cat_page4.imageset/Contents.json index 1e85fe5..f769f77 100644 --- a/Menubar RunCat/Assets.xcassets/cat_page4.imageset/Contents.json +++ b/Menubar RunCat/Assets.xcassets/cat_page4.imageset/Contents.json @@ -1,20 +1,15 @@ { "images" : [ { - "idiom" : "mac", - "scale" : "1x" - }, - { - "idiom" : "mac", "filename" : "cat4.png", - "scale" : "2x" + "idiom" : "mac" } ], "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 }, "properties" : { "template-rendering-intent" : "template" } -} \ No newline at end of file +} diff --git a/Menubar RunCat/Base.lproj/Main.storyboard b/Menubar RunCat/Base.lproj/Main.storyboard deleted file mode 100644 index 4570384..0000000 --- a/Menubar RunCat/Base.lproj/Main.storyboard +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Menubar RunCat/CPU.swift b/Menubar RunCat/CPU.swift index 94b2e4a..210449c 100644 --- a/Menubar RunCat/CPU.swift +++ b/Menubar RunCat/CPU.swift @@ -1,15 +1,18 @@ -// -// CPU.swift -// Menubar RunCat -// -// Created by Takuto Nakamura on 2019/08/06. -// Copyright © 2019 Takuto Nakamura. All rights reserved. -// +/* + CPU.swift + Menubar RunCat + + Created by Takuto Nakamura on 2019/08/06. + Copyright © 2019 Takuto Nakamura. All rights reserved. +*/ import Darwin -public class CPU { - +typealias CPUInfo = (value: Double, description: String) + +final class CPU { + static let `default` = CPUInfo(0.0, " 0.0% ") + private let loadInfoCount: mach_msg_type_number_t! private var loadPrevious = host_cpu_load_info() @@ -20,18 +23,15 @@ public class CPU { private func hostCPULoadInfo() -> host_cpu_load_info { var size: mach_msg_type_number_t = loadInfoCount let hostInfo = host_cpu_load_info_t.allocate(capacity: 1) - let _ = hostInfo.withMemoryRebound(to: integer_t.self, capacity: Int(size)) { (pointer) -> kern_return_t in return host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, pointer, &size) } - // kern_return_t == KERN_SUCCESS let data = hostInfo.move() hostInfo.deallocate() - return data } - public func usageCPU() -> (value: Double, description: String) { + func currentUsage() -> CPUInfo { let load = hostCPULoadInfo() let userDiff = Double(load.cpu_ticks.0 - loadPrevious.cpu_ticks.0) let sysDiff = Double(load.cpu_ticks.1 - loadPrevious.cpu_ticks.1) @@ -42,11 +42,10 @@ public class CPU { let totalTicks = sysDiff + userDiff + idleDiff + niceDiff let sys = 100.0 * sysDiff / totalTicks let user = 100.0 * userDiff / totalTicks + + let value = min(99.9, (10.0 * (sys + user)).rounded() / 10.0) + let description = String(format: "%4.1f%%", value) - let value: Double = round((sys + user) * 10.0) / 10.0 - let description: String = (value >= 100.0) ? "100↑%" : ((value < 10.0 ? " " : "") + String(value)) + "% " - - return (value, description) + return CPUInfo(value, description) } - } diff --git a/Menubar RunCat/Info.plist b/Menubar RunCat/Info.plist index cd774ce..bc11256 100644 --- a/Menubar RunCat/Info.plist +++ b/Menubar RunCat/Info.plist @@ -2,35 +2,7 @@ - CFBundleDevelopmentRegion - $(DEVELOPMENT_LANGUAGE) - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIconFile - - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - APPL - CFBundleShortVersionString - 1.0 - CFBundleVersion - 1.0.0 - LSApplicationCategoryType - public.app-category.utilities - LSMinimumSystemVersion - $(MACOSX_DEPLOYMENT_TARGET) - LSUIElement - - NSHumanReadableCopyright - Copyright © 2019 Takuto Nakamura. All rights reserved. - NSMainStoryboardFile - Main - NSPrincipalClass - NSApplication + ITSAppUsesNonExemptEncryption + diff --git a/Menubar RunCat/main.swift b/Menubar RunCat/main.swift new file mode 100644 index 0000000..50af22d --- /dev/null +++ b/Menubar RunCat/main.swift @@ -0,0 +1,13 @@ +/* + main.swift + Menubar RunCat + + Created by Takuto Nakamura on 2023/05/19. + Copyright © 2023 Takuto Nakamura. All rights reserved. +*/ + +import Cocoa + +let delegate = AppDelegate() +NSApplication.shared.delegate = delegate +_ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv) diff --git a/README b/README deleted file mode 100644 index e965047..0000000 --- a/README +++ /dev/null @@ -1 +0,0 @@ -Hello