diff --git a/app/electron/main.js b/app/electron/main.js
index 644160da1..9d99d192c 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -526,68 +526,72 @@ const initKernel = (initData) => {
return
}
- let cmd = `ui version [${appVer}], booting kernel [${kernelPath} --wd=${appDir}]`
const cmds = ['--wd', appDir]
cmds.push('--resident', 'false')
if (isDevEnv) {
cmds.push('--mode', 'dev')
+ cmds.push('--port', '6806')
}
if (initData) {
const initDatas = initData.split('-')
cmds.push('--workspace', initDatas[0])
cmds.push('--lang', initDatas[1])
- cmd = `ui version [${appVer}], booting kernel [${kernelPath} --wd=${appDir} --workspace=${initDatas[0]} --lang=${initDatas[1]}]`
}
+ let cmd = `ui version [${appVer}], booting kernel [${kernelPath} ${cmds.join(' ')}]`
writeLog(cmd)
- const cp = require('child_process')
- const kernelProcess = cp.spawn(kernelPath,
- cmds, {
- detached: false, // 桌面端内核进程不再以游离模式拉起 https://github.com/siyuan-note/siyuan/issues/6336
- stdio: 'ignore',
- },
- )
- writeLog('booted kernel process [pid=' + kernelProcess.pid + ']')
+ let kernelProcessPid = ""
+ if (!isDevEnv) {
+ const cp = require('child_process')
+ const kernelProcess = cp.spawn(kernelPath,
+ cmds, {
+ detached: false, // 桌面端内核进程不再以游离模式拉起 https://github.com/siyuan-note/siyuan/issues/6336
+ stdio: 'ignore',
+ },
+ )
+ kernelProcessPid = kernelProcess.pid
+ writeLog('booted kernel process [pid=' + kernelProcessPid + ']')
- kernelProcess.on('close', (code) => {
- if (0 !== code) {
- writeLog(`kernel exited with code [${code}]`)
- switch (code) {
- case 20:
- showErrorWindow('⚠️ 数据库被锁定 The database is locked',
- `
数据库文件正在被其他程序锁定。如果你使用了第三方同步盘,请在思源运行期间关闭同步。
The database file is being locked by another program. If you use a third-party sync disk, please turn off sync while SiYuan is running.
`)
- break
- case 21:
- showErrorWindow('⚠️ ' + kernelPort + ' 端口不可用 The port ' + kernelPort + ' is unavailable',
- '思源需要监听 ' + kernelPort + ' 端口,请确保该端口可用且不是其他程序的保留端口。可尝试使用管理员运行命令:' +
- '
net stop winnat\nnetsh interface ipv4 add excludedportrange protocol=tcp startport=' + kernelPort + ' numberofports=1\nnet start winnat
' +
- 'SiYuan needs to listen to port ' + kernelPort + ', please make sure this port is available, and not a reserved port by other software. Try running the command as an administrator: ' +
- '
net stop winnat\nnetsh interface ipv4 add excludedportrange protocol=tcp startport=' + kernelPort + ' numberofports=1\nnet start winnat
')
- break
- case 22:
- showErrorWindow(
- '⚠️ 创建配置目录失败 Failed to create config directory',
- `思源需要在用户家目录下创建配置文件夹(~/.config/siyuan),请确保该路径具有写入权限。
SiYuan needs to create a configuration folder (~/.config/siyuan) in the user\'s home directory. Please make sure that the path has write permissions.
`)
- break
- case 23:
- showErrorWindow(
- '⚠️ 无法读写块树文件 Failed to access blocktree file',
- `块树文件正在被其他程序锁定或者已经损坏,请删除 工作空间/temp/ 文件夹后重启
The block tree file is being locked by another program or is corrupted, please delete the workspace/temp/ folder and restart.
`)
- break
- case 0:
- case 1: // Fatal error
- break
- default:
- showErrorWindow(
- '⚠️ 内核因未知原因退出 The kernel exited for unknown reasons',
- `思源内核因未知原因退出 [code=${code}],请尝试重启操作系统后再启动思源。如果该问题依然发生,请检查杀毒软件是否阻止思源内核启动。
+ kernelProcess.on('close', (code) => {
+ if (0 !== code) {
+ writeLog(`kernel exited with code [${code}]`)
+ switch (code) {
+ case 20:
+ showErrorWindow('⚠️ 数据库被锁定 The database is locked',
+ `数据库文件正在被其他程序锁定。如果你使用了第三方同步盘,请在思源运行期间关闭同步。
The database file is being locked by another program. If you use a third-party sync disk, please turn off sync while SiYuan is running.
`)
+ break
+ case 21:
+ showErrorWindow('⚠️ ' + kernelPort + ' 端口不可用 The port ' + kernelPort + ' is unavailable',
+ '思源需要监听 ' + kernelPort + ' 端口,请确保该端口可用且不是其他程序的保留端口。可尝试使用管理员运行命令:' +
+ '
net stop winnat\nnetsh interface ipv4 add excludedportrange protocol=tcp startport=' + kernelPort + ' numberofports=1\nnet start winnat
' +
+ 'SiYuan needs to listen to port ' + kernelPort + ', please make sure this port is available, and not a reserved port by other software. Try running the command as an administrator: ' +
+ '
net stop winnat\nnetsh interface ipv4 add excludedportrange protocol=tcp startport=' + kernelPort + ' numberofports=1\nnet start winnat
')
+ break
+ case 22:
+ showErrorWindow(
+ '⚠️ 创建配置目录失败 Failed to create config directory',
+ `思源需要在用户家目录下创建配置文件夹(~/.config/siyuan),请确保该路径具有写入权限。
SiYuan needs to create a configuration folder (~/.config/siyuan) in the user\'s home directory. Please make sure that the path has write permissions.
`)
+ break
+ case 23:
+ showErrorWindow(
+ '⚠️ 无法读写块树文件 Failed to access blocktree file',
+ `块树文件正在被其他程序锁定或者已经损坏,请删除 工作空间/temp/ 文件夹后重启
The block tree file is being locked by another program or is corrupted, please delete the workspace/temp/ folder and restart.
`)
+ break
+ case 0:
+ case 1: // Fatal error
+ break
+ default:
+ showErrorWindow(
+ '⚠️ 内核因未知原因退出 The kernel exited for unknown reasons',
+ `思源内核因未知原因退出 [code=${code}],请尝试重启操作系统后再启动思源。如果该问题依然发生,请检查杀毒软件是否阻止思源内核启动。
SiYuan Kernel exited for unknown reasons [code=${code}], please try to reboot your operating system and then start SiYuan again. If occurs this problem still, please check your anti-virus software whether kill the SiYuan Kernel.
`)
- break
- }
+ break
+ }
- bootWindow.destroy()
- resolve(false)
- }
- })
+ bootWindow.destroy()
+ resolve(false)
+ }
+ })
+ }
const sleep = (ms) => {
return new Promise(resolve => setTimeout(resolve, ms))
@@ -604,7 +608,7 @@ const initKernel = (initData) => {
while (!gotPort) {
try {
const portJSON = JSON.parse(fs.readFileSync(portJSONPath, 'utf8'))
- const ret = portJSON[kernelProcess.pid.toString()]
+ const ret = portJSON[kernelProcessPid]
if (ret) {
gotPort = true
return ret
@@ -615,7 +619,7 @@ const initKernel = (initData) => {
} finally {
count++
if (64 < count) {
- writeLog('get kernel port failed [pid=' + kernelProcess.pid + ']')
+ writeLog('get kernel port failed [pid=' + kernelProcessPid + ']')
bootWindow.destroy()
resolve(false)
}
@@ -640,10 +644,10 @@ const initKernel = (initData) => {
bootWindow.show()
} catch (e) {
writeLog('get kernel version failed: ' + e.message)
- await sleep(200)
+ await sleep(100)
} finally {
count++
- if (64 < count) {
+ if (14 < count) {
writeLog('get kernel ver failed')
bootWindow.destroy()
resolve(false)
@@ -800,6 +804,7 @@ app.on('before-quit', (event) => {
})
const {powerMonitor} = require('electron')
+const cp = require("child_process");
powerMonitor.on('suspend', () => {
writeLog('system suspend')
diff --git a/kernel/api/system.go b/kernel/api/system.go
index d3035d6ca..a3cb09908 100644
--- a/kernel/api/system.go
+++ b/kernel/api/system.go
@@ -295,7 +295,7 @@ func setFixedPort(c *gin.Context) {
}
fixedPort := arg["fixedPort"].(bool)
- model.Conf.FixedPort = fixedPort
+ model.Conf.System.FixedPort = fixedPort
model.Conf.Save()
util.PushMsg(model.Conf.Language(42), 1000*15)
diff --git a/kernel/conf/system.go b/kernel/conf/system.go
index 1a6dc85e9..08808ba0e 100644
--- a/kernel/conf/system.go
+++ b/kernel/conf/system.go
@@ -34,7 +34,8 @@ type System struct {
ConfDir string `json:"confDir"`
DataDir string `json:"dataDir"`
- NetworkServe bool `json:"networkServe"`
+ NetworkServe bool `json:"networkServe"` // 是否开启网络伺服
+ FixedPort bool `json:"fixedPort"` // 是否使用固定端口 6806
NetworkProxy *NetworkProxy `json:"networkProxy"`
UploadErrLog bool `json:"uploadErrLog"`
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index 49109d524..f652a94ec 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -60,7 +60,6 @@ type AppConf struct {
User *conf.User `json:"-"` // 社区用户内存结构,不持久化
Account *conf.Account `json:"account"` // 帐号配置
ReadOnly bool `json:"readonly"` // 是否是以只读模式运行
- FixedPort bool `json:"fixedPort"` // 是否使用固定端口 6806
LocalIPs []string `json:"localIPs"` // 本地 IP 列表
AccessAuthCode string `json:"accessAuthCode"` // 访问授权码
System *conf.System `json:"system"` // 系统配置
@@ -273,7 +272,10 @@ func InitConf() {
}
if util.ContainerStd != util.Container {
- Conf.FixedPort = true
+ Conf.System.FixedPort = true
+ }
+ if Conf.System.FixedPort {
+ util.ServerPort = util.FixedPort
}
Conf.LocalIPs = util.GetLocalIPs()
diff --git a/kernel/util/working.go b/kernel/util/working.go
index 9f188a9b8..f5dba1705 100644
--- a/kernel/util/working.go
+++ b/kernel/util/working.go
@@ -61,8 +61,8 @@ func Boot() {
servePath := flag.String("servePath", "", "obsoleted https://github.com/siyuan-note/siyuan/issues/4647")
_ = servePath
port := flag.String("port", "0", "port of the HTTP server")
- resident := flag.Bool("resident", true, "resident memory even if no active session")
- readOnly := flag.Bool("readonly", false, "read-only mode")
+ resident := flag.String("resident", "true", "resident memory even if no active session")
+ readOnly := flag.String("readonly", "false", "read-only mode")
accessAuthCode := flag.String("accessAuthCode", "", "access auth code")
ssl := flag.Bool("ssl", false, "for https and wss")
lang := flag.String("lang", "", "zh_CN/zh_CHT/en_US/fr_FR/es_ES")
@@ -76,17 +76,17 @@ func Boot() {
Lang = *lang
}
Mode = *mode
- Resident = *resident
+ Resident, _ = strconv.ParseBool(*resident)
ServerPort = *port
- if isRunningInDockerContainer() || "dev" == Mode {
- ServerPort = "6806"
- }
- ReadOnly = *readOnly
+ ReadOnly, _ = strconv.ParseBool(*readOnly)
AccessAuthCode = *accessAuthCode
Container = ContainerStd
if isRunningInDockerContainer() {
Container = ContainerDocker
}
+ if ContainerStd != Container || "dev" == Mode {
+ ServerPort = FixedPort
+ }
msStoreFilePath := filepath.Join(WorkingDir, "ms-store")
ISMicrosoftStore = gulu.File.IsExist(msStoreFilePath)
@@ -291,6 +291,8 @@ const (
ContainerDocker = "docker" // Docker 容器端
ContainerAndroid = "android" // Android 端
ContainerIOS = "ios" // iOS 端
+
+ FixedPort = "6806" // 固定端口
)
func initPathDir() {
@@ -333,6 +335,17 @@ func initMime() {
mime.AddExtensionType(".js", "application/x-javascript")
mime.AddExtensionType(".json", "application/json")
mime.AddExtensionType(".html", "text/html")
+
+ // 某些系统上下载资源文件后打开是 zip
+ // https://github.com/siyuan-note/siyuan/issues/6347
+ mime.AddExtensionType(".doc", "application/msword")
+ mime.AddExtensionType(".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
+ mime.AddExtensionType(".xls", "application/vnd.ms-excel")
+ mime.AddExtensionType(".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
+ mime.AddExtensionType(".dwg", "image/x-dwg")
+ mime.AddExtensionType(".dxf", "image/x-dxf")
+ mime.AddExtensionType(".dwf", "drawing/x-dwf")
+ mime.AddExtensionType(".pdf", "application/pdf")
}
func KillByPort(port string) {
diff --git a/kernel/util/working_mobile.go b/kernel/util/working_mobile.go
index 82ae0c789..0f98a2dc4 100644
--- a/kernel/util/working_mobile.go
+++ b/kernel/util/working_mobile.go
@@ -61,7 +61,7 @@ func BootMobile(container, appDir, workspaceDir, nativeLibDir, privateDataDir, l
ThemesPath = filepath.Join(AppearancePath, "themes")
IconsPath = filepath.Join(AppearancePath, "icons")
Resident = true
- ServerPort = "6806"
+ ServerPort = FixedPort
Container = container
UserAgent = UserAgent + " " + Container
httpclient.SetUserAgent(UserAgent)