Skip to content

Commit 132b937

Browse files
authored
fix: Use more robust method for creating the Welcome workspace (#176)
1 parent e55f903 commit 132b937

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

backend/src/commands/workspaces.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ use tauri::{ipc::Channel, path::BaseDirectory, AppHandle, Manager, State};
66
use crate::{
77
state::AtuinState,
88
workspaces::{
9-
fs_ops::WorkspaceDirInfo, manager::WorkspaceEvent, offline_runbook::OfflineRunbook,
9+
fs_ops::{WorkspaceConfig, WorkspaceDirInfo},
10+
manager::WorkspaceEvent,
11+
offline_runbook::OfflineRunbook,
1012
workspace::WorkspaceError,
1113
},
1214
};
1315

1416
#[tauri::command]
15-
pub async fn copy_welcome_workspace(app: AppHandle) -> Result<String, String> {
17+
pub async fn copy_welcome_workspace(app: AppHandle, id: String) -> Result<String, String> {
1618
let welcome_path = app
1719
.path()
1820
.resolve("resources/welcome", BaseDirectory::Resource)
@@ -39,6 +41,17 @@ pub async fn copy_welcome_workspace(app: AppHandle) -> Result<String, String> {
3941

4042
copy_dir_all(&welcome_path, &target_path).map_err(|e| e.to_string())?;
4143

44+
// Overwrite the ID in the copied `atuin.toml` file with the given ID
45+
let config_path = target_path.join("atuin.toml");
46+
let mut config = WorkspaceConfig::from_file(&config_path)
47+
.await
48+
.map_err(|e| e.to_string())?;
49+
config.workspace.id = id;
50+
let contents = toml::to_string(&config).map_err(|e| e.to_string())?;
51+
tokio::fs::write(config_path, contents)
52+
.await
53+
.map_err(|e| e.to_string())?;
54+
4255
Ok(target_path.to_string_lossy().to_string())
4356
}
4457

src/lib/workspace_setup.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { AtuinSharedStateAdapter } from "./shared_state/adapter";
1010
import { uuidv7 } from "uuidv7";
1111
import Logger from "./logger";
1212
import { Rc } from "@binarymuse/ts-stdlib";
13-
import { createWorkspace } from "./workspaces/commands";
1413
import { TabIcon } from "@/state/store/ui_state";
1514
import { invoke } from "@tauri-apps/api/core";
1615
import { DialogBuilder } from "@/components/Dialogs/dialog";
@@ -57,8 +56,9 @@ export default async function doWorkspaceSetup(): Promise<void> {
5756
logger.info("Unable to fetch workspaces from server; creating default workspace");
5857

5958
let workspacePath: string | null = null;
59+
let welcomeWorkspaceId = uuidv7();
6060
try {
61-
workspacePath = await invoke<string>("copy_welcome_workspace");
61+
workspacePath = await invoke<string>("copy_welcome_workspace", { id: welcomeWorkspaceId });
6262
} catch (err) {
6363
await new DialogBuilder()
6464
.title("Failed to create welcome workspace")
@@ -72,14 +72,12 @@ export default async function doWorkspaceSetup(): Promise<void> {
7272
}
7373

7474
let name = "Welcome to Atuin";
75-
let id = uuidv7();
7675
workspace = new Workspace({
77-
id: id,
76+
id: welcomeWorkspaceId,
7877
name: name,
7978
folder: workspacePath,
8079
online: 0,
8180
});
82-
await createWorkspace(workspacePath, id, name);
8381
await workspace.save();
8482
}
8583

0 commit comments

Comments
 (0)