-
-
Notifications
You must be signed in to change notification settings - Fork 138
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
10 changed files
with
209 additions
and
88 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 was deleted.
Oops, something went wrong.
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
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,50 @@ | ||
// | ||
// AccessibilityAccessManager.swift | ||
// Loop | ||
// | ||
// Created by Kai Azim on 2023-04-08. | ||
// | ||
|
||
import SwiftUI | ||
import Defaults | ||
|
||
class PermissionsManager { | ||
class Accessibility { | ||
static func getStatus() -> Bool { | ||
// Get current state for accessibility access | ||
let options: NSDictionary = [kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString: false] | ||
let status = AXIsProcessTrustedWithOptions(options) | ||
|
||
return status | ||
} | ||
|
||
static func requestAccess() { | ||
if PermissionsManager.Accessibility.getStatus() { | ||
return | ||
} | ||
let alert = NSAlert() | ||
alert.messageText = "\(Bundle.main.appName) Needs Accessibility Permissions" | ||
alert.informativeText = "Please grant accessibility access to be able to resize windows." | ||
alert.runModal() | ||
} | ||
} | ||
|
||
class ScreenRecording { | ||
static func getStatus() -> Bool { | ||
return CGPreflightScreenCaptureAccess() | ||
} | ||
|
||
static func requestAccess() { | ||
if PermissionsManager.ScreenRecording.getStatus() { | ||
return | ||
} | ||
|
||
let alert = NSAlert() | ||
alert.messageText = "\(Bundle.main.appName) Needs Screen Recording Permissions" | ||
alert.informativeText = "Please grant screen recording access to be able to resize windows (with animation)." | ||
alert.runModal() | ||
|
||
CGRequestScreenCaptureAccess() | ||
} | ||
} | ||
} |
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
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,49 @@ | ||
// | ||
// WindowTransformAnimation.swift | ||
// Loop | ||
// | ||
// Created by Kai Azim on 2023-09-02. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// Animate a window's resize! | ||
class WindowTransformAnimation: NSAnimation { | ||
private var targetFrame: CGRect | ||
private let oldFrame: CGRect | ||
private let window: Window | ||
|
||
init(_ newRect: CGRect, window: Window) { | ||
self.targetFrame = newRect | ||
self.oldFrame = window.frame | ||
self.window = window | ||
super.init(duration: 0.2, animationCurve: .easeOut) | ||
self.frameRate = 60.0 | ||
self.animationBlockingMode = .nonblocking | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
func startInBackground() { | ||
DispatchQueue.global().async { [self] in | ||
self.start() | ||
RunLoop.current.run() | ||
} | ||
} | ||
|
||
override public var currentProgress: NSAnimation.Progress { | ||
didSet { | ||
let value = CGFloat(self.currentValue) | ||
let newFrame = CGRect( | ||
x: oldFrame.origin.x + value * (targetFrame.origin.x - oldFrame.origin.x), | ||
y: oldFrame.origin.y + value * (targetFrame.origin.y - oldFrame.origin.y), | ||
width: oldFrame.size.width + value * (targetFrame.size.width - oldFrame.size.width), | ||
height: oldFrame.size.height + value * (targetFrame.size.height - oldFrame.size.height) | ||
) | ||
|
||
window.setFrame(newFrame) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.