mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-19 12:56:06 +00:00
Improve introduction view
This commit is contained in:
1 parent
09ef75d249
commit
e8fdd0e94a
3 files changed
+4995
-6907
No files matched your search
+4962
-6826
File diff suppressed because it is too large.
Load diff
@@ -63,6 +63,10 @@ struct IntroductionView: View {
|
|||||||
.padding(.top)
|
.padding(.top)
|
||||||
.minimumScaleFactor(0.5)
|
.minimumScaleFactor(0.5)
|
||||||
.opacity(0.8)
|
.opacity(0.8)
|
||||||
|
|
||||||
|
if currentPage == .enableShareExtension {
|
||||||
|
EnableExtensionView(canShowIntialCheckmark: true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.padding(.horizontal, 40)
|
.padding(.horizontal, 40)
|
||||||
|
|
||||||
@@ -78,8 +82,7 @@ struct IntroductionView: View {
|
|||||||
Divider()
|
Divider()
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
if let skipAction = currentPage.skipAction,
|
if let skipAction = currentPage.skipAction, pollingPage != nil {
|
||||||
(currentPage.needRequestBeforeSkipAvailable == false || pollingPage != nil) {
|
|
||||||
|
|
||||||
Button("introduction_skip") {
|
Button("introduction_skip") {
|
||||||
self.skipAction = skipAction
|
self.skipAction = skipAction
|
||||||
@@ -106,22 +109,6 @@ struct IntroductionView: View {
|
|||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
if let helpAction = currentPage.helpAction, pollingPage != nil {
|
|
||||||
HStack(spacing: 3) {
|
|
||||||
Image(systemName: "questionmark.circle")
|
|
||||||
Text(helpAction.question.localized())
|
|
||||||
}
|
|
||||||
.opacity(0.8)
|
|
||||||
.foregroundColor(.blue)
|
|
||||||
.font(.system(size: 15))
|
|
||||||
.onTapGesture {
|
|
||||||
helpActionAlert = helpAction
|
|
||||||
}
|
|
||||||
.alert(item: $helpActionAlert) { helpAction in
|
|
||||||
.init(title: Text(helpAction.question.localized()), message: Text(helpAction.answer.localized()), dismissButton: .cancel(Text("introduction_help_action_alert_close")))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
continueArea
|
continueArea
|
||||||
}
|
}
|
||||||
.padding(.horizontal)
|
.padding(.horizontal)
|
||||||
@@ -156,6 +143,7 @@ struct IntroductionView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private var continueArea: some View {
|
private var continueArea: some View {
|
||||||
ZStack {
|
ZStack {
|
||||||
@@ -181,6 +169,7 @@ struct IntroductionView: View {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private func pageDidChange(to newPage: IntroductionPage) {
|
private func pageDidChange(to newPage: IntroductionPage) {
|
||||||
stopPolling()
|
stopPolling()
|
||||||
|
|
||||||
@@ -190,6 +179,7 @@ struct IntroductionView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private func continueTapped() {
|
private func continueTapped() {
|
||||||
// If already allowed, advance immediately
|
// If already allowed, advance immediately
|
||||||
if currentPage.canContinue() {
|
if currentPage.canContinue() {
|
||||||
@@ -199,41 +189,18 @@ struct IntroductionView: View {
|
|||||||
|
|
||||||
// Not allowed yet: show loading and start polling every 1s
|
// Not allowed yet: show loading and start polling every 1s
|
||||||
pollingPage = currentPage
|
pollingPage = currentPage
|
||||||
|
|
||||||
// Page-specific "kickoff" action that should happen only after user presses continue
|
|
||||||
if currentPage == .enableShareExtension {
|
|
||||||
if let url = URL(string: "x-apple.systempreferences:com.apple.LoginItems-Settings.extension") {
|
|
||||||
NSWorkspace.shared.open(url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if currentPage == .localNetworkAccess {
|
|
||||||
Task {
|
|
||||||
do {
|
|
||||||
try await Task.sleep(nanoseconds: 20_000_000_000)
|
|
||||||
} catch {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
await MainActor.run {
|
|
||||||
guard currentPage == .localNetworkAccess else { return }
|
|
||||||
guard skipAction == nil else { return }
|
|
||||||
|
|
||||||
if let action = currentPage.skipAction {
|
|
||||||
skipAction = action
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private func triggerLocalNetworkPermission() {
|
private func triggerLocalNetworkPermission() {
|
||||||
self.startReceiving()
|
self.startReceiving()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private func advance() {
|
private func advance() {
|
||||||
|
|
||||||
if currentPage == .splash {
|
if currentPage == .localNetworkAccess {
|
||||||
|
let _ = DeviceToDeviceHeuristicScanner.shared.hasLocalNetworkAccess(completion: {_ in })
|
||||||
triggerLocalNetworkPermission()
|
triggerLocalNetworkPermission()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,6 +211,7 @@ struct IntroductionView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private func stopPolling() {
|
private func stopPolling() {
|
||||||
// Cancels the .task(id:) by changing the id and resets UI state
|
// Cancels the .task(id:) by changing the id and resets UI state
|
||||||
pollingPage = nil
|
pollingPage = nil
|
||||||
@@ -251,7 +219,6 @@ struct IntroductionView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum IntroductionPage: CaseIterable {
|
enum IntroductionPage: CaseIterable {
|
||||||
case splash
|
case splash
|
||||||
case noWifi
|
case noWifi
|
||||||
@@ -274,6 +241,7 @@ enum IntroductionPage: CaseIterable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var subtitle: String {
|
var subtitle: String {
|
||||||
switch self {
|
switch self {
|
||||||
case .splash:
|
case .splash:
|
||||||
@@ -283,47 +251,22 @@ enum IntroductionPage: CaseIterable {
|
|||||||
case .localNetworkAccess:
|
case .localNetworkAccess:
|
||||||
return "introduction_local_network_access_description".localized(with: "introduction_continue".localized())
|
return "introduction_local_network_access_description".localized(with: "introduction_continue".localized())
|
||||||
case .enableShareExtension:
|
case .enableShareExtension:
|
||||||
if #available(macOS 13.0, *) {
|
return "introduction_enable_share_extension_description".localized(with: "EnableQuickDropExtension".localized())
|
||||||
return "introduction_enable_share_extension_description"
|
|
||||||
}
|
|
||||||
return "introduction_enable_share_extension_description_macos12"
|
|
||||||
case .finished:
|
case .finished:
|
||||||
return "introduction_finished_description"
|
return "introduction_finished_description"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var skipAction: SkipAction? {
|
var skipAction: SkipAction? {
|
||||||
switch self {
|
switch self {
|
||||||
case .splash:
|
|
||||||
return nil
|
|
||||||
case .noWifi:
|
case .noWifi:
|
||||||
return .init(action: presentNextPage, warningTitle: "introduction_no_wifi_skip_title", warningMessage: "introduction_no_wifi_skip_message")
|
return .init(action: presentNextPage, warningTitle: "introduction_no_wifi_skip_title", warningMessage: "introduction_no_wifi_skip_message")
|
||||||
case .localNetworkAccess:
|
|
||||||
return .init(action: presentNextPage, warningTitle: "introduction_local_network_access_skip_title", warningMessage: "introduction_local_network_access_skip_message")
|
|
||||||
case .enableShareExtension:
|
|
||||||
return .init(action: presentNextPage, warningTitle: "introduction_enable_share_extension_skip_title", warningMessage: "introduction_enable_share_extension_skip_message")
|
|
||||||
case .finished:
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var helpAction: HelpAction? {
|
|
||||||
switch self {
|
|
||||||
case .enableShareExtension:
|
|
||||||
return .init(question: "introduction_enable_share_extension_not_visible", answer: "introduction_enable_share_extension_not_visible_answer")
|
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var needRequestBeforeSkipAvailable: Bool {
|
|
||||||
switch self {
|
|
||||||
case .localNetworkAccess:
|
|
||||||
return true
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var canPerformAction: Bool {
|
var canPerformAction: Bool {
|
||||||
switch self {
|
switch self {
|
||||||
@@ -334,11 +277,11 @@ enum IntroductionPage: CaseIterable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func presentNextPage() -> IntroductionPage? {
|
func presentNextPage() -> IntroductionPage? {
|
||||||
switch self {
|
switch self {
|
||||||
case .splash:
|
case .splash:
|
||||||
return nil
|
return NearbyConnectionManager.shared.isConnectedToLocalNetwork ? firstPermissionPane() : .noWifi
|
||||||
//NearbyConnectionManager.shared.isConnectedToLocalNetwork ? firstPermissionPane() : .noWifi
|
|
||||||
case .noWifi:
|
case .noWifi:
|
||||||
return firstPermissionPane()
|
return firstPermissionPane()
|
||||||
case .localNetworkAccess:
|
case .localNetworkAccess:
|
||||||
@@ -350,6 +293,7 @@ enum IntroductionPage: CaseIterable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private func firstPermissionPane() -> IntroductionPage {
|
private func firstPermissionPane() -> IntroductionPage {
|
||||||
if #available(macOS 15.0, *) {
|
if #available(macOS 15.0, *) {
|
||||||
// Local network access is requested first on macOS 15+
|
// Local network access is requested first on macOS 15+
|
||||||
@@ -358,19 +302,17 @@ enum IntroductionPage: CaseIterable {
|
|||||||
return .enableShareExtension
|
return .enableShareExtension
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func canContinue() -> Bool {
|
func canContinue() -> Bool {
|
||||||
switch self {
|
switch self {
|
||||||
case .noWifi:
|
case .noWifi:
|
||||||
return NearbyConnectionManager.shared.isConnectedToLocalNetwork
|
return NearbyConnectionManager.shared.isConnectedToLocalNetwork
|
||||||
case .enableShareExtension:
|
|
||||||
return NSSharingService(named: NSSharingService.Name("com.leonboettger.neardrop.ShareExtension")) != nil
|
|
||||||
case .localNetworkAccess:
|
|
||||||
return DeviceToDeviceHeuristicScanner.shared.hasLocalNetworkAccess(completion: {_ in })
|
|
||||||
default:
|
default:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func topHeader(with height: CGFloat) -> some View {
|
func topHeader(with height: CGFloat) -> some View {
|
||||||
ZStack {
|
ZStack {
|
||||||
|
|
||||||
@@ -395,6 +337,7 @@ enum IntroductionPage: CaseIterable {
|
|||||||
.foregroundColor(.blue)
|
.foregroundColor(.blue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private func imageView(for image: String, with height: CGFloat) -> some View {
|
private func imageView(for image: String, with height: CGFloat) -> some View {
|
||||||
Image(systemName: image)
|
Image(systemName: image)
|
||||||
.resizable()
|
.resizable()
|
||||||
@@ -403,6 +346,7 @@ enum IntroductionPage: CaseIterable {
|
|||||||
.padding(.top, height * 0.13)
|
.padding(.top, height * 0.13)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct SkipAction: Identifiable {
|
struct SkipAction: Identifiable {
|
||||||
let action: () -> IntroductionPage?
|
let action: () -> IntroductionPage?
|
||||||
let warningTitle: String
|
let warningTitle: String
|
||||||
@@ -411,6 +355,7 @@ enum IntroductionPage: CaseIterable {
|
|||||||
var id: String { warningTitle }
|
var id: String { warningTitle }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct HelpAction: Identifiable {
|
struct HelpAction: Identifiable {
|
||||||
let question: String
|
let question: String
|
||||||
let answer: String
|
let answer: String
|
||||||
|
|||||||
@@ -100,8 +100,15 @@ struct EnableExtensionView: View {
|
|||||||
|
|
||||||
private let timer = Timer.publish(every: 1.0, on: .main, in: .common).autoconnect()
|
private let timer = Timer.publish(every: 1.0, on: .main, in: .common).autoconnect()
|
||||||
|
|
||||||
init() {
|
init(canShowIntialCheckmark: Bool = false) {
|
||||||
_isExtensionEnabled = State(initialValue: Self.isEnabled())
|
let isEnabled = Self.isEnabled()
|
||||||
|
|
||||||
|
_isExtensionEnabled = State(initialValue: isEnabled)
|
||||||
|
|
||||||
|
if canShowIntialCheckmark && isEnabled {
|
||||||
|
_showSuccessCheckmark = State(initialValue: true)
|
||||||
|
_animateCheckmark = State(initialValue: true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
|||||||
Reference in new issue
Block a user