Skip to content

Commit

Permalink
Customizable useragent (workaround for MajsoulPlus#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtakingiteasy committed Jul 2, 2021
1 parent 38a9249 commit 10d1629
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions i18n/en-US/manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"useHttpServer": "User http server(avoid certificate error)",
"serverToPlay": "Server to play (0 is China server, 1 is Japan server, 2 is America server)",
"proxyUrl": "Proxy server address (leave it empty if you don't want to use it)",
"userAgent": "Useragent",
"userLibPath": "'User Library' Path",
"localVersion": "Version",
"isManagerHide": "Re-open the launcher when the game quit",
Expand Down
1 change: 1 addition & 0 deletions i18n/ja-JP/manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"useHttpServer": "http サービスを使用する(証明書エラーがない)",
"serverToPlay": "ゲームサーバー(0は中国サーバー、1は日本サーバー、2は米国サーバー)",
"proxyUrl": "プロキシサーバーアドレス(プロキシを使用しない場合は空白のままにします)",
"userAgent": "ユーザーエージェント",
"userLibPath": "ユーザライブラリディレクトリ",
"localVersion": "バージョン",
"isManagerHide": "ゲーム終了後、管理画面に戻る",
Expand Down
1 change: 1 addition & 0 deletions i18n/ko/manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"useHttpServer": "\uc0ac\uc6a9\uc790 HTTP \uc11c\ubc84(\uc778\uc99d\uc11c \uc624\ub958 \ud68c\ud53c)",
"serverToPlay": "\ud50c\ub808\uc774\ud560 \uc11c\ubc84 (0 : \uc911\uad6d \uc11c\ubc84, 1 : \uc77c\ubcf8 \uc11c\ubc84, 2 : \ubbf8\uad6d \uc11c\ubc84)",
"proxyUrl": "\ud504\ub85d\uc2dc \uc11c\ubc84 \uc8fc\uc18c (\uc0ac\uc6a9\ud558\uc9c0 \uc54a\uc73c\ub824\uba74 \ube48\uce78\uc73c\ub85c \ub458 \uac83)",
"userAgent": "\uc0ac\uc6a9\uc790\u0020\uc5d0\uc774\uc804\ud2b8",
"userLibPath": "'\uc0ac\uc6a9\uc790 \ub77c\uc774\ube0c\ub7ec\ub9ac' \uacbd\ub85c",
"localVersion": "\ubc84\uc804",
"isManagerHide": "\uac8c\uc784 \uc885\ub8cc \ud6c4 \ub7f0\ucc98 \uc7ac\uc2e4\ud589",
Expand Down
1 change: 1 addition & 0 deletions i18n/zh-CN/manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"useHttpServer": "使用 http 服务器(不存在证书错误)",
"serverToPlay": "游戏服务器(0为国服,1为日服,2为美服)",
"proxyUrl": "代理服务器地址(留空为不使用代理)",
"userAgent": "用户代理",
"userLibPath": "用户库目录",
"localVersion": "版本",
"isManagerHide": "退出游戏后回到管理器界面",
Expand Down
1 change: 1 addition & 0 deletions i18n/zh-TW/manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"useHttpServer": "\u4f7f\u7528 http \u670d\u52d9\u5668\uff08\u4e0d\u5b58\u5728\u8b49\u66f8\u932f\u8aa4\uff09",
"serverToPlay": "\u904a\u6232\u4f3a\u670d\u5668\uff080\u70ba\u570b\u4f3a\uff0c1\u70ba\u65e5\u4f3a\uff0c2\u70ba\u7f8e\u4f3a\uff09",
"proxyUrl": "\u4ee3\u7406\u4f3a\u670d\u5668\u5730\u5740\uff08\u7559\u7a7a\u70ba\u4e0d\u4f7f\u7528\u4ee3\u7406\uff09",
"userAgent": "\u7528\u6236\u4ee3\u7406",
"userLibPath": "\u8cc7\u6599\u593e\u76ee\u9304",
"localVersion": "\u7248\u672c",
"isManagerHide": "\u9000\u51fa\u904a\u6232\u5f8c\uff0c\u8fd4\u56de\u6a94\u6848\u7e3d\u7ba1",
Expand Down
5 changes: 4 additions & 1 deletion src/bin/main/mainLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ function getLocalUrlWithParams(url: string) {
function redirectGameWindow(url: string, gameWindow: Electron.WebviewTag) {
const localUrl = getLocalUrlWithParams(url)
console.log('[Majsoul Plus] Redirect Target:' + localUrl)
gameWindow.loadURL(localUrl)

gameWindow.loadURL(localUrl, {userAgent: navigator.userAgent})
}

function scaleWindow(percent = scalePercent) {
Expand Down Expand Up @@ -152,6 +153,8 @@ ipcRenderer.on(
if (partition) {
mainWindow.partition = partition
}

mainWindow.useragent = navigator.userAgent
mainWindow.src = url
mainWindowBox.style.width = '100vw'
mainWindowBox.style.height = '100vh'
Expand Down
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const defaultWindowConfig: MajsoulPlus.UserWindowConfig = {
renderingMultiple: 100,
isKioskModeOn: false,
isNoBorder: false,
isManagerHide: false
isManagerHide: false,
userAgent: Global.HttpGetUserAgent
}

const defaultUpdateConfig: MajsoulPlus.UserUpdateConfig = {
Expand Down
1 change: 1 addition & 0 deletions src/majsoul_plus.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ declare namespace MajsoulPlus {
isKioskModeOn: boolean
isNoBorder: boolean
isManagerHide: boolean
userAgent: string
}

export interface UserUpdateConfig {
Expand Down
2 changes: 1 addition & 1 deletion src/manager/pages/Setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Setting {
index
}),
string: () => {
if (item === 'proxyUrl') {
if (item === 'proxyUrl' || item === 'userAgent') {
this.renderTextSectionItem({
settingInner,
section,
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export async function getRemoteSource(
const remoteUrl = getRemoteUrl(url)
const resp = await fetch(remoteUrl, {
headers: {
'User-Agent': Global.HttpGetUserAgent
'User-Agent': UserConfigs.window.userAgent
}
})

Expand Down Expand Up @@ -261,7 +261,7 @@ export async function getRemoteOrCachedFile(
export async function fetchAnySite(url: string, encoding = 'binary') {
const resp = await fetch(url, {
headers: {
'User-Agent': Global.HttpGetUserAgent
'User-Agent': UserConfigs.window.userAgent
}
})
return (await resp.buffer()).toString(encoding)
Expand Down
5 changes: 3 additions & 2 deletions src/windows/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,12 @@ export function newGameWindow(id: number) {
window.show()
})


// 设置 GameWindow 的 userAgent
window.webContents.userAgent = Global.HttpGetUserAgent
window.webContents.userAgent = UserConfigs.window.userAgent

// 载入本地启动器
window.loadURL('file://' + path.join(__dirname, '../bin/main/index.html'))
window.loadURL('file://' + path.join(__dirname, '../bin/main/index.html'), {userAgent: UserConfigs.window.userAgent})

// 在 debug 启动环境下打开开发者工具
if (process.env.NODE_ENV === 'development') {
Expand Down

0 comments on commit 10d1629

Please sign in to comment.