From 2ddf5c5ec83d13e89fbb0a3296ff8c32df8bdc99 Mon Sep 17 00:00:00 2001 From: n1vk Date: Thu, 30 Apr 2026 16:29:17 +0800 Subject: [PATCH 1/5] feat: smaller minWidth/Height --- src/main/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index de5d6df..4e6e9c2 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -31,8 +31,8 @@ async function createWindow() { win = new BrowserWindow({ width: 1200, height: 800, - minWidth: 800, - minHeight: 600, + minWidth: 400, + minHeight: 300, frame: false, titleBarStyle: "hidden", // ✅ macOS 专属 icon: path.join(__dirname, "../assets/icons/milkup.ico"), From d3ad325fbf9a3931ddf91d6b6fd323f31630684e Mon Sep 17 00:00:00 2001 From: n1vk Date: Thu, 30 Apr 2026 17:17:07 +0800 Subject: [PATCH 2/5] feat: add settings for default window size --- lang/index.json | 48 ++++++++++++ src/main/index.ts | 22 ++++++ src/preload.ts | 2 + src/renderer/App.vue | 2 + .../components/settings/OtherSetting.vue | 76 +++++++++++++++++++ src/renderer/components/ui/input/Input.vue | 50 +++++++----- src/renderer/global.d.ts | 1 + src/renderer/hooks/useConfig.ts | 4 + 8 files changed, 188 insertions(+), 17 deletions(-) diff --git a/lang/index.json b/lang/index.json index f5d1db5..b0ee938 100644 --- a/lang/index.json +++ b/lang/index.json @@ -3894,5 +3894,53 @@ "ru": "", "en": "", "fr": "" + }, + "70wovq6": { + "zh-cn": "窗口默认尺寸", + "ja": "", + "ko": "", + "ru": "", + "en": "", + "fr": "" + }, + "j6rndol": { + "zh-cn": "设置 Milkup 启动时的窗口宽度和高度", + "ja": "", + "ko": "", + "ru": "", + "en": "", + "fr": "" + }, + "hdojy66": { + "zh-cn": "宽度(PX)", + "ja": "", + "ko": "", + "ru": "", + "en": "", + "fr": "" + }, + "c2mhr16": { + "zh-cn": "最小 400", + "ja": "", + "ko": "", + "ru": "", + "en": "", + "fr": "" + }, + "va60g76": { + "zh-cn": "高度(PX)", + "ja": "", + "ko": "", + "ru": "", + "en": "", + "fr": "" + }, + "c2mihq6": { + "zh-cn": "最小 300", + "ja": "", + "ko": "", + "ru": "", + "en": "", + "fr": "" } } diff --git a/src/main/index.ts b/src/main/index.ts index 4e6e9c2..6d78e69 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -33,6 +33,7 @@ async function createWindow() { height: 800, minWidth: 400, minHeight: 300, + show: false, frame: false, titleBarStyle: "hidden", // ✅ macOS 专属 icon: path.join(__dirname, "../assets/icons/milkup.ico"), @@ -258,6 +259,18 @@ app.whenReady().then(async () => { } }); + let startupSizeTimeout: ReturnType | null = null; + ipcMain.on("window:apply-startup-size", (_event, width: number, height: number) => { + if (!win || win.isDestroyed()) return; + if (startupSizeTimeout) { + clearTimeout(startupSizeTimeout); + startupSizeTimeout = null; + } + win.setSize(width, height); + win.center(); + win.show(); + }); + // 监听渲染进程就绪事件 (Moved up to avoid race condition) ipcMain.on("renderer-ready", () => { isRendererReady = true; @@ -269,6 +282,15 @@ app.whenReady().then(async () => { await createWindow(); + if (win && !win.isDestroyed()) { + startupSizeTimeout = setTimeout(() => { + if (win && !win.isDestroyed() && !win.isVisible()) { + win.center(); + win.show(); + } + }, 2000); + } + sendLaunchFileIfExists(); }); diff --git a/src/preload.ts b/src/preload.ts index 0228e9e..273a199 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -112,6 +112,8 @@ contextBridge.exposeInMainWorld("electronAPI", { saveCustomTheme: (theme: any) => ipcRenderer.send("save-custom-theme", theme), platform: process.platform, rendererReady: () => ipcRenderer.send("renderer-ready"), + applyStartupSize: (width: number, height: number) => + ipcRenderer.send("window:apply-startup-size", width, height), // Tab 拖拽分离 tearOffTabStart: ( diff --git a/src/renderer/App.vue b/src/renderer/App.vue index f333628..40bbb32 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -138,6 +138,8 @@ function onOutlineTransitionEnd(e: TransitionEvent) { } onMounted(() => { + const { windowDefaultWidth = 1200, windowDefaultHeight = 800 } = config.value.other ?? {}; + window.electronAPI.applyStartupSize(windowDefaultWidth, windowDefaultHeight); initTheme(); initFont(); initOtherConfig(); diff --git a/src/renderer/components/settings/OtherSetting.vue b/src/renderer/components/settings/OtherSetting.vue index c634d2b..b243f08 100644 --- a/src/renderer/components/settings/OtherSetting.vue +++ b/src/renderer/components/settings/OtherSetting.vue @@ -10,6 +10,7 @@ const { config } = useConfig(); const paddingSettingsExpanded = ref(false); const mermaidSettingsExpanded = ref(false); +const windowSizeExpanded = ref(false); // 从完整值中提取数字部分用于显示(如 "20px" -> "20") const displayPaddingValue = computed(() => { @@ -45,6 +46,32 @@ function setMermaidMode(mode: string) { mermaid: { ...config.value.mermaid, defaultDisplayMode: mode as "code" | "mixed" | "diagram" }, }; } + +function toggleWindowSize() { + windowSizeExpanded.value = !windowSizeExpanded.value; +} + +const currentWindowWidth = computed(() => String(config.value.other?.windowDefaultWidth ?? 1200)); +const currentWindowHeight = computed(() => String(config.value.other?.windowDefaultHeight ?? 800)); + +const WINDOW_MIN_WIDTH = 400; +const WINDOW_MIN_HEIGHT = 300; + +function handleWindowWidthChange(value: string) { + const num = Math.max(WINDOW_MIN_WIDTH, parseInt(value) || WINDOW_MIN_WIDTH); + config.value = { + ...config.value, + other: { ...config.value.other, windowDefaultWidth: num }, + }; +} + +function handleWindowHeightChange(value: string) { + const num = Math.max(WINDOW_MIN_HEIGHT, parseInt(value) || WINDOW_MIN_HEIGHT); + config.value = { + ...config.value, + other: { ...config.value.other, windowDefaultHeight: num }, + }; +} -