🎨 Support minimize the main window after auto launch on Windows/macOS https://github.com/siyuan-note/siyuan/issues/11145

This commit is contained in:
Daniel 2024-04-27 12:11:42 +08:00
parent 03a6c15d70
commit b64a9a3ad2
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
10 changed files with 75 additions and 17 deletions

View file

@ -1,4 +1,7 @@
{
"autoLaunchMode0": "Do not launch automatically",
"autoLaunchMode1": "Auto launch after booting",
"autoLaunchMode2": "Auto launch and minimize the interface after booting",
"editorMarkdownInlineSup": "Markdown inline superscript syntax",
"editorMarkdownInlineSupTip": "After enabling, <code class='fn__code'>^foo^</code> inline superscript syntax input will be supported",
"editorMarkdownInlineSub": "Markdown inline subscript syntax",

View file

@ -1,4 +1,7 @@
{
"autoLaunchMode0": "No iniciar automáticamente",
"autoLaunchMode1": "Inicio automático después del arranque",
"autoLaunchMode2": "Iniciar automáticamente y minimizar la interfaz después del arranque",
"editorMarkdownInlineSup": "Sintaxis de superíndice en línea de Markdown",
"editorMarkdownInlineSupTip": "Después de habilitar, se admitirá la entrada de sintaxis de superíndice en línea <code class='fn__code'>^foo^</code>",
"editorMarkdownInlineSub": "Sintaxis del subíndice en línea de Markdown",

View file

@ -1,4 +1,7 @@
{
"autoLaunchMode0": "Ne pas lancer automatiquement",
"autoLaunchMode1": "Lancement automatique après le démarrage",
"autoLaunchMode2": "Lancement automatique et réduction de l'interface après le démarrage",
"editorMarkdownInlineSup": "Syntaxe exposant Markdown en ligne",
"editorMarkdownInlineSupTip": "Après l'activation, la saisie de la syntaxe en exposant <code class='fn__code'>^foo^</code> en ligne sera prise en charge",
"editorMarkdownInlineSub": "Syntaxe d'indice en ligne Markdown",

View file

@ -1,4 +1,7 @@
{
"autoLaunchMode0": "不自動啟動",
"autoLaunchMode1": "開機自動啟動",
"autoLaunchMode2": "開機自動啟動並最小化介面",
"editorMarkdownInlineSup": "Markdown 行級上標語法",
"editorMarkdownInlineSupTip": "啟用後將支援 <code class='fn__code'>^foo^</code> 行級上標語法輸入",
"editorMarkdownInlineSub": "Markdown 行級下標語法",

View file

@ -1,4 +1,7 @@
{
"autoLaunchMode0": "不自动启动",
"autoLaunchMode1": "开机后自动启动",
"autoLaunchMode2": "开机后自动启动并最小化界面",
"editorMarkdownInlineSup": "Markdown 行级上标语法",
"editorMarkdownInlineSupTip": "启用后将支持 <code class='fn__code'>^foo^</code> 行级上标语法输入",
"editorMarkdownInlineSub": "Markdown 行级下标语法",

View file

@ -230,7 +230,7 @@ const writeLog = (out) => {
}
};
const boot = () => {
const initMainWindow = () => {
let windowStateInitialized = true;
// 恢复主窗体状态
let oldWindowState = {};
@ -1019,7 +1019,7 @@ app.whenReady().then(() => {
if (!foundWorkspace) {
initKernel(data.workspace, "", "").then((isSucc) => {
if (isSucc) {
boot();
initMainWindow();
}
});
}
@ -1149,7 +1149,7 @@ app.whenReady().then(() => {
ipcMain.on("siyuan-first-init", (event, data) => {
initKernel(data.workspace, "", data.lang).then((isSucc) => {
if (isSucc) {
boot();
initMainWindow();
}
});
firstOpenWindow.destroy();
@ -1173,7 +1173,7 @@ app.whenReady().then(() => {
}
initKernel(workspace, port, "").then((isSucc) => {
if (isSucc) {
boot();
initMainWindow();
}
});
}
@ -1280,7 +1280,7 @@ app.on("second-instance", (event, argv) => {
if (workspace) {
initKernel(workspace, port, "").then((isSucc) => {
if (isSucc) {
boot();
initMainWindow();
}
});
return;
@ -1306,7 +1306,7 @@ app.on("activate", () => {
}
}
if (BrowserWindow.getAllWindows().length === 0) {
boot();
initMainWindow();
}
});

View file

@ -16,14 +16,18 @@ import {setKey} from "../sync/syncGuide";
export const about = {
element: undefined as Element,
genHTML: () => {
return `<label class="fn__flex b3-label${isBrowser() || window.siyuan.config.system.isMicrosoftStore || "std" !== window.siyuan.config.system.container || "linux" === window.siyuan.config.system.os ? " fn__none" : ""}">
return `<div class="fn__flex b3-label config__item${isBrowser() || window.siyuan.config.system.isMicrosoftStore || "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>
<span class="fn__space"></span>
<select class="b3-select fn__flex-center fn__size200" id="autoLaunch">
<option value="0" ${window.siyuan.config.system.autoLaunch === 0 ? "selected" : ""}>${window.siyuan.languages.autoLaunchMode0}</option>
<option value="1" ${window.siyuan.config.system.autoLaunch === 1 ? "selected" : ""}>${window.siyuan.languages.autoLaunchMode1}</option>
<option value="2" ${window.siyuan.config.system.autoLaunch === 2 ? "selected" : ""}>${window.siyuan.languages.autoLaunchMode2}</option>
</select>
</div>
<label class="fn__flex b3-label${isBrowser() || window.siyuan.config.system.isMicrosoftStore || window.siyuan.config.system.container !== "std" ? " fn__none" : ""}">
<div class="fn__flex-1">
${window.siyuan.languages.autoDownloadUpdatePkg}
@ -348,9 +352,10 @@ export const about = {
/// #if !BROWSER
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;
ipcRenderer.send(Constants.SIYUAN_AUTO_LAUNCH, {openAtLogin: autoLaunchElement.checked});
const autoLaunchMode = parseInt(autoLaunchElement.value)
fetchPost("/api/system/setAutoLaunch", {autoLaunch: autoLaunchMode}, () => {
window.siyuan.config.system.autoLaunch = autoLaunchMode;
ipcRenderer.send(Constants.SIYUAN_AUTO_LAUNCH, {openAtLogin: 0 != autoLaunchMode});
});
});
/// #endif

View file

@ -1351,8 +1351,11 @@ declare namespace Config {
appDir: string;
/**
* Boot automatically
* - `0`: Do not boot automatically
* - `1`: Boot automatically
* - `2`: Boot automatically + Minimize UI
*/
autoLaunch: boolean;
autoLaunch: number;
/**
* The absolute path of the `conf` directory of the current workspace
*/

View file

@ -421,9 +421,44 @@ func setAutoLaunch(c *gin.Context) {
return
}
autoLaunch := arg["autoLaunch"].(bool)
model.Conf.System.AutoLaunch = autoLaunch
autoLaunch := int(arg["autoLaunch"].(float64))
model.Conf.System.AutoLaunch2 = autoLaunch
model.Conf.Save()
windowStateConf := filepath.Join(util.ConfDir, "windowState.json")
windowState := map[string]interface{}{}
if gulu.File.IsExist(windowStateConf) {
succ := false
const maxRetry = 7
for i := 0; i < maxRetry; i++ {
data, err := os.ReadFile(windowStateConf)
if nil != err {
logging.LogErrorf("read [windowState.json] failed [%d/%d]: %s", i, maxRetry, err)
time.Sleep(time.Second)
} else {
if err = gulu.JSON.UnmarshalJSON(data, &windowState); nil != err {
logging.LogErrorf("unmarshal [windowState.json] failed: %s", err)
} else {
succ = true
break
}
}
}
if !succ {
logging.LogErrorf("read [windowState.json] failed")
}
}
windowState["autoLaunch"] = autoLaunch
data, err := gulu.JSON.MarshalJSON(windowState)
if nil != err {
logging.LogErrorf("marshal [windowState.json] failed: %s", err)
return
}
if err = gulu.File.WriteFileSafer(windowStateConf, data, 0644); nil != err {
logging.LogErrorf("create [windowState.json] failed: %s", err)
}
}
func setDownloadInstallPkg(c *gin.Context) {

View file

@ -42,7 +42,7 @@ type System struct {
UploadErrLog bool `json:"uploadErrLog"`
DisableGoogleAnalytics bool `json:"disableGoogleAnalytics"`
DownloadInstallPkg bool `json:"downloadInstallPkg"`
AutoLaunch bool `json:"autoLaunch"`
AutoLaunch2 int `json:"autoLaunch2"` // 0不自动启动1自动启动2自动启动+隐藏主窗口
LockScreenMode int `json:"lockScreenMode"` // 0手动1手动+跟随系统 https://github.com/siyuan-note/siyuan/issues/9087
}