Skip to content

Commit

Permalink
0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed Jul 27, 2023
1 parent 5cf04fd commit ff7510b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 22 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "excalibrain",
"name": "ExcaliBrain",
"version": "0.2.0",
"version": "0.2.1",
"minAppVersion": "1.1.6",
"description": "A clean, intuitive and editable graph view for Obsidian",
"author": "Zsolt Viczian",
Expand Down
33 changes: 22 additions & 11 deletions src/Scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Scene {
app: App;
leaf: WorkspaceLeaf;
centralPagePath: string; //path of the page in the center of the graph
private centralLeaf: WorkspaceLeaf; //workspace leaf containing the central page
public centralLeaf: WorkspaceLeaf; //workspace leaf containing the central page
textSize: {width:number, height:number};
nodeWidth: number;
nodeHeight: number;
Expand Down Expand Up @@ -107,8 +107,8 @@ export class Scene {
//@ts-ignore
this.centralLeaf.view?.file?.path !== centralPage.file.path
) {
this.centralLeaf.openFile(centralPage.file, {active: true});
app.workspace.revealLeaf(this.centralLeaf);
this.centralLeaf.openFile(centralPage.file, {active: false});
//app.workspace.revealLeaf(this.centralLeaf);
}
}
await this.render();
Expand Down Expand Up @@ -848,7 +848,7 @@ export class Scene {
}


public unloadScene() {
public unloadScene(saveSettings:boolean = true, silent: boolean = false) {
if(this.removeEH) {
this.removeEH();
this.removeEH = undefined;
Expand Down Expand Up @@ -899,11 +899,13 @@ export class Scene {
// timout is to make sure Obsidian is not being terminated when scene closes,
// becasue that can lead to crippled settings file
// if the plugin is still there after 400ms, it is safe to save the settings
setTimeout(async () => {
await this.plugin.loadSettings(); //only overwrite the navigation history, save other synchronized settings
this.plugin.settings.navigationHistory = [...this.plugin.navigationHistory];
await this.plugin.saveSettings();
},400);
if(saveSettings) {
setTimeout(async () => {
await this.plugin.loadSettings(); //only overwrite the navigation history, save other synchronized settings
this.plugin.settings.navigationHistory = [...this.plugin.navigationHistory];
await this.plugin.saveSettings();
},400);
}
this.toolsPanel?.terminate();
this.toolsPanel = undefined;
this.historyPanel?.terminate();
Expand All @@ -914,9 +916,18 @@ export class Scene {
this.centralPagePath = undefined;
this.terminated = true;
//@ts-ignore
if(!app.plugins.plugins["obsidian-excalidraw-plugin"]) {
if(!this.app.plugins.plugins["obsidian-excalidraw-plugin"]) {
this.plugin.EA = null;
}
new Notice("Brain Graph Off");
if(!silent) {
new Notice("Brain Graph Off");
}
const mostRecentLeaf = this.app.workspace.getMostRecentLeaf();
if(mostRecentLeaf) {
this.app.workspace.setActiveLeaf(
mostRecentLeaf,
{ focus: true },
)
}
}
}
42 changes: 32 additions & 10 deletions src/excalibrain-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ declare module "obsidian" {
disablePlugin(plugin: string):Promise<any>;
};
}
interface WorkspaceLeaf {
id: string;
}
}

declare global {
Expand Down Expand Up @@ -418,8 +421,11 @@ export default class ExcaliBrain extends Plugin {
if(!this.excalidrawAvailable()) return; //still need this in case user sets a hotkey

if(this.scene && !this.scene.terminated) {
this.revealBrainLeaf();
return;
if(this.app.workspace.getLeafById(this.scene.leaf?.id)) {
this.revealBrainLeaf();
return;
}
this.scene.unloadScene(false, true);
}
const leaf = this.getBrainLeaf();
if(leaf) {
Expand All @@ -443,8 +449,11 @@ export default class ExcaliBrain extends Plugin {
if(!this.excalidrawAvailable() || this.EA.DEVICE.isMobile) return; //still need this in case user sets a hotkey

if(this.scene && !this.scene.terminated) {
this.revealBrainLeaf();
return;
if(this.app.workspace.getLeafById(this.scene.leaf?.id)) {
this.revealBrainLeaf();
return;
}
this.scene.unloadScene(false, true);
}
const leaf = this.getBrainLeaf();
if(leaf) {
Expand All @@ -464,15 +473,18 @@ export default class ExcaliBrain extends Plugin {
name: t("COMMAND_START_HOVER"),
checkCallback: (checking: boolean) => {
//@ts-ignore
const hoverEditor = app.plugins.getPlugin("obsidian-hover-editor");
const hoverEditor = this.app.plugins.getPlugin("obsidian-hover-editor");
if(checking) {
return hoverEditor && this.excalidrawAvailable();
}
if(!this.excalidrawAvailable() || !hoverEditor) return;

if(this.scene && !this.scene.terminated) {
this.revealBrainLeaf();
return;
if(this.app.workspace.getLeafById(this.scene.leaf?.id)) {
this.revealBrainLeaf();
return;
}
this.scene.unloadScene(false, true);
}
try {
//getBrainLeaf will only return one leaf. If there are multiple leaves open, some in hover editors other docked, the
Expand Down Expand Up @@ -512,7 +524,7 @@ export default class ExcaliBrain extends Plugin {

getBrainLeaf():WorkspaceLeaf {
let brainLeaf: WorkspaceLeaf;
app.workspace.iterateAllLeaves(leaf=>{
this.app.workspace.iterateAllLeaves(leaf=>{
if(
leaf.view &&
this.EA.isExcalidrawView(leaf.view) &&
Expand Down Expand Up @@ -560,7 +572,8 @@ export default class ExcaliBrain extends Plugin {
}

this.EA.onLinkClickHook = (element,linkText,event) => {
const path = linkText.match(/\[\[([^\]]*)/)[1];
const path = linkText.match(/\[\[([^\]]*)/)?.[1];
if(!path) return true;
const page = this.pages.get(path);
const ea = this.EA;

Expand Down Expand Up @@ -594,6 +607,15 @@ export default class ExcaliBrain extends Plugin {

//if centralPage is in embeddedFrame, simply render the scene
if(this.settings.embedCentralNode) {
if(this.scene.centralPagePath === page.path) {
if(this.scene.isCentralLeafStillThere()) {
this.scene.centralLeaf.openFile(page.file,{active:true});
return false;
}
ea.targetView.linksAlwaysOpenInANewPane = false;
setTimeout(()=>ea.targetView.linksAlwaysOpenInANewPane = true,300);
return true;
}
this.scene.renderGraphForPath(path);
return false;
}
Expand All @@ -610,7 +632,7 @@ export default class ExcaliBrain extends Plugin {
if(this.scene.isCentralLeafStillThere()) {
const f = app.vault.getAbstractFileByPath(path.split("#")[0]);
if(f && f instanceof TFile) {
centralLeaf.openFile(f);
centralLeaf.openFile(f,{active:false});
this.scene.renderGraphForPath(path, false);
return false;
}
Expand Down

0 comments on commit ff7510b

Please sign in to comment.