Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: prompt for sign in when turning VPN on if signed out#114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ethanndickson merged 1 commit intomainfromethan/toggle-prompt-sign-in
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -78,4 +78,6 @@ final class PreviewVPN: Coder_Desktop.VPNService {
func configureTunnelProviderProtocol(proto _: NETunnelProviderProtocol?) {
state = .connecting
}

var startWhenReady: Bool = false
}
1 change: 1 addition & 0 deletionsCoder-Desktop/Coder-Desktop/VPN/VPNService.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,7 @@ protocol VPNService: ObservableObject {
func start() async
func stop() async
func configureTunnelProviderProtocol(proto: NETunnelProviderProtocol?)
var startWhenReady: Bool { get set }
}

enum VPNServiceState: Equatable {
Expand Down
17 changes: 14 additions & 3 deletionsCoder-Desktop/Coder-Desktop/Views/VPNMenu.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@ struct VPNMenu<VPN: VPNService>: View {
@EnvironmentObject var vpn: VPN
@EnvironmentObject var state: AppState
@Environment(\.openSettings) private var openSettings
@Environment(\.openWindow) private var openWindow

let inspection = Inspection<Self>()

Expand All@@ -16,7 +17,18 @@ struct VPNMenu<VPN: VPNService>: View {
Toggle(isOn: Binding(
get: { vpn.state == .connected || vpn.state == .connecting },
set: { isOn in Task {
if isOn { await vpn.start() } else { await vpn.stop() }
if isOn {
// Clicking the toggle while logged out should
// open the login window, then start the VPN asap
if !state.hasSession {
vpn.startWhenReady = true
openWindow(id: .login)
} else {
await vpn.start()
}
} else {
await vpn.stop()
}
}
}
)) {
Expand DownExpand Up@@ -86,8 +98,7 @@ struct VPNMenu<VPN: VPNService>: View {
}

private var vpnDisabled: Bool {
!state.hasSession ||
vpn.state == .connecting ||
vpn.state == .connecting ||
vpn.state == .disconnecting ||
// Prevent starting the VPN before the user has approved the system extension.
vpn.state == .failed(.systemExtensionError(.needsUserApproval))
Expand Down
1 change: 1 addition & 0 deletionsCoder-Desktop/Coder-DesktopTests/Util.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,6 +23,7 @@ class MockVPNService: VPNService, ObservableObject {
}

func configureTunnelProviderProtocol(proto _: NETunnelProviderProtocol?) {}
var startWhenReady: Bool = false
}

extension Inspection: @unchecked Sendable, @retroactive InspectionEmissary {}
2 changes: 1 addition & 1 deletionCoder-Desktop/Coder-DesktopTests/VPNMenuTests.swift
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,7 @@ struct VPNMenuTests {
try await ViewHosting.host(view) {
try await sut.inspection.inspect { view in
let toggle = try view.find(ViewType.Toggle.self)
#expect(toggle.isDisabled())
#expect(!toggle.isDisabled())
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The toggle is now enabled when signed out.

#expect(throws: Never.self) { try view.find(text: "Sign in to use Coder Desktop") }
#expect(throws: Never.self) { try view.find(button: "Sign in") }
}
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp