Skip to content

Commit 3f9bed3

Browse files
authored
fix: Add fallback logic for finding appropriate welcome workspace directory if no documents directory is set (atuinsh#42)
* fix: Add fallback logic for finding appropriate welcome workspace directory * Continue booting app if welcome workspace can't be written
1 parent 5c64aa8 commit 3f9bed3

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

backend/src/commands/workspaces.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ pub async fn copy_welcome_workspace(app: AppHandle) -> Result<String, String> {
1818
.resolve("resources/welcome", BaseDirectory::Resource)
1919
.map_err(|e| e.to_string())?;
2020

21-
let documents_path = app.path().document_dir().map_err(|e| e.to_string())?;
21+
let documents_path = app
22+
.path()
23+
.document_dir()
24+
.or_else(|_| app.path().home_dir()) // possible for a linux system to have no document directory
25+
.or_else(|_| app.path().app_config_dir()) // can't imagine we'd ever have to fallback to here, but we know the dir works
26+
.map_err(|_| "Failed to locate a suitable directory for welcome workspace")?;
2227

2328
let mut target_path = documents_path
2429
.join("Atuin Runbooks")

src/lib/workspace_setup.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Rc } from "@binarymuse/ts-stdlib";
1313
import { createWorkspace } from "./workspaces/commands";
1414
import { TabIcon } from "@/state/store/ui_state";
1515
import { invoke } from "@tauri-apps/api/core";
16+
import { DialogBuilder } from "@/components/Dialogs/dialog";
1617

1718
const logger = new Logger("WorkspaceMigration");
1819

@@ -55,7 +56,20 @@ export default async function doWorkspaceSetup(): Promise<void> {
5556
} catch (err) {
5657
logger.info("Unable to fetch workspaces from server; creating default workspace");
5758

58-
const workspacePath = await invoke<string>("copy_welcome_workspace");
59+
let workspacePath: string | null = null;
60+
try {
61+
workspacePath = await invoke<string>("copy_welcome_workspace");
62+
} catch (err) {
63+
await new DialogBuilder()
64+
.title("Failed to create welcome workspace")
65+
.icon("error")
66+
.message(err as string)
67+
.action({ label: "OK", value: "ok", variant: "flat" })
68+
.build();
69+
70+
resolve?.();
71+
return;
72+
}
5973

6074
let name = "Welcome to Atuin";
6175
let id = uuidv7();

0 commit comments

Comments
 (0)