Skip to content

Commit

Permalink
this time ok
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Jun 17, 2023
1 parent f30e5b6 commit 6035616
Show file tree
Hide file tree
Showing 13 changed files with 387 additions and 344 deletions.
4 changes: 4 additions & 0 deletions Stalker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
C66CABB32A388FBD00E4D8E6 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C66CABB22A388FBD00E4D8E6 /* ViewController.swift */; };
C66CABB72A389F2500E4D8E6 /* EventMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C66CABB62A389F2500E4D8E6 /* EventMonitor.swift */; };
C66F02AF2A3B5B4D00077CE3 /* LaunchAtLogin in Frameworks */ = {isa = PBXBuildFile; productRef = C66F02AE2A3B5B4D00077CE3 /* LaunchAtLogin */; };
C6B3E79B2A3D83C400B650BC /* NSRect+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6B3E79A2A3D83C400B650BC /* NSRect+Extension.swift */; };
C6DEC52A2A38BF6C00943448 /* StatusBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6DEC5292A38BF6C00943448 /* StatusBarController.swift */; };
C6DEC52C2A38CDE500943448 /* Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6DEC52B2A38CDE500943448 /* Helper.swift */; };
C6DEC52F2A39C83F00943448 /* NSView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6DEC52E2A39C83F00943448 /* NSView+Extension.swift */; };
Expand All @@ -30,6 +31,7 @@
C66CABAC2A38871500E4D8E6 /* Stalker.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Stalker.entitlements; sourceTree = "<group>"; };
C66CABB22A388FBD00E4D8E6 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
C66CABB62A389F2500E4D8E6 /* EventMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventMonitor.swift; sourceTree = "<group>"; };
C6B3E79A2A3D83C400B650BC /* NSRect+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSRect+Extension.swift"; sourceTree = "<group>"; };
C6DEC5292A38BF6C00943448 /* StatusBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusBarController.swift; sourceTree = "<group>"; };
C6DEC52B2A38CDE500943448 /* Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helper.swift; sourceTree = "<group>"; };
C6DEC52E2A39C83F00943448 /* NSView+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSView+Extension.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -98,6 +100,7 @@
C6DEC52E2A39C83F00943448 /* NSView+Extension.swift */,
C6DEC5322A3A048B00943448 /* NSSwitch+Extension.swift */,
C6DEC5342A3A052700943448 /* NSButton+Extension.swift */,
C6B3E79A2A3D83C400B650BC /* NSRect+Extension.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -205,6 +208,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C6B3E79B2A3D83C400B650BC /* NSRect+Extension.swift in Sources */,
C6DEC53D2A3A0E8900943448 /* Animations.swift in Sources */,
C6DEC5312A39EE0A00943448 /* Data.swift in Sources */,
C66CABB72A389F2500E4D8E6 /* EventMonitor.swift in Sources */,
Expand Down
136 changes: 67 additions & 69 deletions Stalker/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,43 @@ import AppKit

