Use unique Tauri identifier per worktree for app data isolation

This commit is contained in:
Gregory Schier
2026-01-06 15:09:06 -08:00
parent 1f8fa0f8c3
commit 33afafd890
3 changed files with 17 additions and 23 deletions

3
.gitignore vendored
View File

@@ -37,3 +37,6 @@ tmp
.zed
codebook.toml
target
# Per-worktree Tauri config (generated by post-checkout hook)
src-tauri/tauri.worktree.conf.json

View File

@@ -98,14 +98,22 @@ YAAK_DEV_PORT=${maxDevPort}
# MCP Server port (main worktree uses 64343)
YAAK_PLUGIN_MCP_SERVER_PORT=${maxMcpPort}
# Database path prefix for worktree isolation
YAAK_DB_PATH_PREFIX=worktrees/${worktreeName}
`;
fs.writeFileSync(envLocalPath, envContent, 'utf8');
console.log(`Created .env.local with YAAK_DEV_PORT=${maxDevPort} and YAAK_PLUGIN_MCP_SERVER_PORT=${maxMcpPort}`);
// Create tauri.worktree.conf.json with unique app identifier for complete isolation
// This gives each worktree its own app data directory, avoiding the need for DB path prefixes
const tauriWorktreeConfig = {
identifier: `app.yaak.desktop.dev.${worktreeName}`,
productName: `Daak (${worktreeName})`
};
const tauriConfigPath = path.join(process.cwd(), 'src-tauri', 'tauri.worktree.conf.json');
fs.writeFileSync(tauriConfigPath, JSON.stringify(tauriWorktreeConfig, null, 2) + '\n', 'utf8');
console.log(`Created tauri.worktree.conf.json with identifier: ${tauriWorktreeConfig.identifier}`);
// Copy gitignored editor config folders from main worktree (.zed, .vscode, .claude, etc.)
// This ensures your editor settings, tasks, and configurations are available in the new worktree
// without needing to manually copy them or commit them to git.
@@ -148,12 +156,4 @@ try {
// Continue anyway
}
// Run npm run init to install dependencies and bootstrap
console.log('\nRunning npm run init to install dependencies and bootstrap...');
try {
execSync('npm run init', { stdio: 'inherit' });
console.log('\n✓ Worktree setup complete!');
} catch (err) {
console.error('\n✗ Failed to run npm run init. You may need to run it manually.');
process.exit(1);
}
console.log('\n✓ Worktree setup complete! Run `npm run init` to install dependencies.');

View File

@@ -51,17 +51,8 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
let app_path = app_handle.path().app_data_dir().unwrap();
create_dir_all(app_path.clone()).expect("Problem creating App directory!");
// Support per-worktree databases via YAAK_DB_PATH_PREFIX env var
let db_dir = match std::env::var("YAAK_DB_PATH_PREFIX") {
Ok(prefix) if !prefix.is_empty() => {
let dir = app_path.join(prefix);
create_dir_all(&dir).expect("Problem creating DB directory!");
dir
}
_ => app_path.clone(),
};
let db_file_path = db_dir.join("db.sqlite");
let blob_db_file_path = db_dir.join("blobs.sqlite");
let db_file_path = app_path.join("db.sqlite");
let blob_db_file_path = app_path.join("blobs.sqlite");
// Main database pool
let manager = SqliteConnectionManager::file(db_file_path);