fix(workspace): preserve workspace name during migration to tidgi.config.json

- Fix issue where workspace names were lost when tidgi.config.json didn't exist
- Only remove syncable fields from settings.json if tidgi.config.json exists
- Add fallback to use folder name for workspaces without name field
- Ensure backward compatibility during gradual migration
This commit is contained in:
lin onetwo 2026-01-21 13:34:46 +08:00
parent 7c780ff5ef
commit fad4449d81
2 changed files with 30 additions and 3 deletions

View file

@ -2,7 +2,7 @@
"name": "tidgi",
"productName": "TidGi",
"description": "Customizable personal knowledge-base with Github as unlimited storage and blogging platform.",
"version": "0.13.0-prerelease17",
"version": "0.13.0-prerelease18",
"license": "MPL 2.0",
"packageManager": "pnpm@10.24.0",
"scripts": {

View file

@ -228,6 +228,7 @@ export class Workspace implements IWorkspaceService {
/**
* Save all workspaces to settings.json, removing syncable fields from wiki workspaces
* Only removes syncable fields if tidgi.config.json exists (to maintain backward compatibility)
* @param immediate Whether to immediately flush to disk
*/
private async saveWorkspacesToSettings(immediate?: boolean): Promise<void> {
@ -237,8 +238,23 @@ export class Workspace implements IWorkspaceService {
for (const [key, ws] of Object.entries(workspaces)) {
if (isWikiWorkspace(ws)) {
// Remove syncable fields from wiki workspaces (they are in tidgi.config.json)
workspacesForSettings[key] = removeSyncableFields(ws) as IWorkspace;
// Only remove syncable fields if tidgi.config.json exists
// This prevents losing data when tidgi.config.json hasn't been created yet
const configExists = await readTidgiConfig(ws.wikiFolderLocation);
if (configExists) {
workspacesForSettings[key] = removeSyncableFields(ws) as IWorkspace;
logger.debug('saveWorkspacesToSettings: Removed syncable fields (tidgi.config.json exists)', {
workspaceId: ws.id,
wikiFolderLocation: ws.wikiFolderLocation,
});
} else {
// Keep all fields in settings.json if tidgi.config.json doesn't exist
workspacesForSettings[key] = ws;
logger.debug('saveWorkspacesToSettings: Keeping all fields (no tidgi.config.json)', {
workspaceId: ws.id,
wikiFolderLocation: ws.wikiFolderLocation,
});
}
} else {
// Keep dedicated workspaces as is
workspacesForSettings[key] = ws;
@ -346,6 +362,17 @@ export class Workspace implements IWorkspaceService {
if (legacyTagName && (!workspaceWithSyncedConfig.tagNames || workspaceWithSyncedConfig.tagNames.length === 0)) {
fixingValues.tagNames = [legacyTagName.replaceAll('\n', '')];
}
// Migrate old workspaces without name: use folder name as default
// This ensures backward compatibility when loading workspaces created before tidgi.config.json was used
if (applySyncedConfig && (!workspaceWithSyncedConfig.name || workspaceWithSyncedConfig.name.trim() === '')) {
const folderName = path.basename(workspaceWithSyncedConfig.wikiFolderLocation);
fixingValues.name = folderName;
logger.info('sanitizeWorkspace: Migrating old workspace name from folder', {
workspaceId: workspaceWithSyncedConfig.id,
wikiFolderLocation: workspaceWithSyncedConfig.wikiFolderLocation,
migratedName: folderName,
});
}
// before 0.8.0, tidgi was loading http content, so lastUrl will be http protocol, but later we switch to tidgi:// protocol, so old value can't be used.
if (workspaceWithSyncedConfig.lastUrl && !workspaceWithSyncedConfig.lastUrl.startsWith('tidgi')) {
fixingValues.lastUrl = null;