diff --git a/ApplicationLibrary/Views/Dashboard/ActiveDashboardView.swift b/ApplicationLibrary/Views/Dashboard/ActiveDashboardView.swift index 4b2b7e0..69d8d08 100644 --- a/ApplicationLibrary/Views/Dashboard/ActiveDashboardView.swift +++ b/ApplicationLibrary/Views/Dashboard/ActiveDashboardView.swift @@ -79,48 +79,36 @@ public struct ActiveDashboardView: View { } } .alertBinding($alert) - .onChangeCompat(of: profile.status) { newValue in - if newValue == .disconnecting || newValue == .connected { - Task.detached { - if let serviceError = try? String(contentsOf: ExtensionProvider.errorFile) { - DispatchQueue.main.async { - alert = Alert(errorMessage: serviceError) - } - try? FileManager.default.removeItem(at: ExtensionProvider.errorFile) - } - } - } - } #if os(iOS) || os(tvOS) - .onChangeCompat(of: scenePhase) { newValue in - if newValue == .active { - Task.detached { - await doReload() - } - } - } - .onChangeCompat(of: selection.wrappedValue) { newValue in - if newValue == .dashboard { - Task.detached { - await doReload() - } - } - } - #elseif os(macOS) - .onAppear { - if observer == nil { - observer = NotificationCenter.default.addObserver(forName: ActiveDashboardView.NotificationUpdateSelectedProfile, object: nil, queue: nil, using: { _ in + .onChangeCompat(of: scenePhase) { newValue in + if newValue == .active { Task.detached { await doReload() } - }) + } } - } - .onDisappear { - if let observer { - NotificationCenter.default.removeObserver(observer) + .onChangeCompat(of: selection.wrappedValue) { newValue in + if newValue == .dashboard { + Task.detached { + await doReload() + } + } + } + #elseif os(macOS) + .onAppear { + if observer == nil { + observer = NotificationCenter.default.addObserver(forName: ActiveDashboardView.NotificationUpdateSelectedProfile, object: nil, queue: nil, using: { _ in + Task.detached { + await doReload() + } + }) + } + } + .onDisappear { + if let observer { + NotificationCenter.default.removeObserver(observer) + } } - } #endif } @@ -168,4 +156,15 @@ public struct ActiveDashboardView: View { } reasserting = false } + + private struct ServiceErrorReporter: View { + private let parent: ActiveDashboardView + init(_ parent: ActiveDashboardView) { + self.parent = parent + } + + var body: some View { + EmptyView() + } + } } diff --git a/ApplicationLibrary/Views/Dashboard/DashboardView.swift b/ApplicationLibrary/Views/Dashboard/DashboardView.swift index 97eccdb..4a7bf17 100644 --- a/ApplicationLibrary/Views/Dashboard/DashboardView.swift +++ b/ApplicationLibrary/Views/Dashboard/DashboardView.swift @@ -58,7 +58,7 @@ public struct DashboardView: View { if ApplicationLibrary.inPreview { ActiveDashboardView() } else if let profile = extensionProfile.wrappedValue { - ActiveDashboardView().environmentObject(profile) + DashboardView1().environmentObject(profile) } else { FormView { InstallProfileButton() @@ -66,4 +66,28 @@ public struct DashboardView: View { } } } + + struct DashboardView1: View { + @EnvironmentObject private var profile: ExtensionProfile + @State private var alert: Alert? + + var body: some View { + ActiveDashboardView() + .environmentObject(profile) + EmptyView() + .alertBinding($alert) + .onChangeCompat(of: profile.status) { newValue in + if newValue == .disconnecting || newValue == .connected { + Task.detached { + if let serviceError = try? String(contentsOf: ExtensionProvider.errorFile) { + DispatchQueue.main.async { + alert = Alert(errorMessage: serviceError) + } + try? FileManager.default.removeItem(at: ExtensionProvider.errorFile) + } + } + } + } + } + } } diff --git a/ApplicationLibrary/Views/NavigationPage.swift b/ApplicationLibrary/Views/NavigationPage.swift index c286160..7f4e8f5 100644 --- a/ApplicationLibrary/Views/NavigationPage.swift +++ b/ApplicationLibrary/Views/NavigationPage.swift @@ -71,15 +71,15 @@ public extension NavigationPage { } func visible(_ profile: ExtensionProfile?) -> Bool { - if ApplicationLibrary.inPreview { - return true - } switch self { case .groups: #if os(tvOS) // TODO: fix groups ui return false #else + if ApplicationLibrary.inPreview { + return true + } return profile?.status.isConnectedStrict == true #endif default: diff --git a/ApplicationLibrary/Views/Profile/ProfileView.swift b/ApplicationLibrary/Views/Profile/ProfileView.swift index f072bc5..552bfb8 100644 --- a/ApplicationLibrary/Views/Profile/ProfileView.swift +++ b/ApplicationLibrary/Views/Profile/ProfileView.swift @@ -66,7 +66,7 @@ public struct ProfileView: View { .disabled(editMode.isEditing) #endif #if os(tvOS) - if devicePickerSupports(.applicationService(name: "sing-box"), parameters: { .applicationService }) { + if ApplicationLibrary.inPreview || devicePickerSupports(.applicationService(name: "sing-box"), parameters: { .applicationService }) { NavigationLink { ImportProfileView { Task.detached { diff --git a/Library/Database/Profile+Date.swift b/Library/Database/Profile+Date.swift index 23f3088..c6f4b71 100644 --- a/Library/Database/Profile+Date.swift +++ b/Library/Database/Profile+Date.swift @@ -1,10 +1,3 @@ -// -// Profile+Date.swift -// Library -// -// Created by 世界 on 2023/6/29. -// - import Foundation public extension Profile { diff --git a/MacLibrary/MainView.swift b/MacLibrary/MainView.swift index a026d69..97118f5 100644 --- a/MacLibrary/MainView.swift +++ b/MacLibrary/MainView.swift @@ -49,7 +49,7 @@ public struct MainView: View { StartStopButton() } } - .onChangeComat(of: controlActiveState) { newValue in + .onChangeCompat(of: controlActiveState) { newValue in if newValue != .inactive { Task { await loadProfile() diff --git a/sing-box.xcodeproj/project.pbxproj b/sing-box.xcodeproj/project.pbxproj index a034319..7677432 100644 --- a/sing-box.xcodeproj/project.pbxproj +++ b/sing-box.xcodeproj/project.pbxproj @@ -1198,7 +1198,7 @@ isa = PBXProject; attributes = { BuildIndependentTargetsInParallel = 1; - LastSwiftUpdateCheck = 1430; + LastSwiftUpdateCheck = 1500; LastUpgradeCheck = 1430; TargetAttributes = { 3A096F852A4ED3DE00D4A2ED = { @@ -1716,8 +1716,8 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx"; - SUPPORTS_MACCATALYST = YES; - SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; @@ -1759,8 +1759,8 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx"; - SUPPORTS_MACCATALYST = YES; - SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2,3"; @@ -2252,7 +2252,7 @@ SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx"; SUPPORTS_MACCATALYST = NO; - SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = YES; SWIFT_EMIT_LOC_STRINGS = NO; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -2307,7 +2307,7 @@ SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx"; SUPPORTS_MACCATALYST = NO; - SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = YES; SWIFT_EMIT_LOC_STRINGS = NO; SWIFT_VERSION = 5.0; diff --git a/sing-box.xcodeproj/xcuserdata/sekai.xcuserdatad/xcschemes/xcschememanagement.plist b/sing-box.xcodeproj/xcuserdata/sekai.xcuserdatad/xcschemes/xcschememanagement.plist index 6fd3a9e..4f58539 100644 --- a/sing-box.xcodeproj/xcuserdata/sekai.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/sing-box.xcodeproj/xcuserdata/sekai.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,21 +7,21 @@ ApplicationLibrary.xcscheme_^#shared#^_ orderHint - 6 + 8 Associations (Playground) 1.xcscheme isShown orderHint - 18 + 16 Associations (Playground) 2.xcscheme isShown orderHint - 19 + 17 Associations (Playground) 3.xcscheme @@ -49,7 +49,7 @@ isShown orderHint - 17 + 15 ExtensionMac.xcscheme_^#shared#^_ @@ -69,7 +69,7 @@ MacLibrary.xcscheme_^#shared#^_ orderHint - 2 + 3 MessageExtension.xcscheme_^#shared#^_ @@ -81,14 +81,14 @@ isShown orderHint - 12 + 13 MyPlayground (Playground) 2.xcscheme isShown orderHint - 13 + 14 MyPlayground (Playground) 3.xcscheme @@ -116,7 +116,7 @@ isShown orderHint - 11 + 12 SFA.xcscheme_^#shared#^_ @@ -131,7 +131,7 @@ SFM.System.xcscheme_^#shared#^_ orderHint - 4 + 6 SFM.xcscheme @@ -141,12 +141,17 @@ SFT.xcscheme_^#shared#^_ orderHint - 5 + 7 + + ShareExtension.xcscheme_^#shared#^_ + + orderHint + 21 SystemExtension.xcscheme_^#shared#^_ orderHint - 3 + 5 Test.xcscheme_^#shared#^_ @@ -158,14 +163,14 @@ isShown orderHint - 15 + 10 Tour (Playground) 2.xcscheme isShown orderHint - 16 + 11 Tour (Playground) 3.xcscheme @@ -193,21 +198,21 @@ isShown orderHint - 14 + 9 TransactionObserver (Playground) 1.xcscheme isShown orderHint - 9 + 19 TransactionObserver (Playground) 2.xcscheme isShown orderHint - 10 + 20 TransactionObserver (Playground) 3.xcscheme @@ -235,7 +240,7 @@ isShown orderHint - 8 + 18 mactest.xcscheme_^#shared#^_