Fix preview

This commit is contained in:
世界
2023-07-30 15:35:10 +08:00
parent 2ca6c515b9
commit fed5419ea0
8 changed files with 94 additions and 73 deletions
@@ -79,18 +79,6 @@ public struct ActiveDashboardView: View {
} }
} }
.alertBinding($alert) .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) #if os(iOS) || os(tvOS)
.onChangeCompat(of: scenePhase) { newValue in .onChangeCompat(of: scenePhase) { newValue in
if newValue == .active { if newValue == .active {
@@ -168,4 +156,15 @@ public struct ActiveDashboardView: View {
} }
reasserting = false reasserting = false
} }
private struct ServiceErrorReporter: View {
private let parent: ActiveDashboardView
init(_ parent: ActiveDashboardView) {
self.parent = parent
}
var body: some View {
EmptyView()
}
}
} }
@@ -58,7 +58,7 @@ public struct DashboardView: View {
if ApplicationLibrary.inPreview { if ApplicationLibrary.inPreview {
ActiveDashboardView() ActiveDashboardView()
} else if let profile = extensionProfile.wrappedValue { } else if let profile = extensionProfile.wrappedValue {
ActiveDashboardView().environmentObject(profile) DashboardView1().environmentObject(profile)
} else { } else {
FormView { FormView {
InstallProfileButton() 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)
}
}
}
}
}
}
} }
@@ -71,15 +71,15 @@ public extension NavigationPage {
} }
func visible(_ profile: ExtensionProfile?) -> Bool { func visible(_ profile: ExtensionProfile?) -> Bool {
if ApplicationLibrary.inPreview {
return true
}
switch self { switch self {
case .groups: case .groups:
#if os(tvOS) #if os(tvOS)
// TODO: fix groups ui // TODO: fix groups ui
return false return false
#else #else
if ApplicationLibrary.inPreview {
return true
}
return profile?.status.isConnectedStrict == true return profile?.status.isConnectedStrict == true
#endif #endif
default: default:
@@ -66,7 +66,7 @@ public struct ProfileView: View {
.disabled(editMode.isEditing) .disabled(editMode.isEditing)
#endif #endif
#if os(tvOS) #if os(tvOS)
if devicePickerSupports(.applicationService(name: "sing-box"), parameters: { .applicationService }) { if ApplicationLibrary.inPreview || devicePickerSupports(.applicationService(name: "sing-box"), parameters: { .applicationService }) {
NavigationLink { NavigationLink {
ImportProfileView { ImportProfileView {
Task.detached { Task.detached {
-7
View File
@@ -1,10 +1,3 @@
//
// Profile+Date.swift
// Library
//
// Created by on 2023/6/29.
//
import Foundation import Foundation
public extension Profile { public extension Profile {
+1 -1
View File
@@ -49,7 +49,7 @@ public struct MainView: View {
StartStopButton() StartStopButton()
} }
} }
.onChangeComat(of: controlActiveState) { newValue in .onChangeCompat(of: controlActiveState) { newValue in
if newValue != .inactive { if newValue != .inactive {
Task { Task {
await loadProfile() await loadProfile()
+7 -7
View File
@@ -1198,7 +1198,7 @@
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
BuildIndependentTargetsInParallel = 1; BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1430; LastSwiftUpdateCheck = 1500;
LastUpgradeCheck = 1430; LastUpgradeCheck = 1430;
TargetAttributes = { TargetAttributes = {
3A096F852A4ED3DE00D4A2ED = { 3A096F852A4ED3DE00D4A2ED = {
@@ -1716,8 +1716,8 @@
SDKROOT = iphoneos; SDKROOT = iphoneos;
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx"; SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx";
SUPPORTS_MACCATALYST = YES; SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
@@ -1759,8 +1759,8 @@
SDKROOT = iphoneos; SDKROOT = iphoneos;
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx"; SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx";
SUPPORTS_MACCATALYST = YES; SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3"; TARGETED_DEVICE_FAMILY = "1,2,3";
@@ -2252,7 +2252,7 @@
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx"; SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx";
SUPPORTS_MACCATALYST = NO; SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = YES; SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = YES;
SWIFT_EMIT_LOC_STRINGS = NO; SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@@ -2307,7 +2307,7 @@
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx"; SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx";
SUPPORTS_MACCATALYST = NO; SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = YES; SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = YES;
SWIFT_EMIT_LOC_STRINGS = NO; SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
@@ -7,21 +7,21 @@
<key>ApplicationLibrary.xcscheme_^#shared#^_</key> <key>ApplicationLibrary.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>6</integer> <integer>8</integer>
</dict> </dict>
<key>Associations (Playground) 1.xcscheme</key> <key>Associations (Playground) 1.xcscheme</key>
<dict> <dict>
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>18</integer> <integer>16</integer>
</dict> </dict>
<key>Associations (Playground) 2.xcscheme</key> <key>Associations (Playground) 2.xcscheme</key>
<dict> <dict>
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>19</integer> <integer>17</integer>
</dict> </dict>
<key>Associations (Playground) 3.xcscheme</key> <key>Associations (Playground) 3.xcscheme</key>
<dict> <dict>
@@ -49,7 +49,7 @@
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>17</integer> <integer>15</integer>
</dict> </dict>
<key>ExtensionMac.xcscheme_^#shared#^_</key> <key>ExtensionMac.xcscheme_^#shared#^_</key>
<dict> <dict>
@@ -69,7 +69,7 @@
<key>MacLibrary.xcscheme_^#shared#^_</key> <key>MacLibrary.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>2</integer> <integer>3</integer>
</dict> </dict>
<key>MessageExtension.xcscheme_^#shared#^_</key> <key>MessageExtension.xcscheme_^#shared#^_</key>
<dict> <dict>
@@ -81,14 +81,14 @@
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>12</integer> <integer>13</integer>
</dict> </dict>
<key>MyPlayground (Playground) 2.xcscheme</key> <key>MyPlayground (Playground) 2.xcscheme</key>
<dict> <dict>
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>13</integer> <integer>14</integer>
</dict> </dict>
<key>MyPlayground (Playground) 3.xcscheme</key> <key>MyPlayground (Playground) 3.xcscheme</key>
<dict> <dict>
@@ -116,7 +116,7 @@
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>11</integer> <integer>12</integer>
</dict> </dict>
<key>SFA.xcscheme_^#shared#^_</key> <key>SFA.xcscheme_^#shared#^_</key>
<dict> <dict>
@@ -131,7 +131,7 @@
<key>SFM.System.xcscheme_^#shared#^_</key> <key>SFM.System.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>4</integer> <integer>6</integer>
</dict> </dict>
<key>SFM.xcscheme</key> <key>SFM.xcscheme</key>
<dict> <dict>
@@ -141,12 +141,17 @@
<key>SFT.xcscheme_^#shared#^_</key> <key>SFT.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>5</integer> <integer>7</integer>
</dict>
<key>ShareExtension.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>21</integer>
</dict> </dict>
<key>SystemExtension.xcscheme_^#shared#^_</key> <key>SystemExtension.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>3</integer> <integer>5</integer>
</dict> </dict>
<key>Test.xcscheme_^#shared#^_</key> <key>Test.xcscheme_^#shared#^_</key>
<dict> <dict>
@@ -158,14 +163,14 @@
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>15</integer> <integer>10</integer>
</dict> </dict>
<key>Tour (Playground) 2.xcscheme</key> <key>Tour (Playground) 2.xcscheme</key>
<dict> <dict>
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>16</integer> <integer>11</integer>
</dict> </dict>
<key>Tour (Playground) 3.xcscheme</key> <key>Tour (Playground) 3.xcscheme</key>
<dict> <dict>
@@ -193,21 +198,21 @@
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>14</integer> <integer>9</integer>
</dict> </dict>
<key>TransactionObserver (Playground) 1.xcscheme</key> <key>TransactionObserver (Playground) 1.xcscheme</key>
<dict> <dict>
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>9</integer> <integer>19</integer>
</dict> </dict>
<key>TransactionObserver (Playground) 2.xcscheme</key> <key>TransactionObserver (Playground) 2.xcscheme</key>
<dict> <dict>
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>10</integer> <integer>20</integer>
</dict> </dict>
<key>TransactionObserver (Playground) 3.xcscheme</key> <key>TransactionObserver (Playground) 3.xcscheme</key>
<dict> <dict>
@@ -235,7 +240,7 @@
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>8</integer> <integer>18</integer>
</dict> </dict>
<key>mactest.xcscheme_^#shared#^_</key> <key>mactest.xcscheme_^#shared#^_</key>
<dict> <dict>