@ -0,0 +1,334 @@ | |||||
// !$*UTF8*$! | |||||
{ | |||||
archiveVersion = 1; | |||||
classes = { | |||||
}; | |||||
objectVersion = 50; | |||||
objects = { | |||||
/* Begin PBXBuildFile section */ | |||||
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 */ | |||||
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>"; }; | |||||
/* End PBXFileReference section */ | |||||
/* Begin PBXFrameworksBuildPhase section */ | |||||
1CEF109922F922DB00DAD355 /* Frameworks */ = { | |||||
isa = PBXFrameworksBuildPhase; | |||||
buildActionMask = 2147483647; | |||||
files = ( | |||||
); | |||||
runOnlyForDeploymentPostprocessing = 0; | |||||
}; | |||||
/* End PBXFrameworksBuildPhase section */ | |||||
/* Begin PBXGroup section */ | |||||
1CEF109322F922DB00DAD355 = { | |||||
isa = PBXGroup; | |||||
children = ( | |||||
1CEF109E22F922DB00DAD355 /* Menubar RunCat */, | |||||
1CEF109D22F922DB00DAD355 /* Products */, | |||||
); | |||||
sourceTree = "<group>"; | |||||
}; | |||||
1CEF109D22F922DB00DAD355 /* Products */ = { | |||||
isa = PBXGroup; | |||||
children = ( | |||||
1CEF109C22F922DB00DAD355 /* Menubar RunCat.app */, | |||||
); | |||||
name = Products; | |||||
sourceTree = "<group>"; | |||||
}; | |||||
1CEF109E22F922DB00DAD355 /* Menubar RunCat */ = { | |||||
isa = PBXGroup; | |||||
children = ( | |||||
1CEF109F22F922DB00DAD355 /* AppDelegate.swift */, | |||||
1CEF10AF22F9342600DAD355 /* CPU.swift */, | |||||
1CEF10A322F922DD00DAD355 /* Assets.xcassets */, | |||||
1CEF10A522F922DD00DAD355 /* Main.storyboard */, | |||||
1CEF10A822F922DD00DAD355 /* Info.plist */, | |||||
1CEF10A922F922DD00DAD355 /* Menubar_RunCat.entitlements */, | |||||
); | |||||
path = "Menubar RunCat"; | |||||
sourceTree = "<group>"; | |||||
}; | |||||
/* End PBXGroup section */ | |||||
/* Begin PBXNativeTarget section */ | |||||
1CEF109B22F922DB00DAD355 /* Menubar RunCat */ = { | |||||
isa = PBXNativeTarget; | |||||
buildConfigurationList = 1CEF10AC22F922DD00DAD355 /* Build configuration list for PBXNativeTarget "Menubar RunCat" */; | |||||
buildPhases = ( | |||||
1CEF109822F922DB00DAD355 /* Sources */, | |||||
1CEF109922F922DB00DAD355 /* Frameworks */, | |||||
1CEF109A22F922DB00DAD355 /* Resources */, | |||||
); | |||||
buildRules = ( | |||||
); | |||||
dependencies = ( | |||||
); | |||||
name = "Menubar RunCat"; | |||||
productName = "Menubar RunCat"; | |||||
productReference = 1CEF109C22F922DB00DAD355 /* Menubar RunCat.app */; | |||||
productType = "com.apple.product-type.application"; | |||||
}; | |||||
/* End PBXNativeTarget section */ | |||||
/* Begin PBXProject section */ | |||||
1CEF109422F922DB00DAD355 /* Project object */ = { | |||||
isa = PBXProject; | |||||
attributes = { | |||||
LastSwiftUpdateCheck = 1030; | |||||
LastUpgradeCheck = 1030; | |||||
ORGANIZATIONNAME = "Takuto Nakamura"; | |||||
TargetAttributes = { | |||||
1CEF109B22F922DB00DAD355 = { | |||||
CreatedOnToolsVersion = 10.3; | |||||
}; | |||||
}; | |||||
}; | |||||
buildConfigurationList = 1CEF109722F922DB00DAD355 /* Build configuration list for PBXProject "Menubar RunCat" */; | |||||
compatibilityVersion = "Xcode 9.3"; | |||||
developmentRegion = en; | |||||
hasScannedForEncodings = 0; | |||||
knownRegions = ( | |||||
en, | |||||
Base, | |||||
); | |||||
mainGroup = 1CEF109322F922DB00DAD355; | |||||
productRefGroup = 1CEF109D22F922DB00DAD355 /* Products */; | |||||
projectDirPath = ""; | |||||
projectRoot = ""; | |||||
targets = ( | |||||
1CEF109B22F922DB00DAD355 /* Menubar RunCat */, | |||||
); | |||||
}; | |||||
/* End PBXProject section */ | |||||
/* Begin PBXResourcesBuildPhase section */ | |||||
1CEF109A22F922DB00DAD355 /* Resources */ = { | |||||
isa = PBXResourcesBuildPhase; | |||||
buildActionMask = 2147483647; | |||||
files = ( | |||||
1CEF10A422F922DD00DAD355 /* Assets.xcassets in Resources */, | |||||
1CEF10A722F922DD00DAD355 /* Main.storyboard in Resources */, | |||||
); | |||||
runOnlyForDeploymentPostprocessing = 0; | |||||
}; | |||||
/* End PBXResourcesBuildPhase section */ | |||||
/* Begin PBXSourcesBuildPhase section */ | |||||
1CEF109822F922DB00DAD355 /* Sources */ = { | |||||
isa = PBXSourcesBuildPhase; | |||||
buildActionMask = 2147483647; | |||||
files = ( | |||||
1CEF10B022F9342600DAD355 /* CPU.swift in Sources */, | |||||
1CEF10A022F922DB00DAD355 /* AppDelegate.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; | |||||
buildSettings = { | |||||
ALWAYS_SEARCH_USER_PATHS = NO; | |||||
CLANG_ANALYZER_NONNULL = YES; | |||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; | |||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; | |||||
CLANG_CXX_LIBRARY = "libc++"; | |||||
CLANG_ENABLE_MODULES = YES; | |||||
CLANG_ENABLE_OBJC_ARC = YES; | |||||
CLANG_ENABLE_OBJC_WEAK = YES; | |||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; | |||||
CLANG_WARN_BOOL_CONVERSION = YES; | |||||
CLANG_WARN_COMMA = YES; | |||||
CLANG_WARN_CONSTANT_CONVERSION = YES; | |||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; | |||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; | |||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES; | |||||
CLANG_WARN_EMPTY_BODY = YES; | |||||
CLANG_WARN_ENUM_CONVERSION = YES; | |||||
CLANG_WARN_INFINITE_RECURSION = YES; | |||||
CLANG_WARN_INT_CONVERSION = YES; | |||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; | |||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; | |||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; | |||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; | |||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; | |||||
CLANG_WARN_STRICT_PROTOTYPES = YES; | |||||
CLANG_WARN_SUSPICIOUS_MOVE = YES; | |||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; | |||||
CLANG_WARN_UNREACHABLE_CODE = YES; | |||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; | |||||
CODE_SIGN_IDENTITY = "Mac Developer"; | |||||
COPY_PHASE_STRIP = NO; | |||||
DEBUG_INFORMATION_FORMAT = dwarf; | |||||
ENABLE_STRICT_OBJC_MSGSEND = YES; | |||||
ENABLE_TESTABILITY = YES; | |||||
GCC_C_LANGUAGE_STANDARD = gnu11; | |||||
GCC_DYNAMIC_NO_PIC = NO; | |||||
GCC_NO_COMMON_BLOCKS = YES; | |||||
GCC_OPTIMIZATION_LEVEL = 0; | |||||
GCC_PREPROCESSOR_DEFINITIONS = ( | |||||
"DEBUG=1", | |||||
"$(inherited)", | |||||
); | |||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; | |||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; | |||||
GCC_WARN_UNDECLARED_SELECTOR = YES; | |||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; | |||||
GCC_WARN_UNUSED_FUNCTION = YES; | |||||
GCC_WARN_UNUSED_VARIABLE = YES; | |||||
MACOSX_DEPLOYMENT_TARGET = 10.14; | |||||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; | |||||
MTL_FAST_MATH = YES; | |||||
ONLY_ACTIVE_ARCH = YES; | |||||
SDKROOT = macosx; | |||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; | |||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; | |||||
}; | |||||
name = Debug; | |||||
}; | |||||
1CEF10AB22F922DD00DAD355 /* Release */ = { | |||||
isa = XCBuildConfiguration; | |||||
buildSettings = { | |||||
ALWAYS_SEARCH_USER_PATHS = NO; | |||||
CLANG_ANALYZER_NONNULL = YES; | |||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; | |||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; | |||||
CLANG_CXX_LIBRARY = "libc++"; | |||||
CLANG_ENABLE_MODULES = YES; | |||||
CLANG_ENABLE_OBJC_ARC = YES; | |||||
CLANG_ENABLE_OBJC_WEAK = YES; | |||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; | |||||
CLANG_WARN_BOOL_CONVERSION = YES; | |||||
CLANG_WARN_COMMA = YES; | |||||
CLANG_WARN_CONSTANT_CONVERSION = YES; | |||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; | |||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; | |||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES; | |||||
CLANG_WARN_EMPTY_BODY = YES; | |||||
CLANG_WARN_ENUM_CONVERSION = YES; | |||||
CLANG_WARN_INFINITE_RECURSION = YES; | |||||
CLANG_WARN_INT_CONVERSION = YES; | |||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; | |||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; | |||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; | |||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; | |||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; | |||||
CLANG_WARN_STRICT_PROTOTYPES = YES; | |||||
CLANG_WARN_SUSPICIOUS_MOVE = YES; | |||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; | |||||
CLANG_WARN_UNREACHABLE_CODE = YES; | |||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; | |||||
CODE_SIGN_IDENTITY = "Mac Developer"; | |||||
COPY_PHASE_STRIP = NO; | |||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; | |||||
ENABLE_NS_ASSERTIONS = NO; | |||||
ENABLE_STRICT_OBJC_MSGSEND = YES; | |||||
GCC_C_LANGUAGE_STANDARD = gnu11; | |||||
GCC_NO_COMMON_BLOCKS = YES; | |||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; | |||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; | |||||
GCC_WARN_UNDECLARED_SELECTOR = YES; | |||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; | |||||
GCC_WARN_UNUSED_FUNCTION = YES; | |||||
GCC_WARN_UNUSED_VARIABLE = YES; | |||||
MACOSX_DEPLOYMENT_TARGET = 10.14; | |||||
MTL_ENABLE_DEBUG_INFO = NO; | |||||
MTL_FAST_MATH = YES; | |||||
SDKROOT = macosx; | |||||
SWIFT_COMPILATION_MODE = wholemodule; | |||||
SWIFT_OPTIMIZATION_LEVEL = "-O"; | |||||
}; | |||||
name = Release; | |||||
}; | |||||
1CEF10AD22F922DD00DAD355 /* Debug */ = { | |||||
isa = XCBuildConfiguration; | |||||
buildSettings = { | |||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; | |||||
CODE_SIGN_ENTITLEMENTS = "Menubar RunCat/Menubar_RunCat.entitlements"; | |||||
CODE_SIGN_STYLE = Automatic; | |||||
COMBINE_HIDPI_IMAGES = YES; | |||||
DEVELOPMENT_TEAM = VJ5N2X84K8; | |||||
INFOPLIST_FILE = "Menubar RunCat/Info.plist"; | |||||
LD_RUNPATH_SEARCH_PATHS = ( | |||||
"$(inherited)", | |||||
"@executable_path/../Frameworks", | |||||
); | |||||
MACOSX_DEPLOYMENT_TARGET = 10.12; | |||||
PRODUCT_BUNDLE_IDENTIFIER = "com.kyome.menubar-runcat"; | |||||
PRODUCT_NAME = "$(TARGET_NAME)"; | |||||
SWIFT_VERSION = 5.0; | |||||
}; | |||||
name = Debug; | |||||
}; | |||||
1CEF10AE22F922DD00DAD355 /* Release */ = { | |||||
isa = XCBuildConfiguration; | |||||
buildSettings = { | |||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; | |||||
CODE_SIGN_ENTITLEMENTS = "Menubar RunCat/Menubar_RunCat.entitlements"; | |||||
CODE_SIGN_STYLE = Automatic; | |||||
COMBINE_HIDPI_IMAGES = YES; | |||||
DEVELOPMENT_TEAM = VJ5N2X84K8; | |||||
INFOPLIST_FILE = "Menubar RunCat/Info.plist"; | |||||
LD_RUNPATH_SEARCH_PATHS = ( | |||||
"$(inherited)", | |||||
"@executable_path/../Frameworks", | |||||
); | |||||
MACOSX_DEPLOYMENT_TARGET = 10.12; | |||||
PRODUCT_BUNDLE_IDENTIFIER = "com.kyome.menubar-runcat"; | |||||
PRODUCT_NAME = "$(TARGET_NAME)"; | |||||
SWIFT_VERSION = 5.0; | |||||
}; | |||||
name = Release; | |||||
}; | |||||
/* End XCBuildConfiguration section */ | |||||
/* Begin XCConfigurationList section */ | |||||
1CEF109722F922DB00DAD355 /* Build configuration list for PBXProject "Menubar RunCat" */ = { | |||||
isa = XCConfigurationList; | |||||
buildConfigurations = ( | |||||
1CEF10AA22F922DD00DAD355 /* Debug */, | |||||
1CEF10AB22F922DD00DAD355 /* Release */, | |||||
); | |||||
defaultConfigurationIsVisible = 0; | |||||
defaultConfigurationName = Release; | |||||
}; | |||||
1CEF10AC22F922DD00DAD355 /* Build configuration list for PBXNativeTarget "Menubar RunCat" */ = { | |||||
isa = XCConfigurationList; | |||||
buildConfigurations = ( | |||||
1CEF10AD22F922DD00DAD355 /* Debug */, | |||||
1CEF10AE22F922DD00DAD355 /* Release */, | |||||
); | |||||
defaultConfigurationIsVisible = 0; | |||||
defaultConfigurationName = Release; | |||||
}; | |||||
/* End XCConfigurationList section */ | |||||
}; | |||||
rootObject = 1CEF109422F922DB00DAD355 /* Project object */; | |||||
} |
@ -0,0 +1,7 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<Workspace | |||||
version = "1.0"> | |||||
<FileRef | |||||
location = "self:Menubar RunCat.xcodeproj"> | |||||
</FileRef> | |||||
</Workspace> |
@ -0,0 +1,8 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |||||
<plist version="1.0"> | |||||
<dict> | |||||
<key>IDEDidComputeMac32BitWarning</key> | |||||
<true/> | |||||
</dict> | |||||
</plist> |
@ -0,0 +1,14 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |||||
<plist version="1.0"> | |||||
<dict> | |||||
<key>SchemeUserState</key> | |||||
<dict> | |||||
<key>Menubar RunCat.xcscheme_^#shared#^_</key> | |||||
<dict> | |||||
<key>orderHint</key> | |||||
<integer>0</integer> | |||||
</dict> | |||||
</dict> | |||||
</dict> | |||||
</plist> |
@ -0,0 +1,95 @@ | |||||
// | |||||
// 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 | |||||
private var interval: Double = 1.0 | |||||
private let cpu = CPU() | |||||
private var cpuTimer: Timer? = nil | |||||
private var usage: (value: Double, description: String) = (0.0, "") | |||||
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 | |||||
startRunning() | |||||
} | |||||
func applicationWillTerminate(_ aNotification: 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 | |||||
statusItem.button?.title = isShowUsage ? usage.description : "" | |||||
} | |||||
@IBAction func showAbout(_ sender: Any) { | |||||
NSApp.activate(ignoringOtherApps: true) | |||||
NSApp.orderFrontStandardAboutPanel(nil) | |||||
} | |||||
} | |||||
@ -0,0 +1,68 @@ | |||||
{ | |||||
"images" : [ | |||||
{ | |||||
"size" : "16x16", | |||||
"idiom" : "mac", | |||||
"filename" : "Icon-App-16x16@1x.png", | |||||
"scale" : "1x" | |||||
}, | |||||
{ | |||||
"size" : "16x16", | |||||
"idiom" : "mac", | |||||
"filename" : "Icon-App-16x16@2x.png", | |||||
"scale" : "2x" | |||||
}, | |||||
{ | |||||
"size" : "32x32", | |||||
"idiom" : "mac", | |||||
"filename" : "Icon-App-32x32@1x.png", | |||||
"scale" : "1x" | |||||
}, | |||||
{ | |||||
"size" : "32x32", | |||||
"idiom" : "mac", | |||||
"filename" : "Icon-App-32x32@2x.png", | |||||
"scale" : "2x" | |||||
}, | |||||
{ | |||||
"size" : "128x128", | |||||
"idiom" : "mac", | |||||
"filename" : "Icon-App-128x128@1x.png", | |||||
"scale" : "1x" | |||||
}, | |||||
{ | |||||
"size" : "128x128", | |||||
"idiom" : "mac", | |||||
"filename" : "Icon-App-128x128@2x.png", | |||||
"scale" : "2x" | |||||
}, | |||||
{ | |||||
"size" : "256x256", | |||||
"idiom" : "mac", | |||||
"filename" : "Icon-App-256x256@1x.png", | |||||
"scale" : "1x" | |||||
}, | |||||
{ | |||||
"size" : "256x256", | |||||
"idiom" : "mac", | |||||
"filename" : "Icon-App-256x256@2x.png", | |||||
"scale" : "2x" | |||||
}, | |||||
{ | |||||
"size" : "512x512", | |||||
"idiom" : "mac", | |||||
"filename" : "Icon-App-512x512@1x.png", | |||||
"scale" : "1x" | |||||
}, | |||||
{ | |||||
"size" : "512x512", | |||||
"idiom" : "mac", | |||||
"filename" : "Icon-App-512x512@2x.png", | |||||
"scale" : "2x" | |||||
} | |||||
], | |||||
"info" : { | |||||
"version" : 1, | |||||
"author" : "xcode" | |||||
} | |||||
} |
@ -0,0 +1,6 @@ | |||||
{ | |||||
"info" : { | |||||
"version" : 1, | |||||
"author" : "xcode" | |||||
} | |||||
} |
@ -0,0 +1,20 @@ | |||||
{ | |||||
"images" : [ | |||||
{ | |||||
"idiom" : "mac", | |||||
"scale" : "1x" | |||||
}, | |||||
{ | |||||
"idiom" : "mac", | |||||
"filename" : "cat0.png", | |||||
"scale" : "2x" | |||||
} | |||||
], | |||||
"info" : { | |||||
"version" : 1, | |||||
"author" : "xcode" | |||||
}, | |||||
"properties" : { | |||||
"template-rendering-intent" : "template" | |||||
} | |||||
} |
@ -0,0 +1,20 @@ | |||||
{ | |||||
"images" : [ | |||||
{ | |||||
"idiom" : "mac", | |||||
"scale" : "1x" | |||||
}, | |||||
{ | |||||
"idiom" : "mac", | |||||
"filename" : "cat1.png", | |||||
"scale" : "2x" | |||||
} | |||||
], | |||||
"info" : { | |||||
"version" : 1, | |||||
"author" : "xcode" | |||||
}, | |||||
"properties" : { | |||||
"template-rendering-intent" : "template" | |||||
} | |||||
} |
@ -0,0 +1,20 @@ | |||||
{ | |||||
"images" : [ | |||||
{ | |||||
"idiom" : "mac", | |||||
"scale" : "1x" | |||||
}, | |||||
{ | |||||
"idiom" : "mac", | |||||
"filename" : "cat2.png", | |||||
"scale" : "2x" | |||||
} | |||||
], | |||||
"info" : { | |||||
"version" : 1, | |||||
"author" : "xcode" | |||||
}, | |||||
"properties" : { | |||||
"template-rendering-intent" : "template" | |||||
} | |||||
} |
@ -0,0 +1,20 @@ | |||||
{ | |||||
"images" : [ | |||||
{ | |||||
"idiom" : "mac", | |||||
"scale" : "1x" | |||||
}, | |||||
{ | |||||
"idiom" : "mac", | |||||
"filename" : "cat3.png", | |||||
"scale" : "2x" | |||||
} | |||||
], | |||||
"info" : { | |||||
"version" : 1, | |||||
"author" : "xcode" | |||||
}, | |||||
"properties" : { | |||||
"template-rendering-intent" : "template" | |||||
} | |||||
} |
@ -0,0 +1,20 @@ | |||||
{ | |||||
"images" : [ | |||||
{ | |||||
"idiom" : "mac", | |||||
"scale" : "1x" | |||||
}, | |||||
{ | |||||
"idiom" : "mac", | |||||
"filename" : "cat4.png", | |||||
"scale" : "2x" | |||||
} | |||||
], | |||||
"info" : { | |||||
"version" : 1, | |||||
"author" : "xcode" | |||||
}, | |||||
"properties" : { | |||||
"template-rendering-intent" : "template" | |||||
} | |||||
} |
@ -0,0 +1,67 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> | |||||
<dependencies> | |||||
<deployment identifier="macosx"/> | |||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/> | |||||
</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> |
@ -0,0 +1,52 @@ | |||||
// | |||||
// CPU.swift | |||||
// Menubar RunCat | |||||
// | |||||
// Created by Takuto Nakamura on 2019/08/06. | |||||
// Copyright © 2019 Takuto Nakamura. All rights reserved. | |||||
// | |||||
import Darwin | |||||
public class CPU { | |||||
private let loadInfoCount: mach_msg_type_number_t! | |||||
private var loadPrevious = host_cpu_load_info() | |||||
init() { | |||||
loadInfoCount = UInt32(MemoryLayout<host_cpu_load_info_data_t>.size / MemoryLayout<integer_t>.size) | |||||
} | |||||
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) { | |||||
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) | |||||
let idleDiff = Double(load.cpu_ticks.2 - loadPrevious.cpu_ticks.2) | |||||
let niceDiff = Double(load.cpu_ticks.3 - loadPrevious.cpu_ticks.3) | |||||
loadPrevious = load | |||||
let totalTicks = sysDiff + userDiff + idleDiff + niceDiff | |||||
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)) + "% " | |||||
return (value, description) | |||||
} | |||||
} |
@ -0,0 +1,36 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<!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> | |||||
</dict> | |||||
</plist> |
@ -0,0 +1,10 @@ | |||||
<?xml version="1.0" encoding="UTF-8"?> | |||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |||||
<plist version="1.0"> | |||||
<dict> | |||||
<key>com.apple.security.app-sandbox</key> | |||||
<true/> | |||||
<key>com.apple.security.files.user-selected.read-only</key> | |||||
<true/> | |||||
</dict> | |||||
</plist> |