代码:
const { app, BrowserWindow } = require('electron')
const path = require('node:path')
const Context = require('koishi')
const console = require('@koishijs/plugin-console')
const createWindow = () => {
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
// 加载 index.html
mainWindow.loadFile('src/index.html')
// 打开开发工具
// mainWindow.webContents.openDevTools()
}
// 创建一个 Koishi 应用
const ctx = new Context({
port: 5140
})
app.whenReady().then(() => {
createWindow()
// 启用上述插件
ctx.plugin(console) // 提供控制台
// 启动应用
ctx.start()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
错误:
App threw an error during load
TypeError: Context is not a constructor
at Object. (F:\OpenSource\Lanqi-Koishi\main.js:24:13)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions…js (node:internal/modules/cjs/loader:1311:10)
at Module.load (node:internal/modules/cjs/loader:1098:32)
at Module._load (node:internal/modules/cjs/loader:945:12)
at c._load (node:electron/js2c/node_init:2:13672)
at cjsLoader (node:internal/modules/esm/translators:288:17)
at ModuleWrap. (node:internal/modules/esm/translators:234:7)
at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)