@main
class AppDelegate: NSObject, NSApplicationDelegate {
let popover: NSPopover = NSPopover()
let popover: NSPopover = NSPopover()
let statusBarController = StatusBarController()

// MARK: - Event Monitors

var mouseClickEventMonitor: EventMonitor?

func applicationDidFinishLaunching(
_ aNotification: Notification
) {
statusBarController.setup()

popover.contentViewController = ViewController.freshController()

mouseClickEventMonitor = EventMonitor(
mask: [.leftMouseDown,
.rightMouseDown]
) { [weak self] event in
if let strongSelf = self {

var mouseEventMonitor: EventMonitor?

func applicationDidFinishLaunching(
_ aNotification: Notification
) {
popover.contentViewController = ViewController.freshController()

mouseEventMonitor = EventMonitor(
mask: [.leftMouseDown,
.rightMouseDown]
) { [weak self] event in
if let strongSelf = self {
if strongSelf.popover.isShown {
strongSelf.closePopover(event)
}
}
}
}


func applicationWillTerminate(
_ aNotification: Notification
) {
// Insert code here to tear down your application

statusBarController.terminate()
}

func applicationSupportsSecureRestorableState(
_ app: NSApplication
) -> Bool {
return true
}
}
}
}


func applicationWillTerminate(
_ aNotification: Notification
) {
}

func applicationSupportsSecureRestorableState(
_ app: NSApplication
) -> Bool {
return true
}

@objc func toggle(
_ sender: NSButton
Expand All @@ -66,50 +61,53 @@ class AppDelegate: NSObject, NSApplicationDelegate {
@objc func toggleCollapse(
_ sender: NSButton
) {
guard !(statusBarController.idling || statusBarController.sideIdling) else {
statusBarController.disableIdle()
return
}

if statusBarController.collapsed {
statusBarController.disableCollapse()
} else {
statusBarController.enableCollapse()
}
}
@objc func togglePopover(
_ sender: NSButton
) {
if popover.isShown {
closePopover(sender)
} else {
showPopover(sender)
}
}
func showPopover(
_ sender: Any?
) {
if let button = statusBarController.head.button ?? sender as? NSButton {
popover.show(
@objc func togglePopover(
_ sender: NSButton
) {
if popover.isShown {
closePopover(sender)
} else {
showPopover(sender)
}
}
func showPopover(
_ sender: Any?
) {
if let button = statusBarController.head.button ?? sender as? NSButton {
popover.show(
relativeTo: button.bounds,
of: button,
preferredEdge: NSRectEdge.minY
)
preferredEdge: NSRectEdge.minY
)

if let window = popover.contentViewController?.view.window {
// Activate popover
window.becomeKey()
}
}

mouseClickEventMonitor?.start()
}

func closePopover(
_ sender: Any?
) {
popover.performClose(
sender
)

mouseClickEventMonitor?.stop()
}

}

mouseEventMonitor?.start()
}

func closePopover(
_ sender: Any?
) {
popover.performClose(sender)

mouseEventMonitor?.stop()
}

}
11 changes: 5 additions & 6 deletions Stalker/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@
<rect key="frame" x="0.0" y="0.0" width="408" height="270"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<box fixedFrame="YES" boxType="custom" cornerRadius="13" title="Box" titlePosition="noTitle" translatesAutoresizingMaskIntoConstraints="NO" id="AE1-vw-2zX" userLabel="Info">
<box fixedFrame="YES" boxType="custom" borderWidth="0.0" cornerRadius="13" title="Box" titlePosition="noTitle" translatesAutoresizingMaskIntoConstraints="NO" id="AE1-vw-2zX" userLabel="Info">
<rect key="frame" x="20" y="224" width="368" height="26"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<view key="contentView" id="zt2-N7-04s">
<rect key="frame" x="1" y="1" width="366" height="24"/>
<rect key="frame" x="0.0" y="0.0" width="368" height="26"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button translatesAutoresizingMaskIntoConstraints="NO" id="lno-8O-Iz8">
<rect key="frame" x="8" y="2.5" width="120" height="17"/>
<rect key="frame" x="8" y="3.5" width="120" height="17"/>
<buttonCell key="cell" type="bevel" title="Source Code" bezelStyle="rounded" image="apple.terminal.on.rectangle.fill" catalog="system" imagePosition="leading" alignment="center" imageScaling="proportionallyDown" inset="2" id="OjW-Fe-OGQ">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" size="13" name="MobileMan"/>
Expand All @@ -98,7 +98,7 @@
</connections>
</button>
<button translatesAutoresizingMaskIntoConstraints="NO" id="aXF-sF-flQ" userLabel="Buy Me a Juice">
<rect key="frame" x="221" y="4" width="137.5" height="16"/>
<rect key="frame" x="223" y="5" width="137.5" height="16"/>
<buttonCell key="cell" type="bevel" title="Buy Me a Juice" bezelStyle="rounded" image="cup.and.saucer.fill" catalog="system" imagePosition="trailing" alignment="right" imageScaling="proportionallyDown" inset="2" id="gbY-hT-jUX">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" size="13" name="MobileMan"/>
Expand All @@ -112,7 +112,7 @@
</connections>
</button>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="3pc-OX-nv1">
<rect key="frame" x="129" y="-43" width="108" height="108"/>
<rect key="frame" x="130" y="-42" width="108" height="108"/>
<constraints>
<constraint firstAttribute="width" constant="108" id="MDB-0y-NN9"/>
<constraint firstAttribute="height" constant="108" id="Zeg-jP-UBX"/>
Expand All @@ -130,7 +130,6 @@
<constraint firstItem="3pc-OX-nv1" firstAttribute="centerX" secondItem="zt2-N7-04s" secondAttribute="centerX" id="nFU-so-Ze1"/>
</constraints>
</view>
<color key="borderColor" name="quaternaryLabelColor" catalog="System" colorSpace="catalog"/>
</box>
<box fixedFrame="YES" boxType="custom" cornerRadius="13" title="Box" titlePosition="noTitle" transparent="YES" translatesAutoresizingMaskIntoConstraints="NO" id="oKr-8Q-j0H" userLabel="Stalker Placeholder">
<rect key="frame" x="20" y="224" width="368" height="26"/>
Expand Down
Loading

0 comments on commit 6035616

Please sign in to comment.