Skip to content

Commit

Permalink
♻️
Browse files Browse the repository at this point in the history
  • Loading branch information
Soltus committed Mar 22, 2024
1 parent 53c5132 commit a72cafa
Show file tree
Hide file tree
Showing 39 changed files with 203 additions and 163 deletions.
9 changes: 5 additions & 4 deletions app/electron/error.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Error - SiYuan</title>
<title>Error - Sillot</title>
<meta charset="UTF-8">
<style>
body {
Expand Down Expand Up @@ -145,9 +145,10 @@ <h2 id="title"></h2>
<div id="content"></div>
<div class="fn__flex-1"></div>
<div class="feedback">
<span>🧡 <a href="https://github.com/siyuan-note/siyuan/issues" target="_blank">SiYuan-Note Issues</a></span>
<span>🧡 <a href="https://github.com/siyuan-note/siyuan/issues" target="_blank">SiYuan Issues</a></span>
<span>💜 <a href="https://github.com/Hi-Windom/Sillot/issues" target="_blank">Sillot Issues</a></span>
<span><a href="https://github.com/Hi-Windom/Sillot/releases" target="_blank" class="version"></a></span>
<span><div id="openAppLogFolder" onclick="javascript:ipcRenderer.send('siyuan-open-folder', 'openAppLogFolder');" style="color: #1f5ab3;">📁 App Log Folder</div></span>
<span><div id="openWorkspacesLogFolder" onclick="javascript:ipcRenderer.send('siyuan-open-folder', 'openWorkspacesLogFolder');" style="color: #1f5ab3;">🗂️ Workspaces Log Folder</div></span>
</div>
<div class="fn__flex-1"></div>
</div>
Expand Down Expand Up @@ -177,7 +178,7 @@ <h2 id="title"></h2>
}

