Finalize for first release

This commit is contained in:
Dmitry Shabat 2022-12-20 17:44:43 +04:00
parent 156bfd9dd0
commit f447761a93

25
main.ts
View file

@ -1,4 +1,4 @@
import { Plugin, WorkspaceLeaf, TFile} from 'obsidian';
import { Plugin, WorkspaceLeaf, TFile, normalizePath} from 'obsidian';
import * as path from "path";
import {readFile} from "fs/promises";
@ -13,16 +13,25 @@ export default class SyncGraphPlugin extends Plugin {
async syncGlobalToLocal() {
const configDir = app.vault.configDir;
const graphConfigPath = path.join(configDir, 'graph.json');
const graphConfigPath = normalizePath(configDir + '/graph.json');
// this.app.vault.getAbstractFileByPath('.obsidian/graph.json') would return null
// So we're doing it the less safe way
const graphConfigJson = await this.app.vault.adapter.read(graphConfigPath);
const graphConfig = JSON.parse(graphConfigJson);
const graphColorGroups = graphConfig.colorGroups;
this.getLocalGraphLeaves().forEach((leaf) => {
this.setColorGroups(leaf, graphColorGroups);
})
// const graphConfigJson = await this.app.vault.adapter.read(graphConfigPath);
// const graphConfigFile = app.vault.getAbstractFileByPath(graphConfigPath);
// if (graphConfigFile instanceof TFile) {
if (true) {
// const graphConfigJson = await app.vault.read(graphConfigFile);
const graphConfigJson = await this.app.vault.adapter.read(graphConfigPath);
const graphConfig = JSON.parse(graphConfigJson);
const graphColorGroups = graphConfig.colorGroups;
this.getLocalGraphLeaves().forEach((leaf) => {
this.setColorGroups(leaf, graphColorGroups);
})
} else {
// console.log(graphConfigPath);
// console.log(graphConfigFile);
}
}
getLocalGraphLeaves() {