diff --git a/Menubar RunCat/Menubar RunCat.xcodeproj/project.pbxproj b/Menubar RunCat/Menubar RunCat.xcodeproj/project.pbxproj new file mode 100644 index 0000000..b59b194 --- /dev/null +++ b/Menubar RunCat/Menubar RunCat.xcodeproj/project.pbxproj @@ -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 = ""; }; + 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 = ""; }; +/* 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 = ""; + }; + 1CEF109D22F922DB00DAD355 /* Products */ = { + isa = PBXGroup; + children = ( + 1CEF109C22F922DB00DAD355 /* Menubar RunCat.app */, + ); + name = Products; + sourceTree = ""; + }; + 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 = ""; + }; +/* 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 = ""; + }; +/* 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 */; +} diff --git a/Menubar RunCat/Menubar RunCat.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Menubar RunCat/Menubar RunCat.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..b11c22f --- /dev/null +++ b/Menubar RunCat/Menubar RunCat.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Menubar RunCat/Menubar RunCat.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Menubar RunCat/Menubar RunCat.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Menubar RunCat/Menubar RunCat.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Menubar RunCat/Menubar RunCat.xcodeproj/project.xcworkspace/xcuserdata/takuto.xcuserdatad/UserInterfaceState.xcuserstate b/Menubar RunCat/Menubar RunCat.xcodeproj/project.xcworkspace/xcuserdata/takuto.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..8d89af7 Binary files /dev/null and b/Menubar RunCat/Menubar RunCat.xcodeproj/project.xcworkspace/xcuserdata/takuto.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Menubar RunCat/Menubar RunCat.xcodeproj/xcuserdata/takuto.xcuserdatad/xcschemes/xcschememanagement.plist b/Menubar RunCat/Menubar RunCat.xcodeproj/xcuserdata/takuto.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..999339d --- /dev/null +++ b/Menubar RunCat/Menubar RunCat.xcodeproj/xcuserdata/takuto.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + Menubar RunCat.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/Menubar RunCat/Menubar RunCat/AppDelegate.swift b/Menubar RunCat/Menubar RunCat/AppDelegate.swift new file mode 100644 index 0000000..3c9b609 --- /dev/null +++ b/Menubar RunCat/Menubar RunCat/AppDelegate.swift @@ -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) + } + +} + diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Contents.json b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..7098b7c --- /dev/null +++ b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -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" + } +} \ No newline at end of file diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-128x128@1x.png b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-128x128@1x.png new file mode 100644 index 0000000..d78a144 Binary files /dev/null and b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-128x128@1x.png differ diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-128x128@2x.png b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-128x128@2x.png new file mode 100644 index 0000000..9a23241 Binary files /dev/null and b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-128x128@2x.png differ diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-16x16@1x.png b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-16x16@1x.png new file mode 100644 index 0000000..88b3ea2 Binary files /dev/null and b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-16x16@1x.png differ diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-16x16@2x.png b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-16x16@2x.png new file mode 100644 index 0000000..28d6d41 Binary files /dev/null and b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-16x16@2x.png differ diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-256x256@1x.png b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-256x256@1x.png new file mode 100644 index 0000000..9a23241 Binary files /dev/null and b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-256x256@1x.png differ diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-256x256@2x.png b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-256x256@2x.png new file mode 100644 index 0000000..4722455 Binary files /dev/null and b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-256x256@2x.png differ diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-32x32@1x.png b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-32x32@1x.png new file mode 100644 index 0000000..9bdefd6 Binary files /dev/null and b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-32x32@1x.png differ diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-32x32@2x.png b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-32x32@2x.png new file mode 100644 index 0000000..80aca8c Binary files /dev/null and b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-32x32@2x.png differ diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-512x512@1x.png b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-512x512@1x.png new file mode 100644 index 0000000..4722455 Binary files /dev/null and b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-512x512@1x.png differ diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-512x512@2x.png b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-512x512@2x.png new file mode 100644 index 0000000..dad06a5 Binary files /dev/null and b/Menubar RunCat/Menubar RunCat/Assets.xcassets/AppIcon.appiconset/Icon-App-512x512@2x.png differ diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/Contents.json b/Menubar RunCat/Menubar RunCat/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/Menubar RunCat/Menubar RunCat/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page0.imageset/Contents.json b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page0.imageset/Contents.json new file mode 100644 index 0000000..9fcf337 --- /dev/null +++ b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page0.imageset/Contents.json @@ -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" + } +} \ No newline at end of file diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page0.imageset/cat0.png b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page0.imageset/cat0.png new file mode 100644 index 0000000..215665a Binary files /dev/null and b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page0.imageset/cat0.png differ diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page1.imageset/Contents.json b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page1.imageset/Contents.json new file mode 100644 index 0000000..2bf94cd --- /dev/null +++ b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page1.imageset/Contents.json @@ -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" + } +} \ No newline at end of file diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page1.imageset/cat1.png b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page1.imageset/cat1.png new file mode 100644 index 0000000..a9671cf Binary files /dev/null and b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page1.imageset/cat1.png differ diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page2.imageset/Contents.json b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page2.imageset/Contents.json new file mode 100644 index 0000000..364dd19 --- /dev/null +++ b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page2.imageset/Contents.json @@ -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" + } +} \ No newline at end of file diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page2.imageset/cat2.png b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page2.imageset/cat2.png new file mode 100644 index 0000000..d0ecaeb Binary files /dev/null and b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page2.imageset/cat2.png differ diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page3.imageset/Contents.json b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page3.imageset/Contents.json new file mode 100644 index 0000000..af127ff --- /dev/null +++ b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page3.imageset/Contents.json @@ -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" + } +} \ No newline at end of file diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page3.imageset/cat3.png b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page3.imageset/cat3.png new file mode 100644 index 0000000..97bd00c Binary files /dev/null and b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page3.imageset/cat3.png differ diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page4.imageset/Contents.json b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page4.imageset/Contents.json new file mode 100644 index 0000000..1e85fe5 --- /dev/null +++ b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page4.imageset/Contents.json @@ -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" + } +} \ No newline at end of file diff --git a/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page4.imageset/cat4.png b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page4.imageset/cat4.png new file mode 100644 index 0000000..55f4d08 Binary files /dev/null and b/Menubar RunCat/Menubar RunCat/Assets.xcassets/cat_page4.imageset/cat4.png differ diff --git a/Menubar RunCat/Menubar RunCat/Base.lproj/Main.storyboard b/Menubar RunCat/Menubar RunCat/Base.lproj/Main.storyboard new file mode 100644 index 0000000..6aa83de --- /dev/null +++ b/Menubar RunCat/Menubar RunCat/Base.lproj/Main.storyboard @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Menubar RunCat/Menubar RunCat/CPU.swift b/Menubar RunCat/Menubar RunCat/CPU.swift new file mode 100644 index 0000000..94b2e4a --- /dev/null +++ b/Menubar RunCat/Menubar RunCat/CPU.swift @@ -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.size / MemoryLayout.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) + } + +} diff --git a/Menubar RunCat/Menubar RunCat/Info.plist b/Menubar RunCat/Menubar RunCat/Info.plist new file mode 100644 index 0000000..cd774ce --- /dev/null +++ b/Menubar RunCat/Menubar RunCat/Info.plist @@ -0,0 +1,36 @@ + + + + + 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 + + diff --git a/Menubar RunCat/Menubar RunCat/Menubar_RunCat.entitlements b/Menubar RunCat/Menubar RunCat/Menubar_RunCat.entitlements new file mode 100644 index 0000000..f2ef3ae --- /dev/null +++ b/Menubar RunCat/Menubar RunCat/Menubar_RunCat.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + + diff --git a/README.md b/README.md index 20d2114..1b413b4 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,5 @@ A cute Running Cat animation on your MacBook menubar. Enjoy. あなたのMacBookのメニューバーで可愛い猫のアニメーションを実行できます.楽しんで♪ -[Download ⬇️](https://www.dropbox.com/sh/mhu4xayr56l9hq4/AAAL8LO1pG9rVpC3pQ1bMazOa?dl=0) - -![top](resources/runcat_top.jpg) - -![gif-anime](resources/runcat.gif) - -*** -If you set RunCat to accessibility in [Security & Privacy] of [System Preferences], the cat become able to run by key input. - -システム環境設定のセキュリティとプライバシーでアクセシビリティに設定すると,キー入力でもアニメーションするようになります. - -![gif-anime](resources/accessibility.png) +![top](resources/top.png) +![gif-anime](resources/runcat_demo.gif) diff --git a/RunCat b/RunCat deleted file mode 160000 index dcdcb6d..0000000 --- a/RunCat +++ /dev/null @@ -1 +0,0 @@ -Subproject commit dcdcb6dd181cb380cfdc22109cd55ead66ffc204 diff --git a/resources/accessibility.png b/resources/accessibility.png deleted file mode 100644 index 4d50ea9..0000000 Binary files a/resources/accessibility.png and /dev/null differ diff --git a/resources/runcat.gif b/resources/runcat.gif deleted file mode 100644 index 4919cad..0000000 Binary files a/resources/runcat.gif and /dev/null differ diff --git a/resources/runcat_demo.gif b/resources/runcat_demo.gif new file mode 100644 index 0000000..b735dad Binary files /dev/null and b/resources/runcat_demo.gif differ diff --git a/resources/runcat_top.jpg b/resources/runcat_top.jpg deleted file mode 100644 index b7b4503..0000000 Binary files a/resources/runcat_top.jpg and /dev/null differ diff --git a/resources/top.png b/resources/top.png new file mode 100644 index 0000000..b7398bf Binary files /dev/null and b/resources/top.png differ