-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from kishikawakatsumi/visionos
Support visionOS
- Loading branch information
Showing
37 changed files
with
1,468 additions
and
82 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
11 changes: 11 additions & 0 deletions
11
...les/FileBrowser/FileBrowser (visionOS)/Assets.xcassets/AccentColor.colorset/Contents.json
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,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...xcassets/AppIcon.solidimagestack/Back.solidimagestacklayer/Content.imageset/Contents.json
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,13 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "back.png", | ||
"idiom" : "vision", | ||
"scale" : "2x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+122 KB
...ets/AppIcon.solidimagestack/Back.solidimagestacklayer/Content.imageset/back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions
6
...visionOS)/Assets.xcassets/AppIcon.solidimagestack/Back.solidimagestacklayer/Contents.json
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,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
.../FileBrowser/FileBrowser (visionOS)/Assets.xcassets/AppIcon.solidimagestack/Contents.json
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,17 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"layers" : [ | ||
{ | ||
"filename" : "Front.solidimagestacklayer" | ||
}, | ||
{ | ||
"filename" : "Middle.solidimagestacklayer" | ||
}, | ||
{ | ||
"filename" : "Back.solidimagestacklayer" | ||
} | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
...cassets/AppIcon.solidimagestack/Front.solidimagestacklayer/Content.imageset/Contents.json
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,13 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "front.png", | ||
"idiom" : "vision", | ||
"scale" : "2x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+23.5 KB
...s/AppIcon.solidimagestack/Front.solidimagestacklayer/Content.imageset/front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions
6
...isionOS)/Assets.xcassets/AppIcon.solidimagestack/Front.solidimagestacklayer/Contents.json
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,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...assets/AppIcon.solidimagestack/Middle.solidimagestacklayer/Content.imageset/Contents.json
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,13 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "middle.png", | ||
"idiom" : "vision", | ||
"scale" : "2x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+18.4 KB
...AppIcon.solidimagestack/Middle.solidimagestacklayer/Content.imageset/middle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions
6
...sionOS)/Assets.xcassets/AppIcon.solidimagestack/Middle.solidimagestacklayer/Contents.json
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,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Examples/FileBrowser/FileBrowser (visionOS)/Assets.xcassets/Contents.json
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,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
Examples/FileBrowser/FileBrowser (visionOS)/ConnectServiceView.swift
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,119 @@ | ||
import SwiftUI | ||
import SMBClient | ||
|
||
struct ConnectServiceView: View { | ||
private enum FocusedField { | ||
case username | ||
case password | ||
} | ||
|
||
@State private var server: String | ||
|
||
@State private var username: String | ||
@State private var password: String | ||
|
||
private var canSubmit: Bool { | ||
!username.isEmpty && !password.isEmpty | ||
} | ||
|
||
@FocusState | ||
private var focusedField: FocusedField? | ||
|
||
@State private var presentLocalizedAlert: Bool = false | ||
@State private var localizedError: ErrorResponse? = nil | ||
|
||
@State private var presentAlert: Bool = false | ||
@State private var error: Error? = nil | ||
|
||
@Environment(\.dismiss) private var dismiss | ||
|
||
private let onSuccess: (String, String, SMBClient) -> Void | ||
private let onCancel: () -> Void | ||
|
||
init( | ||
server: String, | ||
username: String, | ||
password: String, | ||
onSuccess: @escaping (_ username: String, _ password: String, _ client: SMBClient) -> Void, | ||
onCancel: @escaping () -> Void | ||
) { | ||
self.server = server | ||
self.username = username | ||
self.password = password | ||
self.onSuccess = onSuccess | ||
self.onCancel = onCancel | ||
} | ||
|
||
var body: some View { | ||
NavigationStack { | ||
Form { | ||
Section { | ||
Label(server, systemImage: "server.rack") | ||
} | ||
Section { | ||
TextField("Username", text: $username) | ||
.autocorrectionDisabled() | ||
.textInputAutocapitalization(.never) | ||
.textContentType(.username) | ||
.focused($focusedField, equals: .username) | ||
SecureField("Password", text: $password) | ||
.textContentType(.password) | ||
.focused($focusedField, equals: .password) | ||
} header: { | ||
Text("Login") | ||
} | ||
Section { | ||
Button("Connect") { | ||
submit() | ||
} | ||
.frame(maxWidth: .infinity) | ||
.disabled(!canSubmit) | ||
} | ||
} | ||
.foregroundStyle(.primary) | ||
.navigationTitle("Connect to Server") | ||
.navigationBarTitleDisplayMode(.inline) | ||
.toolbar { | ||
Button("Cancel") { | ||
onCancel() | ||
dismiss() | ||
} | ||
} | ||
.onAppear { | ||
focusedField = .username | ||
} | ||
.onSubmit { | ||
guard canSubmit else { return } | ||
submit() | ||
} | ||
.alert(isPresented: $presentLocalizedAlert, error: localizedError) { _ in | ||
Button("Close") {} | ||
} message: { error in | ||
Text(error.failureReason ?? error.recoverySuggestion ?? "") | ||
} | ||
.alert("", isPresented: $presentAlert) { | ||
Button("Close") {} | ||
} message: { | ||
Text(error?.localizedDescription ?? "") | ||
} | ||
} | ||
} | ||
|
||
private func submit() { | ||
Task { @MainActor in | ||
do { | ||
let client = SMBClient(host: server) | ||
try await client.login(username: username, password: password) | ||
|
||
dismiss() | ||
onSuccess(username, password, client) | ||
} catch let error as ErrorResponse { | ||
self.localizedError = error | ||
presentLocalizedAlert = true | ||
} catch { | ||
self.error = error | ||
presentAlert = true | ||
} | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
Examples/FileBrowser/FileBrowser (visionOS)/ContentView.swift
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,82 @@ | ||
import SwiftUI | ||
import SMBClient | ||
|
||
struct FileBrowserView: View { | ||
@State | ||
private var services = [Service]() | ||
@State | ||
private var selection: Service? | ||
@State | ||
private var sessions = [ID: SMBClient]() | ||
@State | ||
private var showingLoginSheet: Bool = false | ||
|
||
let publisher = NotificationCenter.default.publisher(for: ServiceDiscovery.serviceDidDiscover) | ||
|
||
var body: some View { | ||
NavigationSplitView { | ||
List(services, id: \.self, selection: $selection) { (service) in | ||
NavigationLink(value: service) { | ||
Label(service.name, systemImage: "server.rack") | ||
.foregroundStyle(.primary) | ||
} | ||
} | ||
.onChange(of: selection, initial: false) { (oldValue, newValue) in | ||
if let selection, sessions[selection.id] == nil { | ||
showingLoginSheet = true | ||
} | ||
} | ||
.onReceive(publisher) { (notification) in | ||
services = ServiceDiscovery.shared.services.sorted { $0.name.localizedStandardCompare($1.name) == .orderedAscending } | ||
} | ||
.navigationTitle("Services") | ||
} detail: { | ||
if let selection { | ||
if let client = sessions[selection.id] { | ||
SharesView(client: client) | ||
.id(selection) | ||
} | ||
} | ||
} | ||
.sheet(isPresented: $showingLoginSheet) { | ||
return | ||
} content: { | ||
if let selection = selection { | ||
let (username, password) = { | ||
let store = CredentialStore.shared | ||
if let credential = store.load(server: selection.name) { | ||
return (credential.username, credential.password) | ||
} else { | ||
return ("", "") | ||
} | ||
}() | ||
|
||
ConnectServiceView(server: selection.name, username: username, password: password) { (username, password, client) in | ||
loginSucceeded(server: selection.name, securityDomain: selection.id.rawValue, username: username, password: password, client: client) | ||
showingLoginSheet = false | ||
} onCancel: { | ||
showingLoginSheet = false | ||
} | ||
} | ||
} | ||
} | ||
|
||
private func loginSucceeded( | ||
server: String, | ||
securityDomain: String, | ||
username: String, | ||
password: String, | ||
client: SMBClient | ||
) { | ||
let store = CredentialStore.shared | ||
store.save(server: server, securityDomain: securityDomain, username: username, password: password) | ||
|
||
sessions[ID(securityDomain)] = client | ||
} | ||
} | ||
|
||
extension Service: Identifiable {} | ||
|
||
#Preview(windowStyle: .automatic) { | ||
FileBrowserView() | ||
} |
Oops, something went wrong.