Skip to content

Commit

Permalink
Change to use icon. Remove launcher that didn't work anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
terkelg committed May 24, 2020
1 parent 8aba726 commit 1a73990
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 267 deletions.
131 changes: 0 additions & 131 deletions CursorTravel.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
84638062247465B100F6CE79 /* Mouse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84638061247465B100F6CE79 /* Mouse.swift */; };
84638064247465C700F6CE79 /* Unit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84638063247465C700F6CE79 /* Unit.swift */; };
84638066247465F000F6CE79 /* EventMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84638065247465F000F6CE79 /* EventMonitor.swift */; };
84A714BC247A124200EE705A /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A714BB247A124200EE705A /* main.swift */; };
84A714C3247A124400EE705A /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 84A714C2247A124400EE705A /* Preview Assets.xcassets */; };
84A714CD247A145100EE705A /* LauncherApplication.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = 84A714B9247A124200EE705A /* LauncherApplication.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
84A714D0247A147B00EE705A /* ServiceManagement.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84A714CF247A147B00EE705A /* ServiceManagement.framework */; };
/* End PBXBuildFile section */

Expand All @@ -31,7 +28,6 @@
dstPath = Contents/Library/LoginItems;
dstSubfolderSpec = 1;
files = (
84A714CD247A145100EE705A /* LauncherApplication.app in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -52,11 +48,6 @@
84638061247465B100F6CE79 /* Mouse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mouse.swift; sourceTree = "<group>"; };
84638063247465C700F6CE79 /* Unit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Unit.swift; sourceTree = "<group>"; };
84638065247465F000F6CE79 /* EventMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventMonitor.swift; sourceTree = "<group>"; };
84A714B9247A124200EE705A /* LauncherApplication.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LauncherApplication.app; sourceTree = BUILT_PRODUCTS_DIR; };
84A714BB247A124200EE705A /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
84A714C2247A124400EE705A /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
84A714C7247A124400EE705A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
84A714C8247A124400EE705A /* LauncherApplication.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = LauncherApplication.entitlements; sourceTree = "<group>"; };
84A714CF247A147B00EE705A /* ServiceManagement.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ServiceManagement.framework; path = System/Library/Frameworks/ServiceManagement.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

Expand All @@ -69,21 +60,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
84A714B6247A124200EE705A /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
846380392474647E00F6CE79 = {
isa = PBXGroup;
children = (
846380442474647E00F6CE79 /* CursorTravel */,
84A714BA247A124200EE705A /* LauncherApplication */,
846380432474647E00F6CE79 /* Products */,
84A714CE247A147B00EE705A /* Frameworks */,
);
Expand All @@ -93,7 +76,6 @@
isa = PBXGroup;
children = (
846380422474647E00F6CE79 /* CursorTravel.app */,
84A714B9247A124200EE705A /* LauncherApplication.app */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -150,25 +132,6 @@
path = "Supporting Views";
sourceTree = "<group>";
};
84A714BA247A124200EE705A /* LauncherApplication */ = {
isa = PBXGroup;
children = (
84A714BB247A124200EE705A /* main.swift */,
84A714C7247A124400EE705A /* Info.plist */,
84A714C8247A124400EE705A /* LauncherApplication.entitlements */,
84A714C1247A124400EE705A /* Preview Content */,
);
path = LauncherApplication;
sourceTree = "<group>";
};
84A714C1247A124400EE705A /* Preview Content */ = {
isa = PBXGroup;
children = (
84A714C2247A124400EE705A /* Preview Assets.xcassets */,
);
path = "Preview Content";
sourceTree = "<group>";
};
84A714CE247A147B00EE705A /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -198,23 +161,6 @@
productReference = 846380422474647E00F6CE79 /* CursorTravel.app */;
productType = "com.apple.product-type.application";
};
84A714B8247A124200EE705A /* LauncherApplication */ = {
isa = PBXNativeTarget;
buildConfigurationList = 84A714CB247A124400EE705A /* Build configuration list for PBXNativeTarget "LauncherApplication" */;
buildPhases = (
84A714B5247A124200EE705A /* Sources */,
84A714B6247A124200EE705A /* Frameworks */,
84A714B7247A124200EE705A /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = LauncherApplication;
productName = LauncherApplication;
productReference = 84A714B9247A124200EE705A /* LauncherApplication.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
Expand All @@ -228,9 +174,6 @@
846380412474647E00F6CE79 = {
CreatedOnToolsVersion = 11.1;
};
84A714B8247A124200EE705A = {
CreatedOnToolsVersion = 11.1;
};
};
};
buildConfigurationList = 8463803D2474647E00F6CE79 /* Build configuration list for PBXProject "CursorTravel" */;
Expand All @@ -247,7 +190,6 @@
projectRoot = "";
targets = (
846380412474647E00F6CE79 /* CursorTravel */,
84A714B8247A124200EE705A /* LauncherApplication */,
);
};
/* End PBXProject section */
Expand All @@ -264,14 +206,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
84A714B7247A124200EE705A /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
84A714C3247A124400EE705A /* Preview Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand All @@ -289,14 +223,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
84A714B5247A124200EE705A /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
84A714BC247A124200EE705A /* main.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXVariantGroup section */
Expand Down Expand Up @@ -472,54 +398,6 @@
};
name = Release;
};
84A714C9247A124400EE705A /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = LauncherApplication/LauncherApplication.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_ASSET_PATHS = "\"LauncherApplication/Preview Content\"";
DEVELOPMENT_TEAM = 5458M4A7SB;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = LauncherApplication/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
PRODUCT_BUNDLE_IDENTIFIER = com.terkel.LauncherApplication;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
84A714CA247A124400EE705A /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = LauncherApplication/LauncherApplication.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_ASSET_PATHS = "\"LauncherApplication/Preview Content\"";
DEVELOPMENT_TEAM = 5458M4A7SB;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = LauncherApplication/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
PRODUCT_BUNDLE_IDENTIFIER = com.terkel.LauncherApplication;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
Expand All @@ -541,15 +419,6 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
84A714CB247A124400EE705A /* Build configuration list for PBXNativeTarget "LauncherApplication" */ = {
isa = XCConfigurationList;
buildConfigurations = (
84A714C9247A124400EE705A /* Debug */,
84A714CA247A124400EE705A /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 8463803A2474647E00F6CE79 /* Project object */;
Expand Down
39 changes: 18 additions & 21 deletions CursorTravel/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

// MARK: TODO
// - [ ] Fix start on startup
// - [ ] Allow launcher/open on startup

import Cocoa
import SwiftUI
Expand All @@ -21,6 +21,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
let mouseData = Mouse()
let popover = NSPopover()

// TODO: Make this an option
private let icon = true

private var cancellableDistance: AnyCancellable?
private var eventMonitor: EventMonitor?

Expand All @@ -29,23 +32,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
initPopover()

cancellableDistance = mouseData.objectWillChange.sink(receiveValue: { item in
self.statusItem.button?.title = self.mouseData.formattedTotal()
if !self.icon {
self.statusItem.button?.title = self.mouseData.totalString
}
})

eventMonitor = EventMonitor(mask: [.leftMouseDown, .rightMouseDown]) { event in
self.togglePopover(nil)
}

// Launcher
let launcherAppId = "com.terkel.LauncherApplication"
let runningApps = NSWorkspace.shared.runningApplications
let isRunning = !runningApps.filter { $0.bundleIdentifier == launcherAppId }.isEmpty

SMLoginItemSetEnabled(launcherAppId as CFString, true)

if isRunning {
DistributedNotificationCenter.default().post(name: .killLauncher, object: Bundle.main.bundleIdentifier!)
}
}

func applicationWillTerminate(_ aNotification: Notification) {
Expand All @@ -71,9 +65,18 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// MARK: Init

func initStatusItem() {

if let button = statusItem.button {
button.title = mouseData.formattedTotal()
button.font = NSFont.monospacedDigitSystemFont(ofSize: 14.0, weight: .regular)

if icon {
button.image = NSImage(named: "Cursor")
// button.imagePosition = NSControl.ImagePosition.imageLeft
button.imageScaling = NSImageScaling.scaleProportionallyDown
statusItem.length = NSStatusItem.squareLength
} else {
button.title = mouseData.totalString
button.font = NSFont.monospacedDigitSystemFont(ofSize: 14.0, weight: .regular)
}
button.action = #selector(togglePopover(_:))
}
}
Expand All @@ -84,9 +87,3 @@ class AppDelegate: NSObject, NSApplicationDelegate {
popover.contentViewController = NSHostingController(rootView: contentView)
}
}

// MARK: - Extensions

extension Notification.Name {
static let killLauncher = Notification.Name("killLauncher")
}
5 changes: 4 additions & 1 deletion CursorTravel/Assets.xcassets/Cursor.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"images" : [
{
"idiom" : "universal",
"filename" : "tray-icon.pdf",
"filename" : "Cursor.pdf",
"scale" : "1x"
},
{
Expand All @@ -17,5 +17,8 @@
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions CursorTravel/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ struct ContentView: View {
}
}
Divider().padding(.bottom, 10)
MetricView(label: "Session", value: mouseData.formattedSession())
MetricView(label: "Total Distance", value: mouseData.formattedTotal())
MetricView(label: "Session", value: mouseData.sessionString)
MetricView(label: "Total Distance", value: mouseData.totalString)
Divider().padding(.top, 10)
HStack {
Button(action: {
Expand Down
16 changes: 8 additions & 8 deletions CursorTravel/Models/Mouse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ final class Mouse: ObservableObject {

// MARK: - Print / Formatting

func getTotalDistance() -> Double {
return distance.total / unitData[distance.unit].multiplier
var totalDistance: Double {
distance.total / unitData[distance.unit].multiplier
}

func getSessionDistance() -> Double {
return distance.session / unitData[distance.unit].multiplier
var sessionDistance: Double {
distance.session / unitData[distance.unit].multiplier
}

func formattedTotal() -> String {
return String(format: "%.2f %@", getTotalDistance(), unitData[distance.unit].short)
var totalString: String {
String(format: "%.2f %@", totalDistance, unitData[distance.unit].short)
}

func formattedSession() -> String {
return String(format: "%.2f %@", getSessionDistance(), unitData[distance.unit].short)
var sessionString: String {
String(format: "%.2f %@", sessionDistance, unitData[distance.unit].short)
}

// MARK: - Persistant Data
Expand Down
Loading

0 comments on commit 1a73990

Please sign in to comment.