MCPcopy
hub / github.com/graphif/project-graph / init

Method init

app/src/core/Project.tsx:300–345  ·  view source on GitHub ↗

* 服务加载完成后再调用

()

Source from the content-addressed store, hash-verified

298 * 服务加载完成后再调用
299 */
300 async init() {
301 if (!(await this.fs.exists(this.uri))) {
302 return;
303 }
304 try {
305 // 解析项目文件
306 const { serializedStageObjects, tags, references, metadata, readme } = await this.parseProjectFile();
307
308 // 检查并确认升级
309 const currentVersion = metadata?.version || "2.0.0";
310 const latestVersion = ProjectUpgrader.NLatestVersion;
311 const confirmed = await this.checkAndConfirmUpgrade(currentVersion, latestVersion);
312 if (!confirmed) return; // 用户取消升级,不打开文件,跳过 this.projectState = ProjectState.Saved
313
314 // 升级数据
315 const [upgradedStageObjects, upgradedMetadata] = ProjectUpgrader.upgradeNAnyToNLatest(
316 serializedStageObjects,
317 metadata as any,
318 );
319
320 // 应用升级后的数据
321 this.stage = deserialize(upgradedStageObjects, this);
322 this.tags = tags;
323 this.references = references;
324 this.metadata = upgradedMetadata;
325 this.readme = readme;
326
327 // 更新引用关系,包括双向线的偏移状态
328 // 注意:这里需要在服务加载后才能调用,所以需要检查服务是否已加载
329 if (this.getService("stageManager")) {
330 this.stageManager.updateReferences();
331 }
332 } catch (e) {
333 console.warn(e);
334 const errorMessage = `打开文件时发生错误,文件内容可能已损坏或与当前软件版本不兼容。\n\n错误信息:${e}`;
335 const result = await Dialog.buttons("文件解析失败", errorMessage, [
336 { id: "ok", label: "确定" },
337 { id: "copy", label: "复制错误信息" },
338 ]);
339 if (result === "copy") {
340 navigator.clipboard.writeText(errorMessage);
341 }
342 return;
343 }
344 this.projectState = ProjectState.Saved;
345 }
346
347 get isDraft() {
348 return this.uri.scheme === "draft";

Callers 11

onUpgradeOldJsonFunction · 0.95
generateSectionFunction · 0.95
generateFullViewFunction · 0.95
getSectionsByFileNameFunction · 0.95
extractSectionTextFunction · 0.95
main.tsxFile · 0.45
loadSyncModulesFunction · 0.45
loadLanguageFilesFunction · 0.45
AppFunction · 0.45

Calls 5

parseProjectFileMethod · 0.95
deserializeFunction · 0.90
updateReferencesMethod · 0.80
existsMethod · 0.65

Tested by

no test coverage detected