-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add esbuild for server middleware
- Loading branch information
Showing
17 changed files
with
569 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,5 @@ | |
"zhi-core", | ||
"siyuan-note", | ||
"theme" | ||
], | ||
"dependencies": { | ||
"express": "^4.18.2" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
#!/bin/sh | ||
ZHI_THEME_DIR=/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi | ||
|
||
## copy dist | ||
cp -r dist/packages/zhi/* $ZHI_THEME_DIR/ | ||
echo "zhi dist copy success" | ||
|
||
## install dependency for zhi | ||
cd $ZHI_THEME_DIR/ || exit | ||
echo "installing zhi dependencies ..." | ||
npm i express compression vite-plugin-ssr --registry=https://registry.npmmirror.com | ||
echo "zhi dependency installed" |
126 changes: 126 additions & 0 deletions
126
packages/zhi-core/src/lib/core/browser-windows/WindowManager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright (c) 2023, Terwer . All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Terwer designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Terwer in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com | ||
* or visit www.terwer.space if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
import ZhiUtil from "../util/ZhiUtil" | ||
|
||
/** | ||
* 窗口管理器 | ||
* | ||
* @author terwer | ||
* @version 1.0.0 | ||
* @since 1.0.0 | ||
*/ | ||
class WindowManager { | ||
private readonly logger | ||
private readonly common | ||
|
||
constructor() { | ||
this.logger = ZhiUtil.zhiLog("window-manager") | ||
this.common = ZhiUtil.zhiCommon() | ||
} | ||
|
||
/** | ||
* 打开新窗口 | ||
* | ||
* 示例: | ||
* | ||
* ``` | ||
* ## development | ||
* windowManager.openBrowserWindow("https://www.baidu.com", undefined, undefined, true, false) | ||
* windowManager.openBrowserWindow("https://www.baidu.com", { "key1": "value1", "key2": "value2" }, undefined, true, false) | ||
* | ||
* ## production | ||
* windowManager.openBrowserWindow("https://www.baidu.com") | ||
* ``` | ||
* | ||
* @param url - url | ||
* @param params - 参数 | ||
* @param win - 父窗口 | ||
* @param isDev - 是否打开开发者工具 | ||
* @param modal - 是否模态 | ||
*/ | ||
public openBrowserWindow(url: string, params?: Record<string, string>, win?: any, isDev = false, modal = false) { | ||
try { | ||
if (this.common.strUtil.isEmptyString(url)) { | ||
this.logger.error("Url cannot be empty") | ||
return | ||
} | ||
|
||
if (!this.common.browserUtil.isElectron()) { | ||
this.logger.info("BrowserWindow can ony be available in siyuan Electron environment") | ||
return | ||
} | ||
|
||
if (params) { | ||
Object.keys(params).forEach((key: string) => { | ||
const value = params[key] | ||
url = this.common.browserUtil.setUrlParameter(url, key, value) | ||
}) | ||
} | ||
|
||
this.logger.info(this.common.strUtil.f("Opening a new BrowserWindow from url => {0}", url)) | ||
|
||
const mainWin = win ?? this.common.siyuanUtil.siyuanWindow() | ||
const { app, BrowserWindow, getCurrentWindow } = mainWin.require("@electron/remote") | ||
const remote = mainWin.require("@electron/remote").require("@electron/remote/main") | ||
const mainWindow = getCurrentWindow() | ||
const newWindow = new BrowserWindow({ | ||
parent: mainWindow, | ||
width: 900, | ||
height: 750, | ||
resizable: true, | ||
modal: modal, | ||
icon: this.common.siyuanUtil.joinPath( | ||
this.common.siyuanUtil.siyuanWindow().siyuan.config.system.appDir, | ||
"stage", | ||
"icon-large.png" | ||
), | ||
titleBarOverlay: { | ||
color: "#cccccca5", | ||
symbolColor: "black", | ||
}, | ||
webPreferences: { | ||
nativeWindowOpen: true, | ||
nodeIntegration: true, | ||
webviewTag: true, | ||
webSecurity: false, | ||
contextIsolation: false, | ||
}, | ||
}) | ||
|
||
newWindow.webContents.userAgent = `SiYuan/${app.getVersion()} https://b3log.org/siyuan Electron` | ||
// 允许 | ||
remote.enable(newWindow.webContents) | ||
if (isDev) { | ||
newWindow.webContents.openDevTools() | ||
} | ||
newWindow.loadURL(url) | ||
} catch (e) { | ||
this.logger.error("Open browser window failed", e) | ||
} | ||
} | ||
} | ||
|
||
export default WindowManager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) 2023, Terwer . All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Terwer designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Terwer in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com | ||
* or visit www.terwer.space if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
import DependencyItem from "../../models/DependencyItem" | ||
import ZhiUtil from "../util/ZhiUtil" | ||
import WindowManager from "./WindowManager" | ||
|
||
/** | ||
* 这里统一挂载一个方法,可以打开 Electron 的 BrowserWindow | ||
*/ | ||
class ZhiBrowserWindow { | ||
private readonly logger | ||
private readonly common | ||
|
||
private windowManager | ||
|
||
constructor() { | ||
this.logger = ZhiUtil.zhiLog("zhi-browser-window") | ||
this.common = ZhiUtil.zhiCommon() | ||
|
||
this.windowManager = new WindowManager() | ||
} | ||
|
||
/** | ||
* 挂载 BrowserWindow | ||
* | ||
* @author terwer | ||
* @since 1.0.0 | ||
*/ | ||
public async initBrowserWindow(): Promise<DependencyItem[]> { | ||
this.logger.info("Init windowManager") | ||
this.common.siyuanUtil.siyuanWindow().windowManager = this.windowManager | ||
this.logger.info("WindowManager inited", this.common.siyuanUtil.siyuanWindow().windowManager) | ||
return Promise.resolve([]) | ||
} | ||
} | ||
|
||
export default ZhiBrowserWindow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright (c) 2023, Terwer . All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Terwer designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Terwer in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com | ||
* or visit www.terwer.space if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
// import child_process from "child_process"; | ||
// | ||
// const { exec } = require('child_process'); | ||
// | ||
// function runCommand(command) { | ||
// return new Promise((resolve, reject) => { | ||
// exec(command, (error, stdout, stderr) => { | ||
// if (error) { | ||
// reject(error); | ||
// } else { | ||
// resolve(stdout.trim()); | ||
// } | ||
// }); | ||
// }); | ||
// } | ||
// | ||
// // 调用示例:执行 ls 命令,并输出其结果 | ||
// runCommand('/Users/terwer/Downloads/n/node_modules/.bin/next -v').then((result) => { | ||
// console.log(result); | ||
// }).catch((error) => { | ||
// console.error(error); | ||
// }); | ||
// | ||
// class CustomCmd { | ||
// init(){ | ||
// const { spawn } = require('child_process'); | ||
// const path = require('path'); | ||
// | ||
// async function executeCommand(command, args = [], options = {}) { | ||
// return new Promise((resolve, reject) => { | ||
// const childProcess = spawn(command, args, options); | ||
// | ||
// let stdout = ''; | ||
// let stderr = ''; | ||
// | ||
// childProcess.stdout.on('data', (data) => { | ||
// stdout += data.toString(); | ||
// }); | ||
// | ||
// childProcess.stderr.on('data', (data) => { | ||
// stderr += data.toString(); | ||
// }); | ||
// | ||
// childProcess.on('close', (code) => { | ||
// if (code === 0) { | ||
// resolve(stdout); | ||
// } else { | ||
// reject(new Error(stderr)); | ||
// } | ||
// }); | ||
// | ||
// childProcess.on('error', (error) => { | ||
// reject(error); | ||
// }); | ||
// }); | ||
// } | ||
// | ||
// const baseDir = "/Users/terwer/Downloads/n" | ||
// const pathToBinary = path.join(baseDir, "node_modules", ".bin", "next") | ||
// const args = ['-v']; | ||
// const options = { | ||
// env: { | ||
// ELECTRON_RUN_AS_NODE: 1, | ||
// }, | ||
// }; | ||
// | ||
// executeCommand(pathToBinary, args, options) | ||
// .then((stdout) => { | ||
// console.log(`Command output: ${stdout}`); | ||
// }) | ||
// .catch((error) => { | ||
// console.error(`Command failed: ${error.message}`); | ||
// }); | ||
// } | ||
// } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) 2023, Terwer . All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Terwer designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Terwer in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com | ||
* or visit www.terwer.space if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
Oops, something went wrong.