Skip to content

Commit

Permalink
remove console
Browse files Browse the repository at this point in the history
  • Loading branch information
webceoboy committed Jan 10, 2025
1 parent a29da40 commit 770a48f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
23 changes: 15 additions & 8 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Plugin, WorkspaceLeaf, ItemView, addIcon, moment } from "obsidian";
import {Plugin, WorkspaceLeaf, ItemView, addIcon, moment} from "obsidian";

const IframeViewType = "moredraw-iframe-view";
// 插件入口
export default class MoreDrawPlugin extends Plugin {
Expand All @@ -24,7 +25,7 @@ export default class MoreDrawPlugin extends Plugin {

// 激活 iframe 视图
async activateIframeView() {
const { workspace } = this.app;
const {workspace} = this.app;
const leaf = workspace.getRightLeaf(false); // 在右侧创建新的叶子
if (leaf) {
await leaf.setViewState({
Expand All @@ -33,16 +34,17 @@ export default class MoreDrawPlugin extends Plugin {
workspace.revealLeaf(leaf);
}
}

// 切换 iframe 视图(打开或关闭)
async toggleIframeView() {
const { workspace } = this.app;

const {workspace} = this.app;
const rightSplit = this.app.workspace.rightSplit;
if (rightSplit.collapsed) rightSplit.expand();
// 检查是否已经有该视图打开
const existingLeaf = workspace.getLeavesOfType(IframeViewType).first();
if (existingLeaf) {
// 如果视图已存在,关闭它
workspace.detachLeavesOfType(IframeViewType);
this.isIframeOpen = false;
workspace.revealLeaf(existingLeaf);
this.isIframeOpen = true;
} else {
// 如果视图不存在,打开它
const leaf = workspace.getRightLeaf(false); // 在右侧创建新的叶子
Expand All @@ -61,12 +63,15 @@ export default class MoreDrawPlugin extends Plugin {
class MoreDrawIframeView extends ItemView {
private ready = false;
private iframe: HTMLIFrameElement | null = null;

constructor(leaf: WorkspaceLeaf) {
super(leaf);
}

getIcon() {
return "moredraw-icon";
}

// 返回视图类型
getViewType() {
return IframeViewType;
Expand Down Expand Up @@ -99,7 +104,6 @@ class MoreDrawIframeView extends ItemView {

this.iframe = iframe;
container.win.onmessage = (event: MessageEvent) => {
console.log("receive message", event);
if (event.data && event.data == "ready") {
this.ready = true;
this.onReady();
Expand All @@ -109,6 +113,7 @@ class MoreDrawIframeView extends ItemView {
}
};
}

onReady() {
this.postMessage({
type: "init",
Expand All @@ -119,6 +124,7 @@ class MoreDrawIframeView extends ItemView {
},
});
}

postMessage(data: any) {
if (this.iframe && this.ready) {
this.iframe.contentWindow?.postMessage(data, "*");
Expand All @@ -129,6 +135,7 @@ class MoreDrawIframeView extends ItemView {
async onClose() {
// 可以在这里清理资源或状态
}

getObsidianVersion(): string {
const userAgent = navigator.userAgent;

Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "moredraw",
"name": "MoreDraw",
"version": "1.0.2",
"version": "1.0.3",
"minAppVersion": "0.15.0",
"description": "A infinite canvas whiteboard with ai to draw flowchart ,mind map and other diagram.",
"description": "A infinite canvas whiteboard with ai to draw flowchart, mind map and other diagram.",
"author": "webceoboy2011",
"authorUrl": "https://moredraw.com",
"isDesktopOnly": false
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "MoreDraw",
"version": "1.0.2",
"version": "1.0.3",
"description": "This is moredraw.com plugin for Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {
Expand All @@ -22,4 +22,4 @@
"tslib": "2.4.0",
"typescript": "4.7.4"
}
}
}
7 changes: 4 additions & 3 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"1.0.0": "0.15.0",
"undefined": "0.15.0",
"1.0.2": "0.15.0"
}
"1.0.1": "0.15.0",
"1.0.2": "0.15.0",
"1.0.3": "0.15.0"
}

0 comments on commit 770a48f

Please sign in to comment.