From bfde54dd054661bf44a2412883f200f4b59de95e Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Tue, 11 Jun 2019 19:10:24 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=89=20Proof=20of=20concept?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + README.md | 3 + phpmon.xcodeproj/project.pbxproj | 340 +++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + phpmon/AppDelegate.swift | 44 ++ .../AppIcon.appiconset/Contents.json | 58 ++ phpmon/Assets.xcassets/Contents.json | 6 + phpmon/Base.lproj/Main.storyboard | 697 ++++++++++++++++++ phpmon/ImageGenerator.swift | 59 ++ phpmon/Info.plist | 34 + phpmon/Shell.swift | 41 ++ phpmon/ViewController.swift | 27 + phpmon/phpmon.entitlements | 10 + 14 files changed, 1335 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 phpmon.xcodeproj/project.pbxproj create mode 100644 phpmon.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 phpmon.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 phpmon/AppDelegate.swift create mode 100644 phpmon/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 phpmon/Assets.xcassets/Contents.json create mode 100644 phpmon/Base.lproj/Main.storyboard create mode 100644 phpmon/ImageGenerator.swift create mode 100644 phpmon/Info.plist create mode 100644 phpmon/Shell.swift create mode 100644 phpmon/ViewController.swift create mode 100644 phpmon/phpmon.entitlements diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..19f4276 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +phpmon.xcodeproj/project.xcworkspace diff --git a/README.md b/README.md new file mode 100644 index 0000000..f817ce0 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# phpmon + +phpmon is a macOS utility that runs on your Mac and displays the active PHP version in your status bar. Handy if you're running multiple versions of PHP with Homebrew and wish to see which version is currently linked. diff --git a/phpmon.xcodeproj/project.pbxproj b/phpmon.xcodeproj/project.pbxproj new file mode 100644 index 0000000..f148295 --- /dev/null +++ b/phpmon.xcodeproj/project.pbxproj @@ -0,0 +1,340 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B3622B0097F00E7CF16 /* AppDelegate.swift */; }; + C41C1B3922B0097F00E7CF16 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B3822B0097F00E7CF16 /* ViewController.swift */; }; + C41C1B3B22B0098000E7CF16 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C41C1B3A22B0098000E7CF16 /* Assets.xcassets */; }; + C41C1B3E22B0098000E7CF16 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C41C1B3C22B0098000E7CF16 /* Main.storyboard */; }; + C41C1B4722B009A400E7CF16 /* Shell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B4622B009A400E7CF16 /* Shell.swift */; }; + C41C1B4922B00A9800E7CF16 /* ImageGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41C1B4822B00A9800E7CF16 /* ImageGenerator.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + C41C1B3322B0097F00E7CF16 /* phpmon.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = phpmon.app; sourceTree = BUILT_PRODUCTS_DIR; }; + C41C1B3622B0097F00E7CF16 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + C41C1B3822B0097F00E7CF16 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + C41C1B3A22B0098000E7CF16 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + C41C1B3D22B0098000E7CF16 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + C41C1B3F22B0098000E7CF16 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + C41C1B4022B0098000E7CF16 /* phpmon.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = phpmon.entitlements; sourceTree = ""; }; + C41C1B4622B009A400E7CF16 /* Shell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shell.swift; sourceTree = ""; }; + C41C1B4822B00A9800E7CF16 /* ImageGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageGenerator.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + C41C1B3022B0097F00E7CF16 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + C41C1B2A22B0097F00E7CF16 = { + isa = PBXGroup; + children = ( + C41C1B3522B0097F00E7CF16 /* phpmon */, + C41C1B3422B0097F00E7CF16 /* Products */, + ); + sourceTree = ""; + }; + C41C1B3422B0097F00E7CF16 /* Products */ = { + isa = PBXGroup; + children = ( + C41C1B3322B0097F00E7CF16 /* phpmon.app */, + ); + name = Products; + sourceTree = ""; + }; + C41C1B3522B0097F00E7CF16 /* phpmon */ = { + isa = PBXGroup; + children = ( + C41C1B3622B0097F00E7CF16 /* AppDelegate.swift */, + C41C1B3822B0097F00E7CF16 /* ViewController.swift */, + C41C1B3A22B0098000E7CF16 /* Assets.xcassets */, + C41C1B3C22B0098000E7CF16 /* Main.storyboard */, + C41C1B3F22B0098000E7CF16 /* Info.plist */, + C41C1B4022B0098000E7CF16 /* phpmon.entitlements */, + C41C1B4622B009A400E7CF16 /* Shell.swift */, + C41C1B4822B00A9800E7CF16 /* ImageGenerator.swift */, + ); + path = phpmon; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + C41C1B3222B0097F00E7CF16 /* phpmon */ = { + isa = PBXNativeTarget; + buildConfigurationList = C41C1B4322B0098000E7CF16 /* Build configuration list for PBXNativeTarget "phpmon" */; + buildPhases = ( + C41C1B2F22B0097F00E7CF16 /* Sources */, + C41C1B3022B0097F00E7CF16 /* Frameworks */, + C41C1B3122B0097F00E7CF16 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = phpmon; + productName = phpmon; + productReference = C41C1B3322B0097F00E7CF16 /* phpmon.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + C41C1B2B22B0097F00E7CF16 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1020; + LastUpgradeCheck = 1020; + ORGANIZATIONNAME = "Nico Verbruggen"; + TargetAttributes = { + C41C1B3222B0097F00E7CF16 = { + CreatedOnToolsVersion = 10.2.1; + }; + }; + }; + buildConfigurationList = C41C1B2E22B0097F00E7CF16 /* Build configuration list for PBXProject "phpmon" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = C41C1B2A22B0097F00E7CF16; + productRefGroup = C41C1B3422B0097F00E7CF16 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + C41C1B3222B0097F00E7CF16 /* phpmon */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + C41C1B3122B0097F00E7CF16 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C41C1B3B22B0098000E7CF16 /* Assets.xcassets in Resources */, + C41C1B3E22B0098000E7CF16 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + C41C1B2F22B0097F00E7CF16 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C41C1B4722B009A400E7CF16 /* Shell.swift in Sources */, + C41C1B4922B00A9800E7CF16 /* ImageGenerator.swift in Sources */, + C41C1B3922B0097F00E7CF16 /* ViewController.swift in Sources */, + C41C1B3722B0097F00E7CF16 /* AppDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + C41C1B3C22B0098000E7CF16 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + C41C1B3D22B0098000E7CF16 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + C41C1B4122B0098000E7CF16 /* 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; + }; + C41C1B4222B0098000E7CF16 /* 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; + }; + C41C1B4422B0098000E7CF16 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = phpmon/phpmon.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = 8M54J5J787; + INFOPLIST_FILE = phpmon/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + C41C1B4522B0098000E7CF16 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = phpmon/phpmon.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = 8M54J5J787; + INFOPLIST_FILE = phpmon/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.nicoverbruggen.phpmon; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + C41C1B2E22B0097F00E7CF16 /* Build configuration list for PBXProject "phpmon" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C41C1B4122B0098000E7CF16 /* Debug */, + C41C1B4222B0098000E7CF16 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + C41C1B4322B0098000E7CF16 /* Build configuration list for PBXNativeTarget "phpmon" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C41C1B4422B0098000E7CF16 /* Debug */, + C41C1B4522B0098000E7CF16 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = C41C1B2B22B0097F00E7CF16 /* Project object */; +} diff --git a/phpmon.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/phpmon.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..da22c70 --- /dev/null +++ b/phpmon.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/phpmon.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/phpmon.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/phpmon.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/phpmon/AppDelegate.swift b/phpmon/AppDelegate.swift new file mode 100644 index 0000000..2c1f294 --- /dev/null +++ b/phpmon/AppDelegate.swift @@ -0,0 +1,44 @@ +// +// AppDelegate.swift +// phpmon +// +// Created by Nico Verbruggen on 11/06/2019. +// Copyright © 2019 Nico Verbruggen. All rights reserved. +// + +import Cocoa + +@NSApplicationMain +class AppDelegate: NSObject, NSApplicationDelegate { + + var timer: Timer? + + let statusItem = NSStatusBar.system.statusItem( + withLength: 40 + ) + + func applicationDidFinishLaunching(_ aNotification: Notification) { + self.setStatusBarImage(version: "???") + self.updatePhpVersionInStatusBar() + // Schedule a request to fetch the PHP version every 15 seconds + Timer.scheduledTimer(timeInterval: 15, target: self, selector: #selector(updatePhpVersionInStatusBar), userInfo: nil, repeats: true) + } + + func setStatusBarImage(version: String) { + if let button = statusItem.button { + let image = ImageGenerator.generateImageForStatusBar(text: version) + image.isTemplate = true + button.image = image + } + } + + func applicationWillTerminate(_ aNotification: Notification) { + // Insert code here to tear down your application + } + + @objc func updatePhpVersionInStatusBar() { + let version = Shell.extractPhpVersion() + self.setStatusBarImage(version: version) + } +} + diff --git a/phpmon/Assets.xcassets/AppIcon.appiconset/Contents.json b/phpmon/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..2db2b1c --- /dev/null +++ b/phpmon/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,58 @@ +{ + "images" : [ + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/phpmon/Assets.xcassets/Contents.json b/phpmon/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/phpmon/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/phpmon/Base.lproj/Main.storyboard b/phpmon/Base.lproj/Main.storyboard new file mode 100644 index 0000000..ccbafc8 --- /dev/null +++ b/phpmon/Base.lproj/Main.storyboard @@ -0,0 +1,697 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/phpmon/ImageGenerator.swift b/phpmon/ImageGenerator.swift new file mode 100644 index 0000000..dd34848 --- /dev/null +++ b/phpmon/ImageGenerator.swift @@ -0,0 +1,59 @@ +// +// ImageGenerator.swift +// phpmon +// +// Created by Nico Verbruggen on 11/06/2019. +// Copyright © 2019 Nico Verbruggen. All rights reserved. +// + +import Cocoa + +class ImageGenerator { + + public static func generateImageForStatusBar( + text: String + ) -> NSImage { + // Create an image with fixed dimensions + let width: CGFloat = 30.0 + let height: CGFloat = 20.0 + let image = NSImage(size: NSMakeSize(width, height)) + + // Use the system font + let font = NSFont.systemFont(ofSize: 14) + + let imageRect = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height) + let textRect = CGRect(x: 5, y: -1, width: image.size.width, height: image.size.height) + + let textStyle = NSMutableParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle + let textFontAttributes = [ + NSAttributedString.Key.font: font, + NSAttributedString.Key.foregroundColor: NSColor.black, + NSAttributedString.Key.paragraphStyle: textStyle + ] + + let targetImage: NSImage = NSImage(size: image.size) + + let rep: NSBitmapImageRep = NSBitmapImageRep( + bitmapDataPlanes: nil, + pixelsWide: Int(image.size.width), + pixelsHigh: Int(image.size.height), + bitsPerSample: 8, + samplesPerPixel: 4, + hasAlpha: true, + isPlanar: false, + colorSpaceName: NSColorSpaceName.calibratedRGB, + bytesPerRow: 0, + bitsPerPixel: 0 + )! + + targetImage.addRepresentation(rep) + targetImage.lockFocus() + + image.draw(in: imageRect) + text.draw(in: textRect, withAttributes: textFontAttributes) + + targetImage.unlockFocus() + return targetImage + } + +} diff --git a/phpmon/Info.plist b/phpmon/Info.plist new file mode 100644 index 0000000..fb41a35 --- /dev/null +++ b/phpmon/Info.plist @@ -0,0 +1,34 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + Copyright © 2019 Nico Verbruggen. All rights reserved. + NSMainStoryboardFile + Main + NSPrincipalClass + NSApplication + LSUIElement + + + diff --git a/phpmon/Shell.swift b/phpmon/Shell.swift new file mode 100644 index 0000000..4eebf92 --- /dev/null +++ b/phpmon/Shell.swift @@ -0,0 +1,41 @@ +// +// Shell.swift +// phpmon +// +// Created by Nico Verbruggen on 11/06/2019. +// Copyright © 2019 Nico Verbruggen. All rights reserved. +// + +import Cocoa + +class Shell { + public static func execute(command: String) -> String? + { + let task = Process() + task.launchPath = "/bin/bash" + task.arguments = ["-c", command] + + let pipe = Pipe() + task.standardOutput = pipe + task.launch() + + let data = pipe.fileHandleForReading.readDataToEndOfFile() + let output: String = NSString(data: data, encoding: String.Encoding.utf8.rawValue)! as String + + return output + } + + public static func extractPhpVersion() -> String + { + // Get the info about the PHP installation + let output = self.execute(command: "php -v") + // Get everything before "(cli)" (PHP X.X.X (cli) ...) + var version = output!.components(separatedBy: " (cli)")[0] + // Strip away the text before the version number + version = version.components(separatedBy: "PHP ")[1] + // Next up, let's strip away the minor version number + let segments = version.components(separatedBy: ".") + // Get the first two elements + return segments[0...1].joined(separator: ".") + } +} diff --git a/phpmon/ViewController.swift b/phpmon/ViewController.swift new file mode 100644 index 0000000..6c7127d --- /dev/null +++ b/phpmon/ViewController.swift @@ -0,0 +1,27 @@ +// +// ViewController.swift +// phpmon +// +// Created by Nico Verbruggen on 11/06/2019. +// Copyright © 2019 Nico Verbruggen. All rights reserved. +// + +import Cocoa + +class ViewController: NSViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + // Do any additional setup after loading the view. + } + + override var representedObject: Any? { + didSet { + // Update the view, if already loaded. + } + } + + +} + diff --git a/phpmon/phpmon.entitlements b/phpmon/phpmon.entitlements new file mode 100644 index 0000000..51a7cc5 --- /dev/null +++ b/phpmon/phpmon.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + +