Skip to content

建议打开新窗口增加自动置顶参数 #16080

@wish5115

Description

@wish5115

Is there an existing issue for this?

  • I have searched the existing issues

Can the issue be reproduced with the default theme (daylight/midnight)?

  • I was able to reproduce the issue with the default theme

Could the issue be due to extensions?

  • I've ruled out the possibility that the extension is causing the problem.

Describe the problem

我把下面这个函数提取出来用于打开新窗口,发现里面有一个pin参数,起初,以为是置顶参数,经过 @TCOTC 讲解发现不是,所以,我在像,能否加个参数用于新窗口置顶的参数?这样新窗口打开并置顶就方便多了。

export const openNewWindowById = async (id: string | string[], options: windowOptions = {}) => {

Image

完整测试函数如下:

// 测试
openNewWindowById('20251013071922-hz4xf3e', {pin: true})

// see https://github.com/siyuan-note/siyuan/blob/26568e33cf3a5e1f847b799118bfcdbb9c31db6a/app/src/window/openNewWindow.ts#L36
// options = {position:{x:0, y:0}, width:0, height:0}
async function openNewWindowById(id, options = {}) {
    await new Promise(resolve => setTimeout(resolve, 50));
    let ids = id;
    if (typeof ids === "string") {
        ids = [ids];
    }
    const json = [];
    for (let i = 0; i < ids.length; i++) {
        const response = await requestApi("/api/block/getBlockInfo", {id: ids[i]});
        if (response.code === 3) {
            showMessage(response.msg);
            return;
        }
        json.push({
            title: response.data.rootTitle,
            docIcon: response.data.rootIcon,
            pin: options.pin || false,
            active: true,
            instance: "Tab",
            action: "Tab",
            children: {
                notebookId: response.data.box,
                blockId: ids[i],
                rootId: response.data.rootID,
                mode: "wysiwyg",
                instance: "Editor",
                action: response.data.rootID === ids[i] ? 'cb-get-scroll' : 'cb-get-all'
            }
        });
    }
    if(!isBrowser()) {
      const ipcRenderer = require('electron').ipcRenderer;
      ipcRenderer.send('siyuan-open-window', {
          position: options.position,
          width: options.width,
          height: options.height,
          url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${window.siyuan.config.system.kernelVersion}&json=${encodeURIComponent(JSON.stringify(json))}`
      });
    }
}
function showMessage(message, isError = false, delay = 7000) {
  return fetch('/api/notification/' + (isError ? 'pushErrMsg' : 'pushMsg'), {
      "method": "POST",
      "body": JSON.stringify({"msg": message, "timeout": delay})
  });
}
function isBrowser() {
  return !navigator.userAgent.startsWith("SiYuan") ||
      navigator.userAgent.indexOf("iPad") > -1 ||
      (/Android/.test(navigator.userAgent) && !/(?:Mobile)/.test(navigator.userAgent));
}

Expected result

期望置顶参数可用

Screenshot or screen recording presentation

No response

Version environment

- Version: 3.3.4
- Operating System: mac14
- Browser (if used): no

Log file

no

More information

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions