electron dialog模块的showMessageBox添加checkBox问题

发布于 2022-09-04 23:07:42 字数 3188 浏览 8 评论 0

我想要用electron的showMessagebox实现下面这个图的不再提示选择的功能:

图片描述

然后查询electron的官方文档的dialog,有这样的说明:

图片描述

于是按照上面的说明在option配置了checkboxLabel,但是没有任何效果,然后按ctrl查看源代码,发现是这样的:

    showMessageBox(browserWindow: BrowserWindow, options: ShowMessageBoxOptions, callback?: (response: number) => void): number;
    /**
     * Shows a message box. It will block until the message box is closed.
     * @param callback If supplied, the API call will be asynchronous.
     * @returns The index of the clicked button.
     */
    showMessageBox(options: ShowMessageBoxOptions, callback?: (response: number) => void): number;
    /**
     * Displays a modal dialog that shows an error message.
     *
     * This API can be called safely before the ready event the app module emits,
     * it is usually used to report errors in early stage of startup.
     * If called before the app readyevent on Linux, the message will be emitted to stderr,
     * and no GUI dialog will appear.
     */

再按ctrl查看,发现是这样的:

    
     interface ShowMessageBoxOptions {
        /**
         * On Windows, "question" displays the same icon as "info", unless you set an icon using the "icon" option.
         */
        type?: 'none' | 'info' | 'error' | 'question' | 'warning';
        /**
         * Texts for buttons. On Windows, an empty array will result in one button labeled "OK".
         */
        buttons?: string[];
        /**
         * Index of the button in the buttons array which will be selected by default when the message box opens.
         */
        defaultId?: number;
        /**
         * Title of the message box (some platforms will not show it).
         */
        title?: string;
        /**
         * Contents of the message box.
         */
        message?: string;
        /**
         * Extra information of the message.
         */
        detail?: string;
        icon?: NativeImage;
        /**
         * The value will be returned when user cancels the dialog instead of clicking the buttons of the dialog.
         * By default it is the index of the buttons that have "cancel" or "no" as label,
         * or 0 if there is no such buttons. On macOS and Windows the index of "Cancel" button
         * will always be used as cancelId, not matter whether it is already specified.
         */
        cancelId?: number;
        /**
         * On Windows Electron will try to figure out which one of the buttons are common buttons
         * (like "Cancel" or "Yes"), and show the others as command links in the dialog.
         * This can make the dialog appear in the style of modern Windows apps.
         * If you don’t like this behavior, you can set noLink to true.
         */
        noLink?: boolean;
    }
    

上面的属性根本就没有checkboxLabel(跟官方文档不一样?),我的package.json的electron的版本是1.6.2,不知道是不是版本的问题,如果有人知道的话,望告知此问题的解决方法?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

池木 2022-09-11 23:07:42

在官文FAQ找了下,还真是版本的问题...,因为我用的是electron-quick-start,里面的package.json的electron是^1.6.2的,而官网checkboxLabel的版本是^1.6.8...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文