Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions app/src/asset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
import {App} from "../index";
import {clearOBG} from "../layout/dock/util";
import {getDisplayName} from "../util/pathName";
import {emitToEventBus} from "../plugin/EventBus";

export class Asset extends Model {
public path: string;
Expand All @@ -35,9 +36,7 @@ export class Asset extends Model {
this.element.addEventListener("click", (event) => {
clearOBG();
setPanelFocus(this.element.parentElement.parentElement);
this.app.plugins.forEach(item => {
item.eventBus.emit("click-pdf", {event});
});
emitToEventBus("click-pdf", {event});
});
if (typeof this.pdfId === "string") {
this.getPdfId(() => {
Expand Down
2 changes: 1 addition & 1 deletion app/src/boot/globalEvent/command/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ export const globalCommand = (command: string, app: App) => {
setReadOnly(!window.siyuan.config.editor.readOnly);
return true;
case "lockScreen":
lockScreen(app);
lockScreen();
return true;
case "newFile":
newFile({
Expand Down
2 changes: 1 addition & 1 deletion app/src/boot/globalEvent/keydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
return;
}
if (matchHotKey(window.siyuan.config.keymap.general.lockScreen.custom, event)) {
lockScreen(app);
lockScreen();
event.preventDefault();
return;
}
Expand Down
19 changes: 9 additions & 10 deletions app/src/card/openCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {updateCardHV} from "./util";
import {showMessage} from "../dialog/message";
import {Menu} from "../plugin/Menu";
import {transaction} from "../protyle/wysiwyg/transaction";
import {emitToEventBus} from "../plugin/EventBus";

const genCardCount = (cardsData: ICardData, allIndex = 0) => {
let newIndex = 0;
Expand Down Expand Up @@ -695,7 +696,7 @@ export const bindCardEvent = async (options: {
element.previousElementSibling.textContent = currentCard.nextDues[btnIndex - 1];
});
actionElements[1].classList.remove("fn__none");
emitEvent(options.app, currentCard, type);
emitEvent(currentCard, type);
return;
}
} else if (type === "-2") { // 上一步
Expand All @@ -708,7 +709,7 @@ export const bindCardEvent = async (options: {
index,
cardsData: options.cardsData
});
emitEvent(options.app, options.cardsData.cards[index + 1], type);
emitEvent(options.cardsData.cards[index + 1], type);
}
return;
}
Expand Down Expand Up @@ -737,7 +738,7 @@ export const bindCardEvent = async (options: {
notebook: docId,
reviewedCards: options.cardsData.cards
}, async (result) => {
emitEvent(options.app, options.cardsData.cards[index - 1], type);
emitEvent(options.cardsData.cards[index - 1], type);
index = 0;
options.cardsData = result.data;
for (let i = 0; i < options.app.plugins.length; i++) {
Expand Down Expand Up @@ -768,19 +769,17 @@ export const bindCardEvent = async (options: {
index,
cardsData: options.cardsData
});
emitEvent(options.app, options.cardsData.cards[index - 1], type);
emitEvent(options.cardsData.cards[index - 1], type);
});
}
});
return editor;
};

const emitEvent = (app: App, card: ICard, type: string) => {
app.plugins.forEach(item => {
item.eventBus.emit("click-flashcard-action", {
type,
card
});
const emitEvent = (card: ICard, type: string) => {
emitToEventBus("click-flashcard-action", {
type,
card
});
};

Expand Down
27 changes: 12 additions & 15 deletions app/src/dialog/processSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {hideAllElements, hideElements} from "../protyle/ui/hideElements";
import {App} from "../index";
import {saveScroll} from "../protyle/scroll/saveScroll";
import {isInAndroid, isInHarmony, isInIOS, setStorageVal} from "../protyle/util/compatibility";
import {Plugin} from "../plugin";
import {emitToEventBus} from "../plugin/EventBus";

const updateTitle = (rootID: string, tab: Tab, protyle?: IProtyle) => {
fetchPost("/api/block/getDocInfo", {
Expand Down Expand Up @@ -233,13 +233,11 @@ export const setDefRefCount = (data: {
}
};

export const lockScreen = async (app: App) => {
export const lockScreen = async () => {
if (window.siyuan.config.readonly || window.siyuan.isPublish) {
return;
}
app.plugins.forEach(item => {
item.eventBus.emit("lock-screen");
});
emitToEventBus("lock-screen");
/// #if !MOBILE
exportLayout({
errorExit: false,
Expand Down Expand Up @@ -558,7 +556,7 @@ export const downloadProgress = (data: { id: string, percent: number }) => {
}
};

export const processSync = (data?: IWebSocketData, plugins?: Plugin[]) => {
export const processSync = (data?: IWebSocketData) => {
/// #if MOBILE
const menuSyncUseElement = document.querySelector("#menuSyncNow use");
const barSyncUseElement = document.querySelector("#toolbarSync use");
Expand All @@ -585,6 +583,7 @@ export const processSync = (data?: IWebSocketData, plugins?: Plugin[]) => {
} else if (data.code === 1) { // success
menuSyncUseElement?.setAttribute("xlink:href", "#iconCloudSucc");
barSyncUseElement.setAttribute("xlink:href", "#iconCloudSucc");
document.getElementById("toolbarSync").classList.add("fn__none");
}
/// #else
const iconElement = document.querySelector("#barSync");
Expand Down Expand Up @@ -614,13 +613,11 @@ export const processSync = (data?: IWebSocketData, plugins?: Plugin[]) => {
useElement.setAttribute("xlink:href", "#iconCloudSucc");
}
/// #endif
plugins.forEach((item) => {
if (data.code === 0) {
item.eventBus.emit("sync-start", data);
} else if (data.code === 1) {
item.eventBus.emit("sync-end", data);
} else if (data.code === 2) {
item.eventBus.emit("sync-fail", data);
}
});
if (data.code === 0) {
emitToEventBus("sync-start", data);
} else if (data.code === 1) {
emitToEventBus("sync-end", data);
} else if (data.code === 2) {
emitToEventBus("sync-fail", data);
}
};
13 changes: 6 additions & 7 deletions app/src/editor/openLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {App} from "../index";
import {fetchPost} from "../util/fetch";
import {checkFold} from "../util/noRelyPCFunction";
import {openMobileFileById} from "../mobile/editor";
import {emitToEventBus} from "../plugin/EventBus";

export const processSYLink = (app: App, url: string) => {
let urlObj: URL;
Expand Down Expand Up @@ -82,13 +83,11 @@ export const processSYLink = (app: App, url: string) => {
ipcRenderer.send(Constants.SIYUAN_CMD, "show");
/// #endif
}
app.plugins.forEach(plugin => {
plugin.eventBus.emit("open-siyuan-url-block", {
url,
id,
focus,
exist: existResponse.data,
});
emitToEventBus("open-siyuan-url-block", {
url,
id,
focus,
exist: existResponse.data,
});
});
return true;
Expand Down
5 changes: 2 additions & 3 deletions app/src/editor/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {preventScroll} from "../protyle/scroll/preventScroll";
import {clearOBG} from "../layout/dock/util";
import {Model} from "../layout/Model";
import {hideElements} from "../protyle/ui/hideElements";
import {emitToEventBus} from "../plugin/EventBus";

export const openFileById = async (options: {
app: App,
Expand Down Expand Up @@ -597,9 +598,7 @@ export const updatePanelByEditor = (options: {
}
}
}
options.protyle.app.plugins.forEach(item => {
item.eventBus.emit("switch-protyle", {protyle: options.protyle});
});
emitToEventBus("switch-protyle", {protyle: options.protyle});
}
// 切换页签或关闭所有页签时,需更新对应的面板
const models = getAllModels();
Expand Down
8 changes: 4 additions & 4 deletions app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {Tag} from "./layout/dock/Tag";
import {updateControlAlt} from "./protyle/util/hotKey";
import {updateAppearance} from "./config/util/updateAppearance";
import {renderSnippet} from "./config/util/snippets";
import {registerCustomEventBus, emitToEventBus} from "./plugin/EventBus";

export class App {
public plugins: import("./plugin").Plugin[] = [];
Expand All @@ -65,14 +66,13 @@ export class App {
closedTabs: [],
ctrlIsPressed: false,
altIsPressed: false,
registerCustomEventBus,
ws: new Model({
app: this,
id: genUUID(),
type: "main",
msgCallback: (data) => {
this.plugins.forEach((plugin) => {
plugin.eventBus.emit("ws-main", data);
});
emitToEventBus("ws-main", data);
if (data) {
switch (data.cmd) {
case "logoutAuth":
Expand Down Expand Up @@ -176,7 +176,7 @@ export class App {
transactionError();
break;
case "syncing":
processSync(data, this.plugins);
processSync(data);
break;
case "backgroundtask":
progressBackgroundTask(data.data.tasks);
Expand Down
9 changes: 3 additions & 6 deletions app/src/layout/dock/Files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {ipcRenderer} from "electron";
/// #endif
import {hideTooltip, showTooltip} from "../../dialog/tooltip";
import {selectOpenTab} from "./util";
import {emitToEventBus} from "../../plugin/EventBus";

export class Files extends Model {
public element: HTMLElement;
Expand Down Expand Up @@ -57,9 +58,7 @@ export class Files extends Model {
break;
case "mount":
this.onMount(data);
options.app.plugins.forEach((item) => {
item.eventBus.emit("opened-notebook", data);
});
emitToEventBus("opened-notebook", data);
break;
case "createnotebook":
setNoteBook((notebooks) => {
Expand All @@ -81,9 +80,7 @@ export class Files extends Model {
break;
case "unmount":
this.onRemove(data);
options.app.plugins.forEach((item) => {
item.eventBus.emit("closed-notebook", data);
});
emitToEventBus("closed-notebook", data);
break;
case "removeDoc":
this.onRemove(data);
Expand Down
19 changes: 8 additions & 11 deletions app/src/layout/dock/Inbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,17 +294,14 @@ ${data.shorthandContent}
}
}).element);
}
if (this.app.plugins) {
emitOpenMenu({
plugins: this.app.plugins,
type: "open-menu-inbox",
detail: {
ids,
element: itemElement || detailsElement,
},
separatorPosition: "top",
});
}
emitOpenMenu({
type: "open-menu-inbox",
detail: {
ids,
element: itemElement || detailsElement,
},
separatorPosition: "top",
});
window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY + 16});
}

Expand Down
57 changes: 24 additions & 33 deletions app/src/menus/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,14 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
}
}]
}).element);
if (app.plugins) {
emitOpenMenu({
plugins: app.plugins,
type: "open-menu-doctree",
detail: {
elements: selectItemElements,
type: "docs"
},
separatorPosition: "top",
});
}
emitOpenMenu({
type: "open-menu-doctree",
detail: {
elements: selectItemElements,
type: "docs"
},
separatorPosition: "top",
});
return window.siyuan.menus.menu;
};

Expand Down Expand Up @@ -417,17 +414,14 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
}
}]
}).element);
if (app.plugins) {
emitOpenMenu({
plugins: app.plugins,
type: "open-menu-doctree",
detail: {
elements: selectItemElements,
type: "notebook"
},
separatorPosition: "top",
});
}
emitOpenMenu({
type: "open-menu-doctree",
detail: {
elements: selectItemElements,
type: "notebook"
},
separatorPosition: "top",
});
return window.siyuan.menus.menu;
};

Expand Down Expand Up @@ -712,17 +706,14 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
}
genImportMenu(notebookId, pathString);
window.siyuan.menus.menu.append(exportMd(id));
if (app.plugins) {
emitOpenMenu({
plugins: app.plugins,
type: "open-menu-doctree",
detail: {
elements: selectItemElements,
type: "doc"
},
separatorPosition: "top",
});
}
emitOpenMenu({
type: "open-menu-doctree",
detail: {
elements: selectItemElements,
type: "doc"
},
separatorPosition: "top",
});
window.siyuan.menus.menu.element.setAttribute("data-from", Constants.MENU_FROM_DOC_TREE_MORE_DOC);
return window.siyuan.menus.menu;
};
Expand Down
Loading