Skip to content

Commit 4400b3c

Browse files
committed
First version
1 parent e02f354 commit 4400b3c

38 files changed

Lines changed: 4155 additions & 24 deletions
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// Support.swift
3+
// SwiftUI-HiddenAPI-Framework
4+
//
5+
// Created by Wouter on 21/11/23.
6+
//
7+
8+
import SwiftUI
9+
10+
public extension SwiftUI.App {
11+
static func openSettings() {
12+
if #available(macOS 14.0, *) {
13+
EnvironmentValues().openSettings()
14+
} else if #available(macOS 13.0, *) {
15+
NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
16+
} else {
17+
NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil)
18+
}
19+
}
20+
21+
@available(macOS 13.0, *)
22+
static func openWindow(id: String) {
23+
EnvironmentValues().openWindow(id: id)
24+
}
25+
26+
@available(macOS 13.0, *)
27+
static func openWindow<Value: Codable & Hashable>(id: String, value: Value) {
28+
EnvironmentValues().openWindow(id: id, value: value)
29+
}
30+
31+
@available(macOS 13.0, *)
32+
static func openWindow<Value: Codable & Hashable>(value: Value) {
33+
EnvironmentValues().openWindow(value: value)
34+
}
35+
36+
@available(macOS 13.0, *)
37+
static func openDocument(at url: URL) async throws {
38+
try await EnvironmentValues().openDocument(at: url)
39+
}
40+
41+
static func openURL(_ url: URL) {
42+
EnvironmentValues().openURL(url)
43+
}
44+
45+
static func openURL(_ url: URL) async -> Bool {
46+
await withCheckedContinuation {
47+
EnvironmentValues().openURL(url, completion: $0.resume(returning:))
48+
}
49+
}
50+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// Environment+extensions.swift
3+
// SwiftUI-HiddenAPI-Framework
4+
//
5+
// Created by Wouter on 22/11/23.
6+
//
7+
8+
import SwiftUI
9+
10+
extension EnvironmentValues {
11+
var hidden: HiddenEnvironmentValues {
12+
.init(environment: self)
13+
}
14+
}
15+
16+
struct WithCurrentWindowAction {
17+
let action: SwiftUI.WithCurrentWindowAction
18+
19+
public func callAsFunction(_ window: (NSWindow?) -> Void) {
20+
action(window)
21+
}
22+
}
23+
24+
struct HiddenEnvironmentValues {
25+
let environment: EnvironmentValues
26+
27+
var openSettings: () -> Void {
28+
if #available(macOS 14.0, *) {
29+
environment.openSettings.callAsFunction
30+
} else if #available(macOS 13.0, *) {
31+
{
32+
NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
33+
}
34+
} else {
35+
{
36+
NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil)
37+
}
38+
}
39+
}
40+
41+
var withCurrentWindow: WithCurrentWindowAction {
42+
.init(action: environment.withCurrentWindow)
43+
}
44+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// Form+init.swift
3+
// SwiftUI-HiddenAPI-Framework
4+
//
5+
// Created by Wouter on 22/11/23.
6+
//
7+
8+
import SwiftUI
9+
10+
public extension Form {
11+
static func withFooter<C: View, F: View>(@ViewBuilder content: () -> C, @ViewBuilder footer: () -> F) -> some View {
12+
Form<FormFooterContent<C, F>>(content: content, footer: footer)
13+
}
14+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Scene+extensions.swift
3+
// SwiftUI-HiddenAPI-Framework
4+
//
5+
// Created by Wouter on 22/11/23.
6+
//
7+
8+
import SwiftUI
9+
10+
extension Scene {
11+
var hidden: HiddenSceneModifier<Self> {
12+
.init(content: self)
13+
}
14+
}
15+
16+
struct HiddenSceneModifier<S: Scene> {
17+
let content: S
18+
19+
func windowBackground(_ shape: some ShapeStyle) -> some Scene {
20+
content.windowBackground(shape)
21+
}
22+
23+
func defaultVisibility(_ visibility: Visibility) -> some Scene {
24+
content.defaultVisibility(visibility)
25+
}
26+
27+
func windowShouldClose(_ perform: @escaping () -> Bool) -> some Scene {
28+
content.windowShouldClose(perform)
29+
}
30+
}

0 commit comments

Comments
 (0)