@vincentbanana/banana-gui 1.0.5 → 1.0.7

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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  // 桌面版启动器:等价于 `banana-gui --desktop`,保留独立命令方便记忆。
3
3
  import { spawn, spawnSync } from 'node:child_process';
4
- import { existsSync, readFileSync } from 'node:fs';
4
+ import { existsSync, mkdirSync, readFileSync } from 'node:fs';
5
5
  import { createRequire } from 'node:module';
6
6
  import { dirname, join } from 'node:path';
7
7
  import { fileURLToPath } from 'node:url';
@@ -10,10 +10,18 @@ const here = dirname(fileURLToPath(import.meta.url));
10
10
  const require_ = createRequire(import.meta.url);
11
11
  const args = process.argv.slice(2);
12
12
 
13
- // 和数据目录保持一致:Electron 二进制缓存与运行数据都放 D 盘
13
+ // Electron 缓存优先放 D 盘;没有 D 盘或不可写就交给系统默认位置。
14
+ // BANANA_HOME 只在用户显式设置时生效,不在这里强制覆盖。
14
15
  if (process.platform === 'win32') {
15
- process.env.ELECTRON_CACHE ??= 'D:\\BananaCLI-data\\electron-cache';
16
- process.env.BANANA_HOME ??= 'D:\\BananaCLI-data';
16
+ try {
17
+ if (existsSync('D:\\')) {
18
+ const cache = join('D:\\BananaCLI-data', 'electron-cache');
19
+ mkdirSync(cache, { recursive: true });
20
+ process.env.ELECTRON_CACHE ??= cache;
21
+ }
22
+ } catch {
23
+ // 忽略,继续用默认缓存目录
24
+ }
17
25
  }
18
26
  if (args.includes('--help') || args.includes('-h')) {
19
27
  console.log('banana-gui-desktop — Banana 的桌面版(独立窗口)');
@@ -3,7 +3,7 @@
3
3
  // 安装:npm install -g @vincentbanana/banana-gui
4
4
  // 启动:banana-gui(首次会进配置向导)
5
5
  import { spawn, spawnSync } from 'node:child_process';
6
- import { existsSync, readFileSync } from 'node:fs';
6
+ import { existsSync, mkdirSync, readFileSync } from 'node:fs';
7
7
  import { createRequire } from 'node:module';
8
8
  import { dirname, join } from 'node:path';
9
9
  import { fileURLToPath } from 'node:url';
@@ -12,10 +12,18 @@ const require = createRequire(import.meta.url);
12
12
  const pkg = require('../package.json');
13
13
  const here = dirname(fileURLToPath(import.meta.url));
14
14
 
15
- // Electron 二进制和运行数据默认放 D 盘,避免往系统盘下载 / 写缓存
15
+ // Electron 缓存优先放 D 盘;没有 D 盘或不可写就交给系统默认位置。
16
+ // 不再强制 BANANA_HOME,避免没有 D 盘的机器保存不了配置和会话。
16
17
  if (process.platform === 'win32') {
17
- process.env.ELECTRON_CACHE ??= 'D:\\BananaCLI-data\\electron-cache';
18
- process.env.BANANA_HOME ??= 'D:\\BananaCLI-data';
18
+ try {
19
+ if (existsSync('D:\\')) {
20
+ const cache = join('D:\\BananaCLI-data', 'electron-cache');
21
+ mkdirSync(cache, { recursive: true });
22
+ process.env.ELECTRON_CACHE ??= cache;
23
+ }
24
+ } catch {
25
+ // 忽略,继续用默认缓存目录
26
+ }
19
27
  }
20
28
 
21
29
  /** CLI 内核入口。依赖可能被 npm 提升到上层 node_modules,用 require 解析更稳。 */
package/desktop/main.cjs CHANGED
@@ -4,11 +4,36 @@ const { app, BrowserWindow, Menu, shell, dialog, ipcMain, nativeTheme } = requir
4
4
  const { spawn, spawnSync } = require('node:child_process');
5
5
  const { createRequire } = require('node:module');
6
6
  const { join } = require('node:path');
7
+ const { homedir } = require('node:os');
7
8
  const { mkdirSync, writeFileSync } = require('node:fs');
8
9
 
9
- // 用户数据、Electron 缓存统一放 D 盘,不写系统盘
10
+ /** 优先用显式 BANANA_HOME,其次可写的 D 盘目录,最后回退到家目录。 */
11
+ function resolveDataRoot() {
12
+ const explicit = process.env.BANANA_HOME?.trim();
13
+ if (explicit) {
14
+ try {
15
+ mkdirSync(explicit, { recursive: true });
16
+ return explicit;
17
+ } catch {
18
+ // 显式目录不可写时继续尝试后面的位置
19
+ }
20
+ }
21
+ if (process.platform === 'win32') {
22
+ for (const candidate of ['D:\\BananaCLI-data', 'D:\\BananaData']) {
23
+ try {
24
+ mkdirSync(candidate, { recursive: true });
25
+ return candidate;
26
+ } catch {
27
+ // 没有 D 盘或没有写权限,试下一个
28
+ }
29
+ }
30
+ }
31
+ return join(homedir(), '.banana');
32
+ }
33
+
34
+ // 用户数据、Electron 缓存优先放 D 盘;没有 D 盘时回退到家目录。
10
35
  try {
11
- const dataRoot = process.env.BANANA_HOME || 'D:\\BananaCLI-data';
36
+ const dataRoot = resolveDataRoot();
12
37
  for (const [name, sub] of [['userData', 'electron'], ['sessionData', 'electron-session'], ['cache', 'cache']]) {
13
38
  const target = join(dataRoot, sub);
14
39
  mkdirSync(target, { recursive: true });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
- {
1
+ {
2
2
  "name": "@vincentbanana/banana-gui",
3
- "version": "1.0.5",
4
- "description": "Banana 的图形界面:本地服务 + 浏览器。黑白主题,自绘图标,无第三方 UI 依赖",
3
+ "version": "1.0.7",
4
+ "description": "Banana 鐨勫浘褰㈢晫闈細鏈湴鏈嶅姟 + 娴忚鍣ㄣ€傞粦鐧戒富棰橈紝鑷粯鍥炬爣锛屾棤绗笁鏂?UI 渚濊禆",
5
5
  "type": "module",
6
6
  "engines": {
7
7
  "node": ">=20.0.0"
@@ -72,7 +72,7 @@
72
72
  "electron-builder": "^25.0.0"
73
73
  },
74
74
  "dependencies": {
75
- "@vincentbanana/bananacli": "^0.8.5"
75
+ "@vincentbanana/bananacli": "^0.8.7"
76
76
  },
77
77
  "license": "MIT",
78
78
  "publishConfig": {