Skip to content

Commit

Permalink
♻️ fix #11733
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Jul 5, 2024
1 parent f25b36f commit cd40ec5
Show file tree
Hide file tree
Showing 21 changed files with 341 additions and 398 deletions.
6 changes: 3 additions & 3 deletions app/src/boot/globalEvent/keydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
event.preventDefault();
return true;
}
if (!isFileFocus && matchHotKey(window.siyuan.config.keymap.editor.general.quickMakeCard.custom, event)) {
if (!isFileFocus && matchHotKey(window.siyuan.config.keymap.editor.general.quickMakeCard.custom, event) && !window.siyuan.config.readonly) {
if (protyle.title?.editElement.contains(range.startContainer)) {
quickMakeCard(protyle, [protyle.title.element]);
} else {
Expand Down Expand Up @@ -316,7 +316,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
event.preventDefault();
return true;
}
if (!isFileFocus && matchHotKey(window.siyuan.config.keymap.editor.general.spaceRepetition.custom, event)) {
if (!isFileFocus && matchHotKey(window.siyuan.config.keymap.editor.general.spaceRepetition.custom, event) && !window.siyuan.config.readonly) {
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: protyle.block.rootID}, (response) => {
openCardByData(app, response.data, "doc", protyle.block.rootID, protyle.title?.editElement.textContent || window.siyuan.languages.untitled);
});
Expand Down Expand Up @@ -593,7 +593,7 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
const pathString = liElements[0].getAttribute("data-path");
const isFile = liElements[0].getAttribute("data-type") === "navigation-file";

if (matchHotKey(window.siyuan.config.keymap.editor.general.spaceRepetition.custom, event)) {
if (matchHotKey(window.siyuan.config.keymap.editor.general.spaceRepetition.custom, event) && !window.siyuan.config.readonly) {
if (isFile) {
const id = liElements[0].getAttribute("data-node-id");
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: id}, (response) => {
Expand Down
3 changes: 3 additions & 0 deletions app/src/card/openCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,9 @@ const emitEvent = (app: App, card: ICard, type: string) => {
};

export const openCard = (app: App) => {
if (window.siyuan.config.readonly) {
return
}
fetchPost("/api/riff/getRiffDueCards", {deckID: ""}, (cardsResponse) => {
openCardByData(app, cardsResponse.data, "all");
});
Expand Down
10 changes: 4 additions & 6 deletions app/src/config/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,10 @@ export const editor = {
if (fontFamilyElement.tagName === "SELECT") {
let fontFamilyHTML = `<option value="">${window.siyuan.languages.default}</option>`;
fetchPost("/api/system/getSysFonts", {}, (response) => {
if (response.code === 0) {
response.data.forEach((item: string) => {
fontFamilyHTML += `<option value="${item}"${window.siyuan.config.editor.fontFamily === item ? " selected" : ""}>${item}</option>`;
});
fontFamilyElement.innerHTML = fontFamilyHTML;
}
response.data.forEach((item: string) => {
fontFamilyHTML += `<option value="${item}"${window.siyuan.config.editor.fontFamily === item ? " selected" : ""}>${item}</option>`;
});
fontFamilyElement.innerHTML = fontFamilyHTML;
});
}
editor.element.querySelector("#clearHistory").addEventListener("click", () => {
Expand Down
46 changes: 14 additions & 32 deletions app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export class App {
registerServiceWorker(`${Constants.SERVICE_WORKER_PATH}?v=${Constants.SIYUAN_VERSION}`);
/// #endif
addBaseURL();
addScriptSync(`${Constants.PROTYLE_CDN}/js/lute/lute.min.js?v=${Constants.SIYUAN_VERSION}`, "protyleLuteScript"),
addScript(`${Constants.PROTYLE_CDN}/js/protyle-html.js?v=${Constants.SIYUAN_VERSION}`, "protyleWcHtmlScript"),

this.appId = Constants.SIYUAN_APPID;
window.siyuan = {
Expand Down Expand Up @@ -160,40 +158,24 @@ export class App {
};

fetchPost("/api/system/getConf", {}, async (response) => {
addScriptSync(`${Constants.PROTYLE_CDN}/js/lute/lute.min.js?v=${Constants.SIYUAN_VERSION}`, "protyleLuteScript");
addScript(`${Constants.PROTYLE_CDN}/js/protyle-html.js?v=${Constants.SIYUAN_VERSION}`, "protyleWcHtmlScript");
window.siyuan.config = response.data.conf;

const promises = [
loadPlugins(this),
new Promise<void>(resolve => getLocalStorage(resolve)),
new Promise<void>(resolve => fetchGet(
`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`,
(lauguages: IObject) => {
window.siyuan.languages = lauguages;
resolve();
},
)),
];

if (!window.siyuan.config.readonly) {
promises.push(new Promise<void>(resolve => {
await loadPlugins(this);
getLocalStorage(() => {
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages: IObject) => {
window.siyuan.languages = lauguages;
window.siyuan.menus = new Menus(this);
bootSync();
fetchPost("/api/setting/getCloudUser", {}, userResponse => {
window.siyuan.user = userResponse.data;
resolve();
onGetConfig(response.data.start, this);
account.onSetaccount();
setTitle(window.siyuan.languages.siyuanNote);
initMessage();
});
}));
}

await Promise.all(promises);

if (!window.siyuan.config.readonly) {
bootSync();
}

window.siyuan.menus = new Menus(this);
onGetConfig(response.data.start, this);
account.onSetaccount();
setTitle(window.siyuan.languages.siyuanNote);
initMessage();
});
});
});
setNoteBook();
initBlockPopover(this);
Expand Down
4 changes: 2 additions & 2 deletions app/src/layout/Wnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class Wnd {
<ul class="fn__flex layout-tab-bar"></ul>
<ul class="layout-tab-bar layout-tab-bar--readonly fn__flex-1">
<li class="item item--readonly">
<span data-type="new" class="block__icon block__icon--show ariaLabel" aria-label="${window.siyuan.languages.newFile}"><svg><use xlink:href="#iconAdd"></use></svg></span>
<span data-type="new" class="block__icon block__icon--show ariaLabel${window.siyuan.config.readonly ? " fn__none" : ""}" aria-label="${window.siyuan.languages.newFile}"><svg><use xlink:href="#iconAdd"></use></svg></span>
<span class="fn__flex-1"></span>
<span data-type="more" data-menu="true" class="block__icon block__icon--show ariaLabel" aria-label="${window.siyuan.languages.switchTab}"><svg><use xlink:href="#iconDown"></use></svg></span>
</li>
Expand Down Expand Up @@ -105,7 +105,7 @@ export class Wnd {
this.headersElement.parentElement.addEventListener("click", (event) => {
let target = event.target as HTMLElement;
while (target && !target.isEqualNode(this.headersElement)) {
if (target.classList.contains("block__icon") && target.getAttribute("data-type") === "new" && !window.siyuan.config.readonly) {
if (target.classList.contains("block__icon") && target.getAttribute("data-type") === "new") {
setPanelFocus(this.headersElement.parentElement.parentElement);
newFile({
app,
Expand Down
22 changes: 10 additions & 12 deletions app/src/layout/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {hasClosestByClassName} from "../protyle/util/hasClosest";
import {fetchPost} from "../util/fetch";
import {mountHelp} from "../util/mount";
/// #if !BROWSER
import { ipcRenderer } from "electron";
import {ipcRenderer} from "electron";
/// #endif
/// #endif
import {MenuItem} from "../menus/Menu";
Expand Down Expand Up @@ -64,16 +64,14 @@ export const initStatus = (isWindow = false) => {
}
window.siyuan.menus.menu.remove();
window.siyuan.menus.menu.element.setAttribute("data-name", "statusHelp");
if (!isIPad()) {
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.userGuide,
icon: "iconHelp",
disabled: window.siyuan.config.readonly,
click: () => {
mountHelp();
}
}).element);
}
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.userGuide,
icon: "iconHelp",
ignore: isIPad() || window.siyuan.config.readonly,
click: () => {
mountHelp();
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.feedback,
icon: "iconFeedback",
Expand Down Expand Up @@ -198,7 +196,7 @@ export const renderStatusbarCounter = (stat: {
imageCount: number,
refCount: number
}) => {
if(!stat) {
if (!stat) {
return;
}
let html = `<span class="ft__on-surface">${window.siyuan.languages.runeCount}</span>&nbsp;${stat.runeCount}<span class="fn__space"></span>
Expand Down
2 changes: 1 addition & 1 deletion app/src/layout/tabUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export const newCenterEmptyTab = (app: App) => {
<svg class="b3-list-item__graphic"><use xlink:href="#iconFilesRoot"></use></svg>
<span>${window.siyuan.languages.newNotebook}</span>
</div>
<div class="b3-list-item${isIPad() ? " fn__none" : ""}" id="editorEmptyHelp">
<div class="b3-list-item${(isIPad() || window.siyuan.config.readonly) ? " fn__none" : ""}" id="editorEmptyHelp">
<svg class="b3-list-item__graphic"><use xlink:href="#iconHelp"></use></svg>
<span>${window.siyuan.languages.userGuide}</span>
</div>
Expand Down
20 changes: 9 additions & 11 deletions app/src/layout/topBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,15 @@ export const setZoom = (type: "zoomIn" | "zoomOut" | "restore") => {

const openPlugin = (app: App, target: Element) => {
const menu = new Menu("topBarPlugin");
if (!isHuawei()) {
menu.addItem({
icon: "iconSettings",
label: window.siyuan.languages.manage,
disabled: window.siyuan.config.readonly,
click() {
openSetting(app).element.querySelector('.b3-tab-bar [data-name="bazaar"]').dispatchEvent(new CustomEvent("click"));
}
});
menu.addSeparator();
}
menu.addItem({
icon: "iconSettings",
label: window.siyuan.languages.manage,
ignore: isHuawei() || window.siyuan.config.readonly,
click() {
openSetting(app).element.querySelector('.b3-tab-bar [data-name="bazaar"]').dispatchEvent(new CustomEvent("click"));
}
});
menu.addSeparator(undefined, isHuawei() || window.siyuan.config.readonly);
let hasPlugin = false;
app.plugins.forEach((plugin) => {
// @ts-ignore
Expand Down
3 changes: 3 additions & 0 deletions app/src/menus/Menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ export class MenuItem {
public element: HTMLElement;

constructor(options: IMenu) {
if (options.ignore) {
return;
}
if (options.type === "empty") {
this.element = document.createElement("div");
this.element.innerHTML = options.label;
Expand Down
4 changes: 1 addition & 3 deletions app/src/menus/commonMenuItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ export const exportMd = (id: string) => {
label: window.siyuan.languages.template,
iconClass: "ft__error",
icon: "iconMarkdown",
disabled: window.siyuan.config.readonly,
click: async () => {
const result = await fetchSyncPost("/api/block/getRefText", {id: id});

Expand Down Expand Up @@ -508,9 +507,8 @@ export const exportMd = (id: string) => {
});
});
return;
} else if (response.code === 0) {
showMessage(window.siyuan.languages.exportTplSucc);
}
showMessage(window.siyuan.languages.exportTplSucc);
});
dialog.destroy();
});
Expand Down
Loading

0 comments on commit cd40ec5

Please sign in to comment.