Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mobile): 无法重载时拒绝切换服务器环境

DavidShenea2cdcac4fe9
diff --git a/apps/mobile/app/settings.tsx b/apps/mobile/app/settings.tsx
index 62ec02ebcc..f4ff258441 100644
--- a/apps/mobile/app/settings.tsx
+++ b/apps/mobile/app/settings.tsx
@@ -563,34 +563,28 @@ export default function SettingsScreen() {
) {
return;
}
+ const reload = __DEV__
+ ? () => DevSettings.reload()
+ : Updates.isEnabled
+ ? () => Updates.reloadAsync()
+ : null;
+ if (!reload) {
+ Alert.alert(
+ t('settings.devServerEnvironment.title'),
+ t('settings.devServerEnvironment.switchFailed'),
+ );
+ return;
+ }
setDevServerEnvironmentBusy(true);
try {
// 旧环境的 push 注销、token 与账号缓存必须先在旧端点仍生效时清理。
await auth.logout();
- if (__DEV__) {
- await switchDevServerEnvironmentAndReload({
- current: devServerEnvironment,
- next,
- reload: () => DevSettings.reload(),
- setEnvironment: setDevServerEnvironment,
- });
- return;
- }
- if (Updates.isEnabled) {
- await switchDevServerEnvironmentAndReload({
- current: devServerEnvironment,
- next,
- reload: () => Updates.reloadAsync(),
- setEnvironment: setDevServerEnvironment,
- });
- return;
- }
- await setDevServerEnvironment(next);
- router.replace('/login');
- Alert.alert(
- t('settings.devServerEnvironment.title'),
- t('settings.devServerEnvironment.restartRequired'),
- );
+ await switchDevServerEnvironmentAndReload({
+ current: devServerEnvironment,
+ next,
+ reload,
+ setEnvironment: setDevServerEnvironment,
+ });
} catch {
Alert.alert(
t('settings.devServerEnvironment.title'),
@@ -605,7 +599,6 @@ export default function SettingsScreen() {
devServerEnvironment,
devServerEnvironmentBusy,
devServerEnvironmentReady,
- router,
setDevServerEnvironment,
t,
],
diff --git a/apps/mobile/src/__tests__/mobileSettings.test.ts b/apps/mobile/src/__tests__/mobileSettings.test.ts
index 3c7fd0e40c..a39502bf7c 100644
--- a/apps/mobile/src/__tests__/mobileSettings.test.ts
+++ b/apps/mobile/src/__tests__/mobileSettings.test.ts
@@ -40,12 +40,16 @@ describe('mobile settings overview', () => {
'await auth.logout();',
switchStart,
);
+ const reloadUnavailableIndex = settingsSource.indexOf(
+ 'if (!reload) {',
+ switchStart,
+ );
const transactionalReloadIndex = settingsSource.indexOf(
'await switchDevServerEnvironmentAndReload({',
switchStart,
);
const reloadIndex = settingsSource.indexOf(
- 'reload: () => DevSettings.reload(),',
+ '? () => DevSettings.reload()',
switchStart,
);
@@ -60,9 +64,15 @@ describe('mobile settings overview', () => {
);
expect(environmentSource).not.toContain('TextInput');
expect(switchStart).toBeGreaterThan(-1);
+ expect(reloadUnavailableIndex).toBeGreaterThan(switchStart);
+ expect(reloadUnavailableIndex).toBeLessThan(logoutIndex);
expect(logoutIndex).toBeGreaterThan(switchStart);
expect(transactionalReloadIndex).toBeGreaterThan(logoutIndex);
- expect(reloadIndex).toBeGreaterThan(transactionalReloadIndex);
+ expect(reloadIndex).toBeGreaterThan(switchStart);
+ expect(reloadIndex).toBeLessThan(reloadUnavailableIndex);
+ expect(settingsSource).not.toContain(
+ 'settings.devServerEnvironment.restartRequired',
+ );
});
it('keeps the device-link hello name and settings device name on one source', () => {
diff --git a/apps/mobile/src/i18n/locales/en/settings.json b/apps/mobile/src/i18n/locales/en/settings.json
index 71b8be5249..058a091d3b 100644
--- a/apps/mobile/src/i18n/locales/en/settings.json
+++ b/apps/mobile/src/i18n/locales/en/settings.json
@@ -98,7 +98,6 @@
"cancel": "Cancel",
"switchAction": "Switch",
"switching": "Switching",
- "restartRequired": "The server environment has changed. Fully quit and reopen the app.",
"switchFailed": "Could not switch the server environment. Try again."
},
"updateInfo": {
diff --git a/apps/mobile/src/i18n/locales/ja/settings.json b/apps/mobile/src/i18n/locales/ja/settings.json
index 5582ac553f..274eda6f7c 100644
--- a/apps/mobile/src/i18n/locales/ja/settings.json
+++ b/apps/mobile/src/i18n/locales/ja/settings.json
@@ -98,7 +98,6 @@
"cancel": "キャンセル",
"switchAction": "切り替える",
"switching": "切り替え中",
- "restartRequired": "サーバー環境を切り替えました。App を完全に終了してから再度開いてください。",
"switchFailed": "サーバー環境を切り替えられませんでした。もう一度お試しください。"
},
"updateInfo": {
diff --git a/apps/mobile/src/i18n/locales/ko/settings.json b/apps/mobile/src/i18n/locales/ko/settings.json
index 0f52ff3023..65531d7ce6 100644
--- a/apps/mobile/src/i18n/locales/ko/settings.json
+++ b/apps/mobile/src/i18n/locales/ko/settings.json
@@ -98,7 +98,6 @@
"cancel": "취소",
"switchAction": "전환",
"switching": "전환 중",
- "restartRequired": "서버 환경을 전환했습니다. App을 완전히 종료한 후 다시 열어 주세요.",
"switchFailed": "서버 환경을 전환하지 못했습니다. 다시 시도해 주세요."
},
"updateInfo": {
diff --git a/apps/mobile/src/i18n/locales/zh-CN/settings.json b/apps/mobile/src/i18n/locales/zh-CN/settings.json
index b4a95a970e..5ae5a8e42d 100644
--- a/apps/mobile/src/i18n/locales/zh-CN/settings.json
+++ b/apps/mobile/src/i18n/locales/zh-CN/settings.json
@@ -98,7 +98,6 @@
"cancel": "取消",
"switchAction": "切换",
"switching": "切换中",
- "restartRequired": "服务器环境已切换。请完全退出 App 后重新打开。",
"switchFailed": "切换服务器环境失败,请重试。"
},
"updateInfo": {
diff --git a/apps/mobile/src/i18n/locales/zh-TW/settings.json b/apps/mobile/src/i18n/locales/zh-TW/settings.json
index e14da59a7a..78a9837d34 100644
--- a/apps/mobile/src/i18n/locales/zh-TW/settings.json
+++ b/apps/mobile/src/i18n/locales/zh-TW/settings.json
@@ -98,7 +98,6 @@
"cancel": "取消",
"switchAction": "切換",
"switching": "切換中",
- "restartRequired": "伺服器環境已切換。請完全結束 App 後重新開啟。",
"switchFailed": "切換伺服器環境失敗,請再試一次。"
},
"updateInfo": {