Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
df6a404492
6 changed files with 85 additions and 64 deletions
|
@ -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',
|
||||
`<div>数据库文件正在被其他程序锁定。如果你使用了第三方同步盘,请在思源运行期间关闭同步。</div><div>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.</div>`)
|
||||
break
|
||||
case 21:
|
||||
showErrorWindow('⚠️ ' + kernelPort + ' 端口不可用 The port ' + kernelPort + ' is unavailable',
|
||||
'<div>思源需要监听 ' + kernelPort + ' 端口,请确保该端口可用且不是其他程序的保留端口。可尝试使用管理员运行命令:' +
|
||||
'<pre><code>net stop winnat\nnetsh interface ipv4 add excludedportrange protocol=tcp startport=' + kernelPort + ' numberofports=1\nnet start winnat</code></pre></div>' +
|
||||
'<div>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: ' +
|
||||
'<pre><code>net stop winnat\nnetsh interface ipv4 add excludedportrange protocol=tcp startport=' + kernelPort + ' numberofports=1\nnet start winnat</code></pre></div>')
|
||||
break
|
||||
case 22:
|
||||
showErrorWindow(
|
||||
'⚠️ 创建配置目录失败 Failed to create config directory',
|
||||
`<div>思源需要在用户家目录下创建配置文件夹(~/.config/siyuan),请确保该路径具有写入权限。</div><div>SiYuan needs to create a configuration folder (~/.config/siyuan) in the user\'s home directory. Please make sure that the path has write permissions.</div>`)
|
||||
break
|
||||
case 23:
|
||||
showErrorWindow(
|
||||
'⚠️ 无法读写块树文件 Failed to access blocktree file',
|
||||
`<div>块树文件正在被其他程序锁定或者已经损坏,请删除 工作空间/temp/ 文件夹后重启</div><div>The block tree file is being locked by another program or is corrupted, please delete the workspace/temp/ folder and restart.</div>`)
|
||||
break
|
||||
case 0:
|
||||
case 1: // Fatal error
|
||||
break
|
||||
default:
|
||||
showErrorWindow(
|
||||
'⚠️ 内核因未知原因退出 The kernel exited for unknown reasons',
|
||||
`<div>思源内核因未知原因退出 [code=${code}],请尝试重启操作系统后再启动思源。如果该问题依然发生,请检查杀毒软件是否阻止思源内核启动。</div>
|
||||
kernelProcess.on('close', (code) => {
|
||||
if (0 !== code) {
|
||||
writeLog(`kernel exited with code [${code}]`)
|
||||
switch (code) {
|
||||
case 20:
|
||||
showErrorWindow('⚠️ 数据库被锁定 The database is locked',
|
||||
`<div>数据库文件正在被其他程序锁定。如果你使用了第三方同步盘,请在思源运行期间关闭同步。</div><div>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.</div>`)
|
||||
break
|
||||
case 21:
|
||||
showErrorWindow('⚠️ ' + kernelPort + ' 端口不可用 The port ' + kernelPort + ' is unavailable',
|
||||
'<div>思源需要监听 ' + kernelPort + ' 端口,请确保该端口可用且不是其他程序的保留端口。可尝试使用管理员运行命令:' +
|
||||
'<pre><code>net stop winnat\nnetsh interface ipv4 add excludedportrange protocol=tcp startport=' + kernelPort + ' numberofports=1\nnet start winnat</code></pre></div>' +
|
||||
'<div>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: ' +
|
||||
'<pre><code>net stop winnat\nnetsh interface ipv4 add excludedportrange protocol=tcp startport=' + kernelPort + ' numberofports=1\nnet start winnat</code></pre></div>')
|
||||
break
|
||||
case 22:
|
||||
showErrorWindow(
|
||||
'⚠️ 创建配置目录失败 Failed to create config directory',
|
||||
`<div>思源需要在用户家目录下创建配置文件夹(~/.config/siyuan),请确保该路径具有写入权限。</div><div>SiYuan needs to create a configuration folder (~/.config/siyuan) in the user\'s home directory. Please make sure that the path has write permissions.</div>`)
|
||||
break
|
||||
case 23:
|
||||
showErrorWindow(
|
||||
'⚠️ 无法读写块树文件 Failed to access blocktree file',
|
||||
`<div>块树文件正在被其他程序锁定或者已经损坏,请删除 工作空间/temp/ 文件夹后重启</div><div>The block tree file is being locked by another program or is corrupted, please delete the workspace/temp/ folder and restart.</div>`)
|
||||
break
|
||||
case 0:
|
||||
case 1: // Fatal error
|
||||
break
|
||||
default:
|
||||
showErrorWindow(
|
||||
'⚠️ 内核因未知原因退出 The kernel exited for unknown reasons',
|
||||
`<div>思源内核因未知原因退出 [code=${code}],请尝试重启操作系统后再启动思源。如果该问题依然发生,请检查杀毒软件是否阻止思源内核启动。</div>
|
||||
<div>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.</div>`)
|
||||
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')
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"`
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue