Skip to content

Commit

Permalink
fix: epic games login now works.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBrest committed Nov 16, 2024
1 parent e8f32ec commit 98f7f2e
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 63 deletions.
140 changes: 92 additions & 48 deletions Sources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -22816,10 +22816,30 @@
}
},
"genericWebView.error" : {

"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "An error occurred while loading this page: %@"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "jiazaiciyemen"
}
}
}
},
"genericWebView.retry" : {

"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Retry"
}
}
}
},
"Get support/Support Mythic" : {
"localizations" : {
Expand Down Expand Up @@ -24158,13 +24178,68 @@
}
},
"hubLibraryView.title" : {

"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Library"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "库"
}
}
}
},
"hubSettingsView.title" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Settings"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "设置"
}
}
}
},
"hubStoreEpicGamesView.title" : {

"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Epic Games Store"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "Epic Games 商店"
}
}
}
},
"hubStoreView.title" : {

"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Store"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "商店"
}
}
}
},
"I have read and agreed to the terms of the software license agreement." : {
"extractionState" : "stale",
Expand Down Expand Up @@ -36222,7 +36297,7 @@
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"state" : "translated",
"value" : "开发版"
}
}
Expand Down Expand Up @@ -36296,7 +36371,7 @@
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"state" : "translated",
"value" : "查看支持页面"
}
}
Expand All @@ -36312,7 +36387,7 @@
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"state" : "translated",
"value" : "跳过 Engine 设置"
}
}
Expand All @@ -36328,7 +36403,7 @@
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"state" : "translated",
"value" : "用户名无效"
}
}
Expand All @@ -36354,7 +36429,7 @@
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"state" : "translated",
"value" : "CodeWeavers"
}
}
Expand All @@ -36370,7 +36445,7 @@
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"state" : "translated",
"value" : "Mac 版 Wine 的重大贡献和持续的开发支持。"
}
}
Expand All @@ -36386,7 +36461,7 @@
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"state" : "translated",
"value" : "Gcenx"
}
}
Expand All @@ -36412,7 +36487,7 @@
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"state" : "translated",
"value" : "Whisky"
}
}
Expand Down Expand Up @@ -36444,23 +36519,6 @@
}
}
},
"onboardingEpicGamesLoginStepView.authCode" : {
"extractionState" : "stale",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Authorization Code"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "授权吗"
}
}
}
},
"onboardingEpicGamesLoginStepView.description" : {
"localizations" : {
"en" : {
Expand All @@ -36481,7 +36539,7 @@
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"state" : "translated",
"value" : "Epic Games 登录"
}
}
Expand Down Expand Up @@ -36523,23 +36581,6 @@
}
}
},
"onboardingEpicGamesLoginStepView.getCode" : {
"extractionState" : "stale",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Get Code"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "获取授权吗"
}
}
}
},
"onboardingEpicGamesLoginStepView.loading" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -42882,6 +42923,9 @@
}
}
}
},
"Settings!" : {

},
"Show in Finder" : {
"localizations" : {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Views/Components/GenericWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ public struct GenericWebView: View {
Label("genericWebView.retry", systemImage: "arrow.clockwise")
.padding(6)
.multilineTextAlignment(.center)
.frame(maxWidth: .infinity)
}
}
.padding(32)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
.background(.ultraThinMaterial)
}
Expand Down
37 changes: 23 additions & 14 deletions Sources/Views/Onboarding/OnboardingEpicGamesLoginStepView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,31 @@ public struct OnboardingEpicGamesLoginStepView: View {
let authorizationCode: String
}

URLSession.shared.dataTask(with: url) { data, response, error in
guard let data = data, let string = String(data: data, encoding: .utf8) else {
action(true)
return
}
webView.configuration.websiteDataStore.httpCookieStore.getAllCookies { cookies in
let epicGamesCookies = cookies.filter { $0.domain == ".epicgames.com" }
let cookiesString = epicGamesCookies.map { "\($0.name)=\($0.value)" }.joined(separator: "; ")

let decoder = JSONDecoder()
guard let jsonData = string.data(using: .utf8),
let json = try? decoder.decode(JSONData.self, from: jsonData) else {
action(true)
return
}
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue(cookiesString, forHTTPHeaderField: "Cookie")

URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data, let string = String(data: data, encoding: .utf8) else {
action(true)
return
}

let decoder = JSONDecoder()
guard let jsonData = string.data(using: .utf8),
let json = try? decoder.decode(JSONData.self, from: jsonData) else {
action(true)
return
}

self.onAuthorizationCode(json.authorizationCode)
action(true)
}.resume()
self.onAuthorizationCode(json.authorizationCode)
action(true)
}.resume()
}
return
}

Expand Down

0 comments on commit 98f7f2e

Please sign in to comment.