Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit 1a72423

Browse files
authored
Refactor SetupView shortcut installation logic
Updated the shortcut installation step to improve clarity and maintainability.
1 parent 849d4ab commit 1a72423

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

Sources/prostore/views/SetupView.swift

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct SetupView: View {
1515
),
1616
SetupPage(
1717
title: "Install ProStore Shortcut",
18-
subtitle: "Please install the shorcut below.",
18+
subtitle: "Please install the shortcut below.",
1919
imageName: "shortcut"
2020
),
2121
SetupPage(
@@ -67,35 +67,36 @@ struct SetupView: View {
6767

6868
Spacer()
6969

70-
Button(currentPage == pages.count - 1 ? "Finish" : "Next") {
71-
withAnimation {
72-
if pages[currentPage].title == "Install ProStore Shortcut" {
73-
// The raw GitHub URL (no extra encoding here).
74-
let rawURLString = "https://raw.githubusercontent.com/ProStore-iOS/files/refs/heads/main/Turn on VPN.shortcut"
75-
76-
// Build the shortcuts URL safely via URLComponents so the `url` query item is percent-encoded correctly.
77-
if var components = URLComponents(string: "shortcuts://import-shortcut") {
78-
components.queryItems = [
79-
URLQueryItem(name: "url", value: rawURLString)
80-
]
81-
82-
if let shortcutURL = components.url {
83-
UIApplication.shared.open(shortcutURL)
84-
} else {
85-
// fallback or debug
86-
print("Failed to build shortcuts URL")
87-
}
88-
}
89-
}
70+
Button(currentPage == pages.count - 1 ? "Finish" : "Next") {
71+
withAnimation {
9072

91-
if currentPage < pages.count - 1 {
92-
currentPage += 1
93-
} else {
94-
onComplete()
95-
}
96-
}
97-
}
73+
// MARK: - Shortcut install step
74+
if pages[currentPage].title == "Install ProStore Shortcut" {
75+
76+
// Raw GitHub URL — DO NOT manually encode it
77+
let rawURL = "https://raw.githubusercontent.com/ProStore-iOS/files/refs/heads/main/Turn on VPN.shortcut"
78+
79+
if var components = URLComponents(string: "shortcuts://import-shortcut") {
80+
components.queryItems = [
81+
URLQueryItem(name: "url", value: rawURL)
82+
]
9883

84+
if let shortcutURL = components.url {
85+
UIApplication.shared.open(shortcutURL)
86+
} else {
87+
print("⚠️ Failed to build import URL")
88+
}
89+
}
90+
}
91+
92+
// Continue navigation
93+
if currentPage < pages.count - 1 {
94+
currentPage += 1
95+
} else {
96+
onComplete()
97+
}
98+
}
99+
}
99100
.buttonStyle(.borderedProminent)
100101
}
101102
.padding(.horizontal)
@@ -111,6 +112,4 @@ struct SetupPage {
111112
let title: String
112113
let subtitle: String
113114
let imageName: String
114-
115115
}
116-

0 commit comments

Comments
 (0)