Vanessa 2023-11-09 10:20:31 +08:00
parent 311f182009
commit fcdc2f8718

View file

@ -418,120 +418,124 @@
<div class="b3-snackbar__content"></div>
</div>
<script>
if ({{.appearanceModeOS}} && window.matchMedia('(prefers-color-scheme: dark)').matches || {{.appearanceMode}} === 1) {
document.body.classList.add('dark')
}
if (window.location.hostname !== 'localhost' && window.location.hostname !== '127.0.0.1') {
document.querySelector('.b3-button--white').remove()
}
try {
const {ipcRenderer} = require('electron')
ipcRenderer.on('siyuan-save-close', (event, close) => {
exitSiYuan()
})
} catch (e) {
// console.log(e)
}
const exitApp = () => {
try {
const {ipcRenderer} = require('electron')
ipcRenderer.send('siyuan-quit', window.location.port)
} catch (e) {
if ((window.webkit && window.webkit.messageHandlers) || window.JSAndroid) {
window.location.href = 'siyuan://api/system/exit'
} else {
window.location.reload()
}
if ({{.appearanceModeOS}} && window.matchMedia('(prefers-color-scheme: dark)').matches || {{.appearanceMode}} ===1) {
document.body.classList.add('dark')
}
}
const exitSiYuan = () => {
if (window.location.hostname !== 'localhost' && window.location.hostname !== '127.0.0.1') {
document.querySelector('.b3-button--white').remove()
}
try {
fetch('/api/system/exit', {
method: 'POST',
body: JSON.stringify({force: false}),
}).then((response) => {
return response.json()
}).then((response) => {
if (response.code === 1) {
document.querySelector('#message').classList.add('b3-snackbar--show')
document.querySelector('#message').firstElementChild.textContent = response.msg
const buttonElement = document.querySelector(`#message button`)
if (buttonElement) {
buttonElement.addEventListener('click', () => {
fetch('/api/system/exit', {
method: 'POST',
body: JSON.stringify({force: true}),
}).then((response) => {
return response.json()
}).then(() => {
exitApp()
})
})
}
} else {
exitApp()
ipcRenderer.on('siyuan-save-close', (event, close) => {
exitSiYuan()
})
} catch (e) {
// console.log(e)
}
const exitApp = () => {
try {
const {ipcRenderer} = require('electron')
ipcRenderer.send('siyuan-quit', window.location.port)
} catch (e) {
if ((window.webkit && window.webkit.messageHandlers) || window.JSAndroid) {
window.location.href = 'siyuan://api/system/exit'
} else {
window.location.reload()
}
}
}).catch(() => {
exitApp()
})
} catch (e) {
exitApp()
}
}
const inputElement = document.getElementById('authCode')
const captchaElement = document.getElementById('captcha')
inputElement.focus()
inputElement.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
submitAuth()
const exitSiYuan = () => {
try {
fetch('/api/system/exit', {
method: 'POST',
body: JSON.stringify({force: false}),
}).then((response) => {
return response.json()
}).then((response) => {
if (response.code === 1) {
document.querySelector('#message').classList.add('b3-snackbar--show')
document.querySelector('#message').firstElementChild.textContent = response.msg
const buttonElement = document.querySelector(`#message button`)
if (buttonElement) {
buttonElement.addEventListener('click', () => {
fetch('/api/system/exit', {
method: 'POST',
body: JSON.stringify({force: true}),
}).then((response) => {
return response.json()
}).then(() => {
exitApp()
})
})
}
} else {
exitApp()
}
}).catch(() => {
exitApp()
})
} catch (e) {
exitApp()
}
}
})
captchaElement.previousElementSibling.addEventListener('click', function () {
this.src = `/api/system/getCaptcha?v=${new Date().getTime()}`
})
const submitAuth = () => {
fetch('/api/system/loginAuth', {
method: 'POST',
body: JSON.stringify({
authCode: inputElement.value,
captcha: captchaElement.value,
}),
}).then((response) => {
return response.json()
}).then((response) => {
if (0 === response.code) {
const url = new URL(window.location)
window.location.href = url.searchParams.get("to") || "/"
return
}
if (response.code === 1) {
captchaElement.previousElementSibling.src = `/api/system/getCaptcha?v=${new Date().getTime()}`
captchaElement.parentElement.style.display = 'block'
} else {
captchaElement.parentElement.style.display = 'none'
captchaElement.previousElementSibling.src = ''
}
document.querySelector('#message').classList.add('b3-snackbar--show')
document.querySelector('#message').firstElementChild.textContent = response.msg
inputElement.value = ''
captchaElement.value = ''
inputElement.focus()
setTimeout(() => {
document.querySelector('#message').classList.remove('b3-snackbar--show')
document.querySelector('#message').firstElementChild.textContent = ''
}, 6000)
const inputElement = document.getElementById('authCode')
const captchaElement = document.getElementById('captcha')
inputElement.focus()
inputElement.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
submitAuth()
}
})
}
// 用于授权页保持连接,避免非常驻内存内核自动退出 https://github.com/siyuan-note/insider/issues/1099
new WebSocket((window.location.protocol === 'https:' ? 'wss' : 'ws') + '://' + window.location.host + '/ws?app=siyuan&id=auth')
captchaElement.previousElementSibling.addEventListener('click', function () {
this.src = `/api/system/getCaptcha?v=${new Date().getTime()}`
})
const submitAuth = () => {
fetch('/api/system/loginAuth', {
method: 'POST',
body: JSON.stringify({
authCode: inputElement.value,
captcha: captchaElement.value,
}),
}).then((response) => {
return response.json()
}).then((response) => {
if (0 === response.code) {
const url = new URL(window.location)
window.location.href = url.searchParams.get("to") || "/"
return
}
if (response.code === 1) {
captchaElement.previousElementSibling.src = `/api/system/getCaptcha?v=${new Date().getTime()}`
captchaElement.parentElement.style.display = 'block'
} else {
captchaElement.parentElement.style.display = 'none'
captchaElement.previousElementSibling.src = ''
}
document.querySelector('#message').classList.add('b3-snackbar--show')
document.querySelector('#message').firstElementChild.textContent = response.msg
inputElement.value = ''
captchaElement.value = ''
inputElement.focus()
setTimeout(() => {
document.querySelector('#message').classList.remove('b3-snackbar--show')
document.querySelector('#message').firstElementChild.textContent = ''
}, 6000)
})
}
// 用于授权页保持连接,避免非常驻内存内核自动退出 https://github.com/siyuan-note/insider/issues/1099
new WebSocket((window.location.protocol === 'https:' ? 'wss' : 'ws') + '://' + window.location.host + '/ws?app=siyuan&id=auth')
ipcRenderer.send("siyuan-hotkey", {
languages: {},
hotkeys: ['{{.keymapGeneralToggleWin}}']
});
</script>
</body>
</html>