Skip to content

Commit 33f05c6

Browse files
authored
Update data and config paths to match platform defaults (#1047)
Going forward for new installations, config and data files will be stored at the platform default paths, as defined by [env-paths](https://www.npmjs.com/package/env-paths). For backwards compatibility, if the `~/.waveterm` or `WAVETERM_HOME` directory exists and contains valid data, it will be used. If this check fails, then `WAVETERM_DATA_HOME` and `WAVETERM_CONFIG_HOME` will be used. If these are not defined, then `XDG_DATA_HOME` and `XDG_CONFIG_HOME` will be used. Finally, if none of these are defined, the [env-paths](https://www.npmjs.com/package/env-paths) defaults will be used. As with the existing app, dev instances will write to `waveterm-dev` directories, while all others will write to `waveterm`.
1 parent 39fff9e commit 33f05c6

26 files changed

+241
-105
lines changed

Taskfile.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ tasks:
184184
generate:
185185
desc: Generate Typescript bindings for the Go backend.
186186
cmds:
187-
- go run cmd/generatets/main-generatets.go
188-
- go run cmd/generatego/main-generatego.go
187+
- NO_PANIC=1 go run cmd/generatets/main-generatets.go
188+
- NO_PANIC=1 go run cmd/generatego/main-generatego.go
189189
sources:
190190
- "cmd/generatego/*.go"
191191
- "cmd/generatets/*.go"

cmd/server/main-server.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func main() {
182182
log.Printf("error validating service map: %v\n", err)
183183
return
184184
}
185-
err = wavebase.EnsureWaveHomeDir()
185+
err = wavebase.EnsureWaveDataDir()
186186
if err != nil {
187187
log.Printf("error ensuring wave home dir: %v\n", err)
188188
return
@@ -192,14 +192,14 @@ func main() {
192192
log.Printf("error ensuring wave db dir: %v\n", err)
193193
return
194194
}
195-
err = wconfig.EnsureWaveConfigDir()
195+
err = wavebase.EnsureWaveConfigDir()
196196
if err != nil {
197197
log.Printf("error ensuring wave config dir: %v\n", err)
198198
return
199199
}
200200

201201
// TODO: rather than ensure this dir exists, we should let the editor recursively create parent dirs on save
202-
err = wconfig.EnsureWavePresetsDir()
202+
err = wavebase.EnsureWavePresetsDir()
203203
if err != nil {
204204
log.Printf("error ensuring wave presets dir: %v\n", err)
205205
return
@@ -216,7 +216,8 @@ func main() {
216216
}
217217
}()
218218
log.Printf("wave version: %s (%s)\n", WaveVersion, BuildTime)
219-
log.Printf("wave home dir: %s\n", wavebase.GetWaveHomeDir())
219+
log.Printf("wave data dir: %s\n", wavebase.GetWaveDataDir())
220+
log.Printf("wave config dir: %s\n", wavebase.GetWaveConfigDir())
220221
err = filestore.InitFilestore()
221222
if err != nil {
222223
log.Printf("error initializing filestore: %v\n", err)

emain/docsite.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { getWebServerEndpoint } from "@/util/endpoints";
2-
import { fetch } from "@/util/fetchutil";
31
import { ipcMain } from "electron";
2+
import { getWebServerEndpoint } from "../frontend/util/endpoints";
3+
import { fetch } from "../frontend/util/fetchutil";
44

55
const docsiteWebUrl = "https://docs.waveterm.dev/";
66
let docsiteUrl: string;

emain/emain-viewmgr.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
// Copyright 2024, Command Line Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { ClientService, FileService, ObjectService, WindowService } from "@/app/store/services";
54
import * as electron from "electron";
5+
import * as path from "path";
6+
import { debounce } from "throttle-debounce";
7+
import { ClientService, FileService, ObjectService, WindowService } from "../frontend/app/store/services";
8+
import * as keyutil from "../frontend/util/keyutil";
9+
import { configureAuthKeyRequestInjection } from "./authkey";
10+
import { getGlobalIsQuitting, getGlobalIsStarting, setWasActive, setWasInFg } from "./emain-activity";
611
import {
712
delay,
813
ensureBoundsAreVisible,
914
handleCtrlShiftFocus,
1015
handleCtrlShiftState,
1116
shFrameNavHandler,
1217
shNavHandler,
13-
} from "emain/emain-util";
14-
import * as keyutil from "frontend/util/keyutil";
15-
import * as path from "path";
16-
import { debounce } from "throttle-debounce";
17-
import { configureAuthKeyRequestInjection } from "./authkey";
18-
import { getGlobalIsQuitting, getGlobalIsStarting, setWasActive, setWasInFg } from "./emain-activity";
18+
} from "./emain-util";
1919
import { getElectronAppBasePath, isDevVite } from "./platform";
2020
import { updater } from "./updater";
2121

emain/emain-wavesrv.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
// Copyright 2024, Command Line Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { WebServerEndpointVarName, WSServerEndpointVarName } from "@/util/endpoints";
54
import * as electron from "electron";
6-
import { AuthKey, AuthKeyEnv } from "emain/authkey";
7-
import { setForceQuit } from "emain/emain-activity";
8-
import { WaveAppPathVarName } from "emain/emain-util";
9-
import { getElectronAppUnpackedBasePath, getWaveSrvCwd, getWaveSrvPath } from "emain/platform";
10-
import { updater } from "emain/updater";
115
import * as child_process from "node:child_process";
126
import * as readline from "readline";
7+
import { WebServerEndpointVarName, WSServerEndpointVarName } from "../frontend/util/endpoints";
8+
import { AuthKey, AuthKeyEnv } from "./authkey";
9+
import { setForceQuit } from "./emain-activity";
10+
import { WaveAppPathVarName } from "./emain-util";
11+
import {
12+
getElectronAppUnpackedBasePath,
13+
getWaveConfigDir,
14+
getWaveDataDir,
15+
getWaveSrvCwd,
16+
getWaveSrvPath,
17+
WaveConfigHomeVarName,
18+
WaveDataHomeVarName,
19+
} from "./platform";
20+
import { updater } from "./updater";
1321

1422
export const WaveSrvReadySignalPidVarName = "WAVETERM_READY_SIGNAL_PID";
1523

@@ -50,6 +58,8 @@ export function runWaveSrv(handleWSEvent: (evtMsg: WSEventType) => void): Promis
5058
envCopy[WaveAppPathVarName] = getElectronAppUnpackedBasePath();
5159
envCopy[WaveSrvReadySignalPidVarName] = process.pid.toString();
5260
envCopy[AuthKeyEnv] = AuthKey;
61+
envCopy[WaveDataHomeVarName] = getWaveDataDir();
62+
envCopy[WaveConfigHomeVarName] = getWaveConfigDir();
5363
const waveSrvCmd = getWaveSrvPath();
5464
console.log("trying to run local server", waveSrvCmd);
5565
const proc = child_process.spawn(getWaveSrvPath(), {

emain/emain-wsh.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { Notification } from "electron";
5-
import { getWaveWindowById } from "emain/emain-viewmgr";
65
import { RpcResponseHelper, WshClient } from "../frontend/app/store/wshclient";
6+
import { getWaveWindowById } from "./emain-viewmgr";
77
import { getWebContentsByBlockId, webGetSelector } from "./emain-web";
88

99
export class ElectronWshClientType extends WshClient {

emain/emain.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import * as electron from "electron";
5+
import { FastAverageColor } from "fast-average-color";
6+
import fs from "fs";
7+
import * as child_process from "node:child_process";
8+
import * as path from "path";
9+
import { PNG } from "pngjs";
10+
import { sprintf } from "sprintf-js";
11+
import { Readable } from "stream";
12+
import * as util from "util";
13+
import winston from "winston";
14+
import * as services from "../frontend/app/store/services";
15+
import { initElectronWshrpc, shutdownWshrpc } from "../frontend/app/store/wshrpcutil";
16+
import { getWebServerEndpoint } from "../frontend/util/endpoints";
17+
import { fetch } from "../frontend/util/fetchutil";
18+
import * as keyutil from "../frontend/util/keyutil";
19+
import { fireAndForget } from "../frontend/util/util";
20+
import { AuthKey, configureAuthKeyRequestInjection } from "./authkey";
21+
import { initDocsite } from "./docsite";
522
import {
623
getActivityState,
724
getForceQuit,
@@ -12,8 +29,8 @@ import {
1229
setGlobalIsStarting,
1330
setWasActive,
1431
setWasInFg,
15-
} from "emain/emain-activity";
16-
import { handleCtrlShiftState } from "emain/emain-util";
32+
} from "./emain-activity";
33+
import { handleCtrlShiftState } from "./emain-util";
1734
import {
1835
createBrowserWindow,
1936
ensureHotSpareTab,
@@ -25,32 +42,16 @@ import {
2542
getWaveWindowByWebContentsId,
2643
setActiveTab,
2744
setMaxTabCacheSize,
28-
} from "emain/emain-viewmgr";
29-
import { getIsWaveSrvDead, getWaveSrvProc, getWaveSrvReady, getWaveVersion, runWaveSrv } from "emain/emain-wavesrv";
30-
import { FastAverageColor } from "fast-average-color";
31-
import fs from "fs";
32-
import * as child_process from "node:child_process";
33-
import * as path from "path";
34-
import { PNG } from "pngjs";
35-
import { sprintf } from "sprintf-js";
36-
import { Readable } from "stream";
37-
import * as util from "util";
38-
import winston from "winston";
39-
import * as services from "../frontend/app/store/services";
40-
import { initElectronWshrpc, shutdownWshrpc } from "../frontend/app/store/wshrpcutil";
41-
import { getWebServerEndpoint } from "../frontend/util/endpoints";
42-
import { fetch } from "../frontend/util/fetchutil";
43-
import * as keyutil from "../frontend/util/keyutil";
44-
import { fireAndForget } from "../frontend/util/util";
45-
import { AuthKey, configureAuthKeyRequestInjection } from "./authkey";
46-
import { initDocsite } from "./docsite";
45+
} from "./emain-viewmgr";
46+
import { getIsWaveSrvDead, getWaveSrvProc, getWaveSrvReady, getWaveVersion, runWaveSrv } from "./emain-wavesrv";
4747
import { ElectronWshClient, initElectronWshClient } from "./emain-wsh";
4848
import { getLaunchSettings } from "./launchsettings";
4949
import { getAppMenu } from "./menu";
5050
import {
5151
getElectronAppBasePath,
5252
getElectronAppUnpackedBasePath,
53-
getWaveHomeDir,
53+
getWaveConfigDir,
54+
getWaveDataDir,
5455
isDev,
5556
unameArch,
5657
unamePlatform,
@@ -59,15 +60,17 @@ import { configureAutoUpdater, updater } from "./updater";
5960

6061
const electronApp = electron.app;
6162

63+
const waveDataDir = getWaveDataDir();
64+
const waveConfigDir = getWaveConfigDir();
65+
6266
electron.nativeTheme.themeSource = "dark";
6367

6468
let webviewFocusId: number = null; // set to the getWebContentsId of the webview that has focus (null if not focused)
6569
let webviewKeys: string[] = []; // the keys to trap when webview has focus
66-
const waveHome = getWaveHomeDir();
6770
const oldConsoleLog = console.log;
6871

6972
const loggerTransports: winston.transport[] = [
70-
new winston.transports.File({ filename: path.join(getWaveHomeDir(), "waveapp.log"), level: "info" }),
73+
new winston.transports.File({ filename: path.join(waveDataDir, "waveapp.log"), level: "info" }),
7174
];
7275
if (isDev) {
7376
loggerTransports.push(new winston.transports.Console());
@@ -91,8 +94,9 @@ function log(...msg: any[]) {
9194
console.log = log;
9295
console.log(
9396
sprintf(
94-
"waveterm-app starting, WAVETERM_HOME=%s, electronpath=%s gopath=%s arch=%s/%s",
95-
waveHome,
97+
"waveterm-app starting, data_dir=%s, config_dir=%s electronpath=%s gopath=%s arch=%s/%s",
98+
waveDataDir,
99+
waveConfigDir,
96100
getElectronAppBasePath(),
97101
getElectronAppUnpackedBasePath(),
98102
unamePlatform,
@@ -676,10 +680,6 @@ async function appMain() {
676680
electronApp.quit();
677681
return;
678682
}
679-
const waveHomeDir = getWaveHomeDir();
680-
if (!fs.existsSync(waveHomeDir)) {
681-
fs.mkdirSync(waveHomeDir);
682-
}
683683
makeAppMenu();
684684
try {
685685
await runWaveSrv(handleWSEvent);

emain/launchsettings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import fs from "fs";
22
import path from "path";
3-
import { getWaveHomeDir } from "./platform";
3+
import { getWaveConfigDir } from "./platform";
44

55
/**
66
* Get settings directly from the Wave Home directory on launch.
77
* Only use this when the app is first starting up. Otherwise, prefer the settings.GetFullConfig function.
88
* @returns The initial launch settings for the application.
99
*/
1010
export function getLaunchSettings(): SettingsType {
11-
const settingsPath = path.join(getWaveHomeDir(), "config", "settings.json");
11+
const settingsPath = path.join(getWaveConfigDir(), "settings.json");
1212
try {
1313
const settingsContents = fs.readFileSync(settingsPath, "utf8");
1414
return JSON.parse(settingsContents);

emain/menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import * as electron from "electron";
5-
import { clearTabCache, getFocusedWaveWindow } from "emain/emain-viewmgr";
65
import { fireAndForget } from "../frontend/util/util";
6+
import { clearTabCache, getFocusedWaveWindow } from "./emain-viewmgr";
77
import { unamePlatform } from "./platform";
88
import { updater } from "./updater";
99

0 commit comments

Comments
 (0)