(() => {
document.querySelector('#icon').innerHTML = `<img src="${decodeURIComponent(getSearch('icon'))}"> SiYuan v${getSearch('v')}`
document.querySelector('#icon').innerHTML = `<img src="${decodeURIComponent(getSearch('icon'))}"> Sillot v${getSearch('v')}`

document.getElementById('title').innerHTML = decodeURIComponent(getSearch('title'))
document.getElementById('content').innerHTML = decodeURIComponent(getSearch('content'))
Expand Down
4 changes: 2 additions & 2 deletions app/electron/init.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>SiYuan</title>
<title>Sillot</title>
<meta charset="UTF-8">
<style>
body {
Expand Down Expand Up @@ -356,7 +356,7 @@ <h2 class="BBN">汐洛 - Sillot</h2>
const path = require('path')
const fs = require('fs')

const defaultWorkspace = path.join(decodeURIComponent(getSearch('home')), "SiYuan")
const defaultWorkspace = path.join(decodeURIComponent(getSearch('home')), "Sillot")
if (!fs.existsSync(defaultWorkspace)) {
fs.mkdirSync(defaultWorkspace, {mode: 0o755, recursive: true})
}
Expand Down
21 changes: 18 additions & 3 deletions app/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ const remote = require("@electron/remote/main");
process.noAsar = true;
const appDir = path.dirname(app.getAppPath());
const isDevEnv = process.env.NODE_ENV === "development";
const appVer = app.getVersion();
// const branchVer = app.getVersion();
let appVer = app.getVersion();
try { require("electron-reloader")(module); } catch {}

let pkg = {};
if (isDevEnv) {
pkg = JSON.parse(fs.readFileSync(path.join(appDir, "package.json")).toString());
if (pkg.version) { appVer = pkg.version;}
} else {
pkg = JSON.parse(fs.readFileSync(path.join(appDir, "app", "package.json")).toString());
}
Expand All @@ -70,7 +70,7 @@ try {
}
} catch (e) {
console.error(e);
require("electron").dialog.showErrorBox("创建配置目录失败 Failed to create config directory", "思源需要在用户家目录下创建配置文件夹(~/.config/siyuan),请确保该路径具有写入权限。\n\nSiYuan needs to create a configuration folder (~/.config/siyuan) in the user's home directory. Please make sure that the path has write permissions.");
require("electron").dialog.showErrorBox("创建配置目录失败 Failed to create config directory", "思源(汐洛)需要在用户家目录下创建配置文件夹(~/.config/sillot),请确保该路径具有写入权限。\n\nSiYuan needs to create a configuration folder (~/.config/sillot) in the user's home directory. Please make sure that the path has write permissions.");
app.exit();
}

Expand Down Expand Up @@ -203,6 +203,11 @@ const showErrorWindow = (title, content) => {
icon: path.join(appDir, "stage", "icon-large.png"),
},
});
errWindow.webContents.on('did-finish-load', () => {
errWindow.webContents.executeJavaScript(`
const { ipcRenderer } = require('electron');
`);
});
errWindow.show();
return errWindow.id;
};
Expand Down Expand Up @@ -775,6 +780,16 @@ app.whenReady().then(() => {
};

ipcMain.on("siyuan-open-folder", (event, filePath) => {
if (filePath === "openAppLogFolder") {
filePath = path.join(confDir, "app.log");
}
if (filePath === "openWorkspacesLogFolder") {
let ws = JSON.parse(fs.readFileSync(path.join(confDir, "workspace.json")).toString());
ws.forEach((workspacePath) => {
shell.showItemInFolder(path.join(workspacePath, "temp", "siyuan.log"));
});
return;
}
shell.showItemInFolder(filePath);
});
ipcMain.on("siyuan-first-quit", () => {
Expand Down
6 changes: 4 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sillot",
"version": "0.27.21",
"version": "0.27.22",
"syv": "3.0.5",
"sypv": "3.0.4",
"description": "Build Your Eternal Digital Garden",
Expand All @@ -17,6 +17,8 @@
"v": "pnpm version && echo '\npnpm:' && pnpm -v && echo '\n'",
"git:tag": "git push origin --tags",
"git:proxy": "git config --global http.proxy http://127.0.0.1:7890 && git config --global https.proxy http://127.0.0.1:7890",
"link:sofill": "pnpm install ../../sofillBuilder/out -D && echo '仅用于开发调试,推送前请恢复'",
"unlink:sofill": "pnpm uninstall sofill && pnpm i sofill -D",
"check": "NPM_CHECK_INSTALLER=pnpm npm-check -u",
"check:electron": "pnpm install electron@alpha",
"gentpl": "echo '危险操作警告:生成替换前请确认版本合并冲突已解决' && pause && pnpm run '/gentpl:.*/'",
Expand Down Expand Up @@ -154,7 +156,7 @@
"sass-loader": "^14.1.1",
"shelljs": "^0.8.5",
"socket.io": "^4.7.5",
"sofill": "^1.0.76",
"sofill": "^1.1.4",
"sout": "^1.1.0",
"style-loader": "^3.3.4",
"sweetalert2": "^11.10.6",
Expand Down
10 changes: 5 additions & 5 deletions app/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/src/asset/renderAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {getAllModels} from "../layout/getAll";
/// #endif
import {pathPosix} from "../util/pathName";
// import * as dayjs from "dayjs";
import {format} from "date-fns";
import {formatDate} from "sofill/mid";

export const renderAssetsPreview = (pathString: string) => {
if (!pathString) {
Expand Down Expand Up @@ -63,15 +63,15 @@ export const pdfResize = () => {
export const genAssetHTML = (type: string, pathString: string, imgName: string, linkName: string) => {
let html = "";
if (Constants.SIYUAN_ASSETS_AUDIO.includes(type)) {
html = `<div data-node-id="${Lute.NewNodeID()}" data-type="NodeAudio" class="iframe" updated="${format(new Date(), 'yyyyMMddHHmmss')}"><div class="iframe-content"><audio controls="controls" src="${pathString}" data-src="${pathString}"></audio>${Constants.ZWSP}</div><div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div></div>`;
html = `<div data-node-id="${Lute.NewNodeID()}" data-type="NodeAudio" class="iframe" updated="${formatDate(new Date(), 'yyyyMMddHHmmss')}"><div class="iframe-content"><audio controls="controls" src="${pathString}" data-src="${pathString}"></audio>${Constants.ZWSP}</div><div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div></div>`;
} else if (Constants.SIYUAN_ASSETS_IMAGE.includes(type)) {
let netHTML = "";
if (!pathString.startsWith("assets/")) {
netHTML = '<span class="img__net"><svg><use xlink:href="#iconLanguage"></use></svg></span>';
}
html = `<span contenteditable="false" data-type="img" class="img"><span> </span><span><span class="protyle-action protyle-icons"><span class="protyle-icon protyle-icon--only"><svg><use xlink:href="#iconMore"></use></svg></span></span><img src="${pathString}" data-src="${pathString}" alt="${imgName}" /><span class="protyle-action__drag"></span>${netHTML}<span class="protyle-action__title"></span></span><span> </span></span>`;
} else if (Constants.SIYUAN_ASSETS_VIDEO.includes(type)) {
html = `<div data-node-id="${Lute.NewNodeID()}" data-type="NodeVideo" class="iframe" updated="${format(new Date(), 'yyyyMMddHHmmss')}"><div class="iframe-content">${Constants.ZWSP}<video controls="controls" src="${pathString}" data-src="${pathString}"></video><span class="protyle-action__drag" contenteditable="false"></span></div><div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div></div>`;
html = `<div data-node-id="${Lute.NewNodeID()}" data-type="NodeVideo" class="iframe" updated="${formatDate(new Date(), 'yyyyMMddHHmmss')}"><div class="iframe-content">${Constants.ZWSP}<video controls="controls" src="${pathString}" data-src="${pathString}"></video><span class="protyle-action__drag" contenteditable="false"></span></div><div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div></div>`;
} else {
html = `<span data-type="a" data-href="${pathString}">${linkName}</span>`;
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/boot/globalEvent/keydown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import {historyKeydown} from "../../history/keydown";
import {zoomOut} from "../../menus/protyle";
import {openSearchAV} from "../../protyle/render/av/relation";
// import * as dayjs from "dayjs";
import {format} from "date-fns";
import {formatDate} from "sofill/mid";

const switchDialogEvent = (app: App, event: MouseEvent) => {
event.preventDefault();
Expand Down Expand Up @@ -323,7 +323,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
}, {
action: "doUpdateUpdated",
id: listItemElement.dataset.nodeId,
data: format(new Date(), 'yyyyMMddHHmmss'),
data: formatDate(new Date(), 'yyyyMMddHHmmss'),
}], [{
action: "removeAttrViewBlock",
srcIDs: sourceIds,
Expand Down Expand Up @@ -357,7 +357,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
}, {
action: "doUpdateUpdated",
id: listItemElement.dataset.blockId,
data: format(new Date(), 'yyyyMMddHHmmss'),
data: formatDate(new Date(), 'yyyyMMddHHmmss'),
}], [{
action: "removeAttrViewBlock",
srcIDs: sourceIds,
Expand Down
6 changes: 3 additions & 3 deletions app/src/card/openCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {escapeHtml} from "../util/escape";
import {openFile} from "../editor/util";
/// #endif
// import * as dayjs from "dayjs";
import {format} from "date-fns";
import {formatDate} from "sofill/mid";
import {getDisplayName, movePathTo} from "../util/pathName";
import {App} from "../index";
import {resize} from "../protyle/util/resize";
Expand Down Expand Up @@ -311,7 +311,7 @@ export const bindCardEvent = async (options: {
fetchPost("/api/riff/batchSetRiffCardsDueTime", {
cardDues: [{
id: currentCard.cardID,
due: format(parseInt(inputElement.value) * 1000, 'yyyyMMddHHmmss')
due: formatDate(parseInt(inputElement.value) * 1000, 'yyyyMMddHHmmss')
}]
}, () => {
actionElements[0].classList.add("fn__none");
Expand Down Expand Up @@ -401,7 +401,7 @@ export const bindCardEvent = async (options: {
</div><div class="fn__flex${currentCard.lastReview > 0 ? "" : " fn__none"}">
<div class="fn__flex-1">${window.siyuan.languages.lastReviewTime}</div>
<div class="fn__space"></div>
<div>${dayjs(currentCard.lastReview).format("YYYY-MM-DD")}</div>
<div>${formatDate(new Date(currentCard.lastReview), 'yyyy-MM-dd')}</div>
</div>`,
});
/// #if MOBILE
Expand Down
8 changes: 4 additions & 4 deletions app/src/card/viewCards.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {format} from "date-fns";
import {formatDate} from "sofill/mid";
import {Protyle} from "../protyle";
import {fetchPost} from "../util/fetch";
import {Dialog} from "../dialog";
Expand Down Expand Up @@ -171,7 +171,7 @@ export const viewCards = (app: App, deckID: string, title: string, deckType: "Tr
id: deckID,
blockIDs: [target.getAttribute("data-id")],
}, () => {
target.parentElement.querySelector(".ariaLabel.b3-list-item__meta").textContent = format(new Date(), 'yyyy-MM-dd');
target.parentElement.querySelector(".ariaLabel.b3-list-item__meta").textContent = formatDate(new Date(), 'yyyy-MM-dd');
});
event.stopPropagation();
event.preventDefault();
Expand All @@ -185,7 +185,7 @@ export const viewCards = (app: App, deckID: string, title: string, deckType: "Tr
id: deckID,
}, () => {
dialog.element.querySelectorAll(".ariaLabel.b3-list-item__meta").forEach(item => {
item.textContent = format(new Date(), 'yyyy-MM-dd');
item.textContent = formatDate(new Date(), 'yyyy-MM-dd');
});
});
});
Expand Down Expand Up @@ -260,7 +260,7 @@ ${unicode2Emoji(item.ial.icon, "b3-list-item__graphic", true)}
<span class="b3-list-item__text">${item.content || Constants.ZWSP}</span>
<span class="${(isMobile() || !hPath) ? "fn__none " : ""}b3-list-item__meta b3-list-item__meta--ellipsis" title="${escapeAttr(hPath)}">${escapeHtml(hPath)}</span>
<span data-position="parentE" aria-label="${window.siyuan.languages.revisionCount}" class="ariaLabel counter${item.riffCard?.reps === 0 ? " fn__none" : ""}">${item.riffCard?.reps}</span>
<span data-position="parentE" aria-label="${window.siyuan.languages.nextDue}" class="ariaLabel b3-list-item__meta${!item.riffCard?.due ? " fn__none" : ""}">${format(new Date(item.riffCard?.due), 'yyyy-MM-dd')}</span>
<span data-position="parentE" aria-label="${window.siyuan.languages.nextDue}" class="ariaLabel b3-list-item__meta${!item.riffCard?.due ? " fn__none" : ""}">${formatDate(new Date(item.riffCard?.due), 'yyyy-MM-dd')}</span>
<span data-position="parentE" data-type="reset" data-id="${item.id}" class="b3-list-item__action ariaLabel" aria-label="${window.siyuan.languages.reset}">
<svg><use xlink:href="#iconUndo"></use></svg>
</span>
Expand Down
21 changes: 21 additions & 0 deletions app/src/dialog/processSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,28 @@ export const kernelError = () => {
}
};

// 在退出时禁用整个 HTML 页面的交互
function disableInteractions() {
// 创建一个遮罩层
const overlay = document.createElement('div');
overlay.style.position = 'fixed';
overlay.style.top = '0';
overlay.style.left = '0';
overlay.style.width = '100%';
overlay.style.height = '100%';
overlay.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
overlay.style.zIndex = '9999'; // 确保在最上层
document.body.appendChild(overlay);

// 禁用遮罩层上的点击事件
overlay.addEventListener('click', (event) => {
event.preventDefault();
event.stopPropagation();
});
}

export const exitSiYuan = () => {
disableInteractions();
exportIDB().then(() => {
hideAllElements(["util"]);
/// #if MOBILE
Expand Down
14 changes: 7 additions & 7 deletions app/src/history/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {disabledProtyle, onGet} from "../protyle/util/onGet";
import {hasClosestByClassName} from "../protyle/util/hasClosest";
import {escapeAttr, escapeHtml} from "../util/escape";
// import * as dayjs from "dayjs";
import {format} from "date-fns";
import {formatDate} from "sofill/mid";
import {isMobile} from "../util/functions";
import {App} from "../index";
import {pathPosix} from "../util/pathName";
Expand Down Expand Up @@ -102,7 +102,7 @@ const renderCompare = (app: App, element: HTMLElement) => {
action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML],
});
}
leftElement.querySelector(".history__date").textContent = format(new Date(response.data.updated), 'yyyy-MM-dd HH:mm');
leftElement.querySelector(".history__date").textContent = formatDate(new Date(response.data.updated), 'yyyy-MM-dd HH:mm');
});
const id2 = element.getAttribute("data-id2");
if (id2) {
Expand Down Expand Up @@ -131,7 +131,7 @@ const renderCompare = (app: App, element: HTMLElement) => {
action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML],
});
}
rightElement.querySelector(".history__date").textContent = format(new Date(response.data.updated), 'yyyy-MM-dd HH:mm');
rightElement.querySelector(".history__date").textContent = formatDate(new Date(response.data.updated), 'yyyy-MM-dd HH:mm');
});
} else {
rightElement.classList.add("fn__none");
Expand Down Expand Up @@ -216,13 +216,13 @@ const genHTML = (left: string, right: string, dialog: Dialog, direct: string) =>
<span class="fn__flex-1"></span>
<code class="fn__code${isPhone ? " fn__none" : ""}" data-snapshot="${left}">${left.substring(0, 7)}</code>
${isPhone ? "" : '<span class="fn__space"></span>'}
${format(new Date(response.data.left.created), 'yyyy-MM-dd HH:mm')}
${formatDate(new Date(response.data.left.created), 'yyyy-MM-dd HH:mm')}
<span class="fn__space"></span>
<span class="block__icon block__icon--show b3-tooltips b3-tooltips__s" aria-label="${window.siyuan.languages.switchDirect}" data-direct="${direct}"><svg><use xlink:href="#iconScrollHoriz"></use></svg></span>
<span class="fn__space"></span>
<code class="fn__code${isPhone ? " fn__none" : ""}" data-snapshot="${right}">${right.substring(0, 7)}</code>
${isPhone ? "" : '<span class="fn__space"></span>'}
${format(new Date(response.data.right.created), 'yyyy-MM-dd HH:mm')}
${formatDate(new Date(response.data.right.created), 'yyyy-MM-dd HH:mm')}
<span class="fn__flex-1"></span>
</div>`;
headElement.nextElementSibling.innerHTML = `<div class="fn__flex history__panel" style="height: 100%">
Expand Down Expand Up @@ -260,13 +260,13 @@ const genHTML = (left: string, right: string, dialog: Dialog, direct: string) =>
</div>
<div class="fn__flex-1 fn__flex">
<div class="fn__none fn__flex-1 fn__flex-column">
<div class="history__date">${format(response.data.left.created, 'yyyy-MM-dd HH:mm')}</div>
<div class="history__date">${formatDate(response.data.left.created, 'yyyy-MM-dd HH:mm')}</div>
<div class="ft__center"></div>
<textarea class="history__text fn__none fn__flex-1" readonly></textarea>
<div class="fn__flex-1"></div>
</div>
<div class="fn__none fn__flex-1 fn__flex-column" style="border-left: 1px solid var(--b3-border-color);">
<div class="history__date">${format(response.data.right.created, 'yyyy-MM-dd HH:mm')}</div>
<div class="history__date">${formatDate(response.data.right.created, 'yyyy-MM-dd HH:mm')}</div>
<div class="ft__center"></div>
<textarea class="history__text fn__none fn__flex-1" readonly></textarea>
<div class="fn__flex-1"></div>
Expand Down
Loading

0 comments on commit a72cafa

Please sign in to comment.