|
|
@@ -33,6 +33,16 @@ export interface SubWindowDefinition {
|
|
|
* 只有 ?newChat=1 / ?view=agent 这类明确意图才跳转。
|
|
|
*/
|
|
|
navigateOnlyWhenQuery?: boolean;
|
|
|
+ /**
|
|
|
+ * 已保存 bounds 的使用方式。
|
|
|
+ *
|
|
|
+ * <ul>
|
|
|
+ * <li>all(默认):位置 + 尺寸</li>
|
|
|
+ * <li>position:只用上次的位置,尺寸由 createWindowOptions 决定(权限窗口跟随主窗口大小)</li>
|
|
|
+ * <li>none:不恢复</li>
|
|
|
+ * </ul>
|
|
|
+ */
|
|
|
+ restoreBoundsMode?: 'all' | 'position' | 'none';
|
|
|
}
|
|
|
|
|
|
export interface SubWindowController {
|
|
|
@@ -111,6 +121,7 @@ export function createSubWindowController(definition: SubWindowDefinition): SubW
|
|
|
...restoreBounds(),
|
|
|
});
|
|
|
win = created;
|
|
|
+ clampToVisibleArea(created);
|
|
|
|
|
|
created.once('ready-to-show', () => {
|
|
|
if (!created.isDestroyed()) {
|
|
|
@@ -200,13 +211,44 @@ export function createSubWindowController(definition: SubWindowDefinition): SubW
|
|
|
);
|
|
|
});
|
|
|
|
|
|
- return visible ? { x, y, width, height } : {};
|
|
|
+ return visible ? buildRestoredBounds({ x, y, width, height }) : {};
|
|
|
} catch (e) {
|
|
|
logger.warn(`${logPrefix} 恢复窗口位置失败:`, e instanceof Error ? e.message : String(e));
|
|
|
return {};
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /** 按配置决定恢复位置和/或尺寸 */
|
|
|
+ function buildRestoredBounds(saved: Partial<SavedBounds>): Partial<SavedBounds> {
|
|
|
+ switch (definition.restoreBoundsMode) {
|
|
|
+ case 'none':
|
|
|
+ return {};
|
|
|
+ case 'position':
|
|
|
+ // 尺寸交给 createWindowOptions(例如权限窗口跟随主窗口大小),这里只保留位置
|
|
|
+ return { x: saved.x, y: saved.y };
|
|
|
+ default:
|
|
|
+ return saved;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 位置可能配不上新的窗口尺寸(例如跟随最大化的主窗口):保证窗口完整落在最近显示器的工作区内 */
|
|
|
+ function clampToVisibleArea(target: BrowserWindow): void {
|
|
|
+ try {
|
|
|
+ const bounds = target.getBounds();
|
|
|
+ const display = screen.getDisplayMatching(bounds);
|
|
|
+ const area = display.workArea;
|
|
|
+ const width = Math.min(bounds.width, area.width);
|
|
|
+ const height = Math.min(bounds.height, area.height);
|
|
|
+ const x = Math.min(Math.max(bounds.x, area.x), Math.max(area.x, area.x + area.width - width));
|
|
|
+ const y = Math.min(Math.max(bounds.y, area.y), Math.max(area.y, area.y + area.height - height));
|
|
|
+ if (x !== bounds.x || y !== bounds.y || width !== bounds.width || height !== bounds.height) {
|
|
|
+ target.setBounds({ x, y, width, height });
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ logger.warn(`${logPrefix} 校正窗口位置失败:`, e instanceof Error ? e.message : String(e));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function notifyState(open: boolean): void {
|
|
|
const channel = definition.stateChannel;
|
|
|
if (!channel) return;
|