atm-droid 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands.js +14 -2
- package/src/config.js +6 -5
- package/src/daemon.js +2 -2
- package/src/menu.js +2 -2
package/package.json
CHANGED
package/src/commands.js
CHANGED
|
@@ -33,6 +33,18 @@ async function login(code) {
|
|
|
33
33
|
console.log(chalk.cyan(' 自动切换: 已启用'));
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
// 自动启动后台服务
|
|
37
|
+
const daemonStatus = daemon.getDaemonStatus();
|
|
38
|
+
if (!daemonStatus.running) {
|
|
39
|
+
console.log(chalk.gray(' 正在启动后台服务...'));
|
|
40
|
+
const { spawn } = require('child_process');
|
|
41
|
+
const child = spawn(process.execPath, [
|
|
42
|
+
path.join(__dirname, 'daemon-runner.js')
|
|
43
|
+
], { detached: true, stdio: 'ignore' });
|
|
44
|
+
child.unref();
|
|
45
|
+
console.log(chalk.green(' ✓ 后台服务已启动'));
|
|
46
|
+
}
|
|
47
|
+
|
|
36
48
|
console.log(chalk.yellow('\n 提示: 使用 atm list 查看账号列表'));
|
|
37
49
|
} else {
|
|
38
50
|
spinner.fail(chalk.red('激活失败: ' + (result.error || '未知错误')));
|
|
@@ -173,7 +185,7 @@ async function switchToken(index) {
|
|
|
173
185
|
if (activateResult.success) {
|
|
174
186
|
// 写入 auth.json
|
|
175
187
|
if (activateResult.access_token && activateResult.refresh_token) {
|
|
176
|
-
writeFactoryAuth(activateResult.access_token, activateResult.refresh_token);
|
|
188
|
+
writeFactoryAuth(activateResult.access_token, activateResult.refresh_token, targetToken.id);
|
|
177
189
|
config.set('currentTokenId', targetToken.id);
|
|
178
190
|
|
|
179
191
|
switchSpinner.succeed(chalk.green(`已切换到 ${targetToken.email}`));
|
|
@@ -349,7 +361,7 @@ async function check() {
|
|
|
349
361
|
const activateResult = await api.activateToken(target.id);
|
|
350
362
|
|
|
351
363
|
if (activateResult.success && activateResult.access_token) {
|
|
352
|
-
writeFactoryAuth(activateResult.access_token, activateResult.refresh_token);
|
|
364
|
+
writeFactoryAuth(activateResult.access_token, activateResult.refresh_token, target.id);
|
|
353
365
|
config.set('currentTokenId', target.id);
|
|
354
366
|
spinner.succeed(chalk.green(`已自动切换到 ${target.email}`));
|
|
355
367
|
} else {
|
package/src/config.js
CHANGED
|
@@ -42,14 +42,15 @@ function readFactoryAuth() {
|
|
|
42
42
|
return null;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
// 写入 Factory auth.json
|
|
46
|
-
function writeFactoryAuth(accessToken, refreshToken) {
|
|
45
|
+
// 写入 Factory auth.json (格式与 Tauri 客户端一致)
|
|
46
|
+
function writeFactoryAuth(accessToken, refreshToken, tokenId) {
|
|
47
47
|
ensureFactoryDir();
|
|
48
48
|
const authPath = getFactoryAuthPath();
|
|
49
49
|
const data = {
|
|
50
|
-
accessToken,
|
|
51
|
-
refreshToken,
|
|
52
|
-
|
|
50
|
+
access_token: accessToken,
|
|
51
|
+
refresh_token: refreshToken,
|
|
52
|
+
token_id: tokenId || null,
|
|
53
|
+
updated_at: Math.floor(Date.now() / 1000)
|
|
53
54
|
};
|
|
54
55
|
fs.writeFileSync(authPath, JSON.stringify(data, null, 2));
|
|
55
56
|
return true;
|
package/src/daemon.js
CHANGED
|
@@ -86,7 +86,7 @@ async function refreshCurrentToken() {
|
|
|
86
86
|
|
|
87
87
|
const result = await api.activateToken(currentTokenId);
|
|
88
88
|
if (result.success && result.access_token && result.refresh_token) {
|
|
89
|
-
writeFactoryAuth(result.access_token, result.refresh_token);
|
|
89
|
+
writeFactoryAuth(result.access_token, result.refresh_token, currentTokenId);
|
|
90
90
|
log(`Token 已更新: ${currentTokenId}`);
|
|
91
91
|
}
|
|
92
92
|
} catch (e) {
|
|
@@ -121,7 +121,7 @@ async function autoSwitch() {
|
|
|
121
121
|
|
|
122
122
|
if (activateResult.success) {
|
|
123
123
|
config.set('currentTokenId', target.id);
|
|
124
|
-
writeFactoryAuth(activateResult.access_token, activateResult.refresh_token);
|
|
124
|
+
writeFactoryAuth(activateResult.access_token, activateResult.refresh_token, target.id);
|
|
125
125
|
log(`自动切换到: ${target.email}`);
|
|
126
126
|
}
|
|
127
127
|
} else {
|
package/src/menu.js
CHANGED
|
@@ -246,7 +246,7 @@ async function doSwitch() {
|
|
|
246
246
|
const activateResult = await api.activateToken(selected.id);
|
|
247
247
|
|
|
248
248
|
if (activateResult.success && activateResult.access_token) {
|
|
249
|
-
writeFactoryAuth(activateResult.access_token, activateResult.refresh_token);
|
|
249
|
+
writeFactoryAuth(activateResult.access_token, activateResult.refresh_token, selected.id);
|
|
250
250
|
config.set('currentTokenId', selected.id);
|
|
251
251
|
|
|
252
252
|
console.log(chalk.green(` ✓ 已切换到 ${selected.email}`));
|
|
@@ -316,7 +316,7 @@ async function doCheck() {
|
|
|
316
316
|
const activateResult = await api.activateToken(target.id);
|
|
317
317
|
|
|
318
318
|
if (activateResult.success && activateResult.access_token) {
|
|
319
|
-
writeFactoryAuth(activateResult.access_token, activateResult.refresh_token);
|
|
319
|
+
writeFactoryAuth(activateResult.access_token, activateResult.refresh_token, target.id);
|
|
320
320
|
config.set('currentTokenId', target.id);
|
|
321
321
|
console.log(chalk.green(` ✓ 已自动切换到 ${target.email}`));
|
|
322
322
|
} else {
|