electron dialog模块的showMessageBox添加checkBox问题

新手上路,请多包涵

我想要用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,不知道是不是版本的问题,如果有人知道的话,望告知此问题的解决方法?

阅读 6.6k
1 个回答
✓ 已被采纳新手上路,请多包涵

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题