This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// NSApplication+Activate.swift | ||
// Aware | ||
// | ||
// Created by Joshua Peek on 4/25/24. | ||
// | ||
|
||
import AppKit | ||
import OSLog | ||
|
||
private nonisolated(unsafe) let logger = Logger( | ||
subsystem: "com.awaremac.Aware", category: "NSApp+Activate" | ||
) | ||
|
||
extension NSApplication { | ||
func activateAggressively() { | ||
let start: ContinuousClock.Instant = .now | ||
let deadline: ContinuousClock.Instant = start.advanced(by: .seconds(1)) | ||
|
||
Task(priority: .high) { | ||
while isActive == false && deadline > .now && !Task.isCancelled { | ||
activate() | ||
await Task.yield() | ||
} | ||
|
||
assert(isActive, "expected app to be active") | ||
logger.debug("\(self) application took \(.now - start) to activate") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters