Update for Xcode14.3
This commit is contained in:
parent
1b5ac6f492
commit
5c67c1928c
@ -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 = "<group>"; };
|
||||
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 = "<group>"; };
|
||||
1CEF10A322F922DD00DAD355 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
1CEF10A622F922DD00DAD355 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
1CEF10A822F922DD00DAD355 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
1CEF10A922F922DD00DAD355 /* Menubar_RunCat.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Menubar_RunCat.entitlements; sourceTree = "<group>"; };
|
||||
1CEF10AF22F9342600DAD355 /* CPU.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CPU.swift; sourceTree = "<group>"; };
|
||||
@ -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 = "<group>";
|
||||
};
|
||||
/* 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;
|
||||
|
Binary file not shown.
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
@ -1,18 +1,13 @@
|
||||
{
|
||||
"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"
|
||||
|
@ -1,18 +1,13 @@
|
||||
{
|
||||
"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"
|
||||
|
@ -1,18 +1,13 @@
|
||||
{
|
||||
"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"
|
||||
|
@ -1,18 +1,13 @@
|
||||
{
|
||||
"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"
|
||||
|
@ -1,18 +1,13 @@
|
||||
{
|
||||
"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"
|
||||
|
@ -1,67 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="17156" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17156"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Application-->
|
||||
<scene sceneID="JPo-4y-FX3">
|
||||
<objects>
|
||||
<application id="hnw-xV-0zn" sceneMemberID="viewController">
|
||||
<menu key="mainMenu" title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
|
||||
<items>
|
||||
<menuItem title="Menubar RunCat" id="1Xt-HY-uBw">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Menubar RunCat" systemMenu="apple" id="uQy-DD-JDr">
|
||||
<items>
|
||||
<menuItem title="About Menubar RunCat" id="5kV-Vb-QxS">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
|
||||
<menuItem title="Quit Menubar RunCat" id="4sb-4s-VLi">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
<connections>
|
||||
<outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/>
|
||||
</connections>
|
||||
</application>
|
||||
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="Menubar_RunCat" customModuleProvider="target">
|
||||
<connections>
|
||||
<outlet property="menu" destination="p9w-zP-csW" id="lzr-DG-WJX"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
|
||||
<menu id="p9w-zP-csW">
|
||||
<items>
|
||||
<menuItem title="Show CPU Usage" id="igF-HN-MW8">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="toggleShowUsage:" target="Voe-Tx-rLC" id="udX-at-y7i"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="About Menubar RunCat" id="Brf-nN-lus">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="showAbout:" target="Voe-Tx-rLC" id="WRn-u0-7zp"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Quit" tag="1" id="SYX-4G-YIS">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="terminate:" target="Ady-hI-5gd" id="ewY-2s-NLb"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="75" y="0.0"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
@ -1,14 +1,17 @@
|
||||
//
|
||||
// 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)
|
||||
@ -43,10 +43,9 @@ public class CPU {
|
||||
let sys = 100.0 * sysDiff / totalTicks
|
||||
let user = 100.0 * userDiff / totalTicks
|
||||
|
||||
let value: Double = round((sys + user) * 10.0) / 10.0
|
||||
let description: String = (value >= 100.0) ? "100↑%" : ((value < 10.0 ? " " : "") + String(value)) + "% "
|
||||
let value = min(99.9, (10.0 * (sys + user)).rounded() / 10.0)
|
||||
let description = String(format: "%4.1f%%", value)
|
||||
|
||||
return (value, description)
|
||||
return CPUInfo(value, description)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,35 +2,7 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0.0</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.utilities</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
||||
<key>LSUIElement</key>
|
||||
<true/>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2019 Takuto Nakamura. All rights reserved.</string>
|
||||
<key>NSMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
13
Menubar RunCat/main.swift
Normal file
13
Menubar RunCat/main.swift
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user