Skip to content
This repository has been archived by the owner on Nov 17, 2024. It is now read-only.

Commit

Permalink
GetCookieViews // Use nav in lieu of sheet.
Browse files Browse the repository at this point in the history
- Updated the Miyoushe / HoYoLAB login view by using destination-based navigations in lieu of pop-up sheets. This behavioral change is a workaround for a system bug happened inside iOS 18, causing the QR Code login sheet automatically dismisses when the user saved the QR code through the shared link menu called by system APIs.
  • Loading branch information
ShikiSuen committed Sep 11, 2024
1 parent 9b546ea commit 50bf4d4
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 68 deletions.
88 changes: 80 additions & 8 deletions GenshinPizzaHepler/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -39830,25 +39830,61 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "China Mainland Server"
"value" : "Miyoushe"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Miyoushe"
}
},
"fil" : {
"stringUnit" : {
"state" : "translated",
"value" : "Miyoushe"
}
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Miyoushe"
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "中国内陸のサーバー"
"value" : "米遊社"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "Miyoushe"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "Miyoushe"
}
},
"vi" : {
"stringUnit" : {
"state" : "translated",
"value" : "Miyoushe"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "中国内地服务器"
"value" : "米游社"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "translated",
"value" : "中國內地伺服器"
"value" : "米遊社"
}
}
}
Expand All @@ -39858,25 +39894,61 @@
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Global Servers"
"value" : "HoYoLAB"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "HoYoLAB"
}
},
"fil" : {
"stringUnit" : {
"state" : "translated",
"value" : "HoYoLAB"
}
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "HoYoLAB"
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "他のサーバー"
"value" : "HoYoLAB"
}
},
"ko" : {
"stringUnit" : {
"state" : "translated",
"value" : "HoYoLAB"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "HoYoLAB"
}
},
"vi" : {
"stringUnit" : {
"state" : "translated",
"value" : "HoYoLAB"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "全球服务器"
"value" : "HoYoLAB"
}
},
"zh-Hant" : {
"stringUnit" : {
"state" : "translated",
"value" : "全球伺服器"
"value" : "HoYoLAB"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ struct CreateAccountSheetView: View {
private struct RequireLoginView: View {
// MARK: Internal

@State
var getCookieWebViewRegion: Region?
@Binding
var unsavedCookie: String?
@Binding
Expand All @@ -232,38 +230,26 @@ private struct RequireLoginView: View {
var region: Region

var body: some View {
Menu {
Button("sys.server.cn") {
assign(region: .mainlandChina)
}
Button("sys.server.os") {
assign(region: .global)
}
Picker("".description, selection: $region) {
Text("sys.server.cn").tag(Region.mainlandChina)
Text("sys.server.os").tag(Region.global)
}
.labelsHidden()
.pickerStyle(.segmented)
NavigationLink {
handleSheetNavigation()
} label: {
Group {
if isUnsavedCookieInvalid {
Text("settings.account.loginViaMiyousheOrHoyoLab")
} else {
Text("settings.account.loginViaMiyousheOrHoyoLab.relogin")
}
}
Text(
isUnsavedCookieInvalid
? "settings.account.loginViaMiyousheOrHoyoLab"
: "settings.account.loginViaMiyousheOrHoyoLab.relogin"
)
.frame(
maxWidth: .infinity,
maxHeight: .infinity
)
}
.sheet(item: $getCookieWebViewRegion, content: { region in
switch region {
case .mainlandChina:
GetCookieQRCodeView(cookie: $unsavedCookie, deviceFP: $unsavedFP)
case .global:
GetCookieWebView(
isShown: isCookieWebViewShown,
cookie: $unsavedCookie,
region: region
)
}
})
.foregroundColor(.accentColor)
}

// MARK: Private
Expand All @@ -272,19 +258,23 @@ private struct RequireLoginView: View {
(unsavedCookie ?? "").isEmpty
}

private var isCookieWebViewShown: Binding<Bool> {
.init(get: {
getCookieWebViewRegion != nil
}, set: { newValue in
if !newValue {
getCookieWebViewRegion = nil
private func handleSheetNavigation() -> some View {
Group {
switch region {
case .mainlandChina:
GetCookieQRCodeView(cookie: $unsavedCookie, deviceFP: $unsavedFP)
case .global:
GetCookieWebView(cookie: $unsavedCookie, region: region)
}
})
}

private func assign(region givenRegion: Region) {
getCookieWebViewRegion = givenRegion
region = givenRegion
}
// 保证用户只能在结束编辑、关掉该画面之后才能切到别的 Tab。
#if os(iOS) || targetEnvironment(macCatalyst)
.toolbar(.hidden, for: .tabBar)
#endif
// 逼着用户改用自订的后退按钮。
// 这也防止 iPhone / iPad 用户以横扫手势将当前画面失手关掉。
// 当且仅当用户点了后退按钮或完成按钮,这个画面才会关闭。
.navigationBarBackButtonHidden(true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,47 @@ struct EditAccountView: View {
// MARK: - RequireLoginView

private struct RequireLoginView: View {
// MARK: Internal

@Binding
var unsavedCookie: String?
@Binding
var unsavedFP: String

@State
private var isGetCookieWebViewShown: Bool = false

let region: Region

var body: some View {
Button {
isGetCookieWebViewShown.toggle()
NavigationLink {
handleSheetNavigation()
} label: {
Text("settings.account.loginViaMiyousheOrHoyoLab.relogin")
.frame(
maxWidth: .infinity,
maxHeight: .infinity
)
}
.sheet(isPresented: $isGetCookieWebViewShown, content: {
.foregroundColor(.accentColor)
}

// MARK: Private

private func handleSheetNavigation() -> some View {
Group {
switch region {
case .mainlandChina:
GetCookieQRCodeView(cookie: $unsavedCookie, deviceFP: $unsavedFP)
case .global:
GetCookieWebView(
isShown: $isGetCookieWebViewShown,
cookie: $unsavedCookie,
region: region
)
GetCookieWebView(cookie: $unsavedCookie, region: region)
}
})
}
// 保证用户只能在结束编辑、关掉该画面之后才能切到别的 Tab。
#if os(iOS) || targetEnvironment(macCatalyst)
.toolbar(.hidden, for: .tabBar)
#endif
// 逼着用户改用自订的后退按钮。
// 这也防止 iPhone / iPad 用户以横扫手势将当前画面失手关掉。
// 当且仅当用户点了后退按钮或完成按钮,这个画面才会关闭。
.navigationBarBackButtonHidden(true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import SwiftUI
// MARK: - GetCookieQRCodeView

struct GetCookieQRCodeView: View {
@Environment(\.dismiss)
private var dismiss
@Environment(\.presentationMode)
private var presentationMode: Binding<PresentationMode>

@StateObject
var viewModel = GetCookieQRCodeViewModel.shared
Expand Down Expand Up @@ -111,7 +111,7 @@ struct GetCookieQRCodeView: View {
cookie += "mid=" + parsedResult.mid + "; "
try await extraCookieProcess(cookie: &cookie)
self.cookie = cookie
if shouldDismiss { dismiss() }
if shouldDismiss { presentationMode.wrappedValue.dismiss() }
}

@ViewBuilder
Expand Down Expand Up @@ -206,7 +206,7 @@ struct GetCookieQRCodeView: View {
.toolbar {
ToolbarItem(placement: .topBarLeading) {
Button("sys.cancel") {
dismiss()
presentationMode.wrappedValue.dismiss()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import WebKit
// MARK: - GetCookieWebView

struct GetCookieWebView: View {
@Binding
var isShown: Bool
@Environment(\.presentationMode)
private var presentationMode: Binding<PresentationMode>

@Binding
var cookie: String!
Expand Down Expand Up @@ -43,7 +43,7 @@ struct GetCookieWebView: View {
ToolbarItem(placement: .navigationBarLeading) {
Button("sys.cancel") {
Task.detached { @MainActor in
isShown.toggle()
presentationMode.wrappedValue.dismiss()
}
}
}
Expand All @@ -60,7 +60,7 @@ struct GetCookieWebView: View {

@MainActor
func getCookieFromDataStore() async {
defer { isShown.toggle() }
defer { presentationMode.wrappedValue.dismiss() }
cookie = ""
let cookies = await dataStore.httpCookieStore.allCookies()

Expand Down

0 comments on commit 50bf4d4

Please sign in to comment.