🎨 Windows/macOS 桌面端支持开机启动 https://github.com/siyuan-note/siyuan/issues/6833

This commit is contained in:
Liang Ding 2022-12-09 16:35:11 +08:00
parent ad1924890b
commit 5a4b64464d
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
9 changed files with 43 additions and 2 deletions

View file

@ -1,4 +1,6 @@
{ {
"autoLaunch": "Automatic launch at boot",
"autoLaunchTip": "After enabling, the application will be automatically launched after logging into the operating system",
"sortByRankDesc": "Relevance DESC", "sortByRankDesc": "Relevance DESC",
"sortByRankAsc": "Relevance ASC", "sortByRankAsc": "Relevance ASC",
"saveCriterion": "Save named criterion", "saveCriterion": "Save named criterion",

View file

@ -1,4 +1,6 @@
{ {
"autoLaunch": "Inicio automático al arrancar",
"autoLaunchTip": "Después de habilitar, la aplicación se iniciará automáticamente después de iniciar sesión en el sistema operativo",
"sortByRankDesc": "Relevancia DESC", "sortByRankDesc": "Relevancia DESC",
"sortByRankAsc": "Relevancia ASC", "sortByRankAsc": "Relevancia ASC",
"saveCriterion": "Guardar criterio nombrado", "saveCriterion": "Guardar criterio nombrado",

View file

@ -1,4 +1,6 @@
{ {
"autoLaunch": "Lancement automatique au démarrage",
"autoLaunchTip": "Après l'activation, l'application sera automatiquement lancée après la connexion au système d'exploitation",
"sortByRankDesc": "DESC de pertinence", "sortByRankDesc": "DESC de pertinence",
"sortByRankAsc": "ASC de pertinence", "sortByRankAsc": "ASC de pertinence",
"saveCriterion": "Enregistrer le critère nommé", "saveCriterion": "Enregistrer le critère nommé",

View file

@ -1,4 +1,6 @@
{ {
"autoLaunch": "開機自動啟動",
"autoLaunchTip": "啟用後會在登錄操作系統後自動啟動應用",
"sortByRankDesc": "按相關度降序", "sortByRankDesc": "按相關度降序",
"sortByRankAsc": "按相關度升序", "sortByRankAsc": "按相關度升序",
"saveCriterion": "保存命名查詢", "saveCriterion": "保存命名查詢",

View file

@ -1,4 +1,6 @@
{ {
"autoLaunch": "开机自动启动",
"autoLaunchTip": "启用后会在登录操作系统后自动启动应用",
"sortByRankDesc": "按相关度降序", "sortByRankDesc": "按相关度降序",
"sortByRankAsc": "按相关度升序", "sortByRankAsc": "按相关度升序",
"saveCriterion": "保存命名查询", "saveCriterion": "保存命名查询",

View file

@ -1,6 +1,6 @@
import {Constants} from "../constants"; import {Constants} from "../constants";
/// #if !BROWSER /// #if !BROWSER
import {shell} from "electron"; import {app, shell} from "electron";
import {dialog} from "@electron/remote"; import {dialog} from "@electron/remote";
/// #endif /// #endif
import {isBrowser} from "../util/functions"; import {isBrowser} from "../util/functions";
@ -17,7 +17,15 @@ import {setProxy} from "../util/onGetConfig";
export const about = { export const about = {
element: undefined as Element, element: undefined as Element,
genHTML: () => { genHTML: () => {
return `<label class="fn__flex b3-label${isBrowser() || window.siyuan.config.system.isMicrosoftStore ? " fn__none" : ""}"> return `<label class="fn__flex b3-label${isBrowser() || "std" !== window.siyuan.config.system.container || "linux" === window.siyuan.config.system.os ? " fn__none" : ""}">
<div class="fn__flex-1">
${window.siyuan.languages.autoLaunch}
<div class="b3-label__text">${window.siyuan.languages.autoLaunchTip}</div>
</div>
<div class="fn__space"></div>
<input class="b3-switch fn__flex-center" id="autoLaunch" type="checkbox"${window.siyuan.config.system.autoLaunch ? " checked" : ""}>
</label>
<label class="fn__flex b3-label${isBrowser() || window.siyuan.config.system.isMicrosoftStore ? " fn__none" : ""}">
<div class="fn__flex-1"> <div class="fn__flex-1">
${window.siyuan.languages.autoDownloadUpdatePkg} ${window.siyuan.languages.autoDownloadUpdatePkg}
<div class="b3-label__text">${window.siyuan.languages.autoDownloadUpdatePkgTip}</div> <div class="b3-label__text">${window.siyuan.languages.autoDownloadUpdatePkgTip}</div>
@ -389,6 +397,13 @@ export const about = {
window.siyuan.config.system.downloadInstallPkg = downloadInstallPkgElement.checked; window.siyuan.config.system.downloadInstallPkg = downloadInstallPkgElement.checked;
}); });
}); });
const autoLaunchElement = about.element.querySelector("#autoLaunch") as HTMLInputElement;
autoLaunchElement.addEventListener("change", () => {
fetchPost("/api/system/setAutoLaunch", {autoLaunch: autoLaunchElement.checked}, () => {
window.siyuan.config.system.autoLaunch = autoLaunchElement.checked;
app.setLoginItemSettings({openAtLogin: autoLaunchElement.checked});
});
});
about.element.querySelector("#aboutConfirm").addEventListener("click", () => { about.element.querySelector("#aboutConfirm").addEventListener("click", () => {
const scheme = (about.element.querySelector("#aboutScheme") as HTMLInputElement).value; const scheme = (about.element.querySelector("#aboutScheme") as HTMLInputElement).value;
const host = (about.element.querySelector("#aboutHost") as HTMLInputElement).value; const host = (about.element.querySelector("#aboutHost") as HTMLInputElement).value;

View file

@ -410,6 +410,7 @@ declare interface IConfig {
downloadInstallPkg: boolean downloadInstallPkg: boolean
networkServe: boolean networkServe: boolean
fixedPort: boolean fixedPort: boolean
autoLaunch: boolean
} }
localIPs: string[] localIPs: string[]
readonly: boolean readonly: boolean

View file

@ -333,6 +333,20 @@ func setUploadErrLog(c *gin.Context) {
time.Sleep(time.Second * 3) time.Sleep(time.Second * 3)
} }
func setAutoLaunch(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
arg, ok := util.JsonArg(c, ret)
if !ok {
return
}
autoLaunch := arg["autoLaunch"].(bool)
model.Conf.System.AutoLaunch = autoLaunch
model.Conf.Save()
}
func setDownloadInstallPkg(c *gin.Context) { func setDownloadInstallPkg(c *gin.Context) {
ret := gulu.Ret.NewResult() ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret) defer c.JSON(http.StatusOK, ret)

View file

@ -41,6 +41,7 @@ type System struct {
UploadErrLog bool `json:"uploadErrLog"` UploadErrLog bool `json:"uploadErrLog"`
DisableGoogleAnalytics bool `json:"disableGoogleAnalytics"` DisableGoogleAnalytics bool `json:"disableGoogleAnalytics"`
DownloadInstallPkg bool `json:"downloadInstallPkg"` DownloadInstallPkg bool `json:"downloadInstallPkg"`
AutoLaunch bool `json:"autoLaunch"`
} }
func NewSystem() *System { func NewSystem() *System {