向 storage.json 写入项目用户信息
在最近打开记录中,向 storage.json 写入项目额外信息(创建用户、项目类型、打开时间等),用于区分不同登录用户的项目。
src/vs/platform/workspaces/electron-main/workspacesHistoryMainService.ts
// Folder — 向 storage.json 中添加其他信息
else if (isRecentFolder(recent)) {
if (indexOfFolder(workspaces, recent.folderUri) === -1) {
// 读取当前登录用户
const localConfigPath = path.join(this.environmentService.appRoot, 'out', 'localConfig.json');
const username = JSON.parse(fs.readFileSync(localConfigPath).toString()).userData.username;
const userId = JSON.parse(fs.readFileSync(localConfigPath).toString()).userData.userId;
// 判断打开的是否是当前登录用户创建的项目
if (recent.folderUri.fsPath.indexOf(username) !== -1 || recent.folderUri.fsPath.indexOf(userId) !== -1) {
recent.folderName = getFileName(recent.folderUri);
if (fs.existsSync(path.join(recent.folderUri.fsPath, '.efort.json'))) {
recent.folderType = (this.efortConfigService.readSync(`${recent.folderUri.fsPath}\\.efort.json`)).type;
} else if (fs.existsSync(path.join(recent.folderUri.fsPath, 'solution', '.efort.json'))) {
recent.folderType = (this.efortConfigService.readSync(`${recent.folderUri.fsPath}\\solution\\.efort.json`)).type;
} else {
recent.folderType = 'other';
}
recent.openDate = new Date().getTime();
recent.createDate = fs.statSync(recent.folderUri.fsPath).birthtime.getTime();
recent.createUser = userId;
workspaces.push(recent);
}
}
}
原文链接:https://www.ssssmy.com/notes/mo-dou-ide-yuan-ma-xiang-storagejson-xie-ru-xiang-mu-yong-hu-xin-xi