electron dialog模块的showMessageBox添加checkBox问题

查看:427
本文介绍了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,不知道是不是版本的问题,如果有人知道的话,望告知此问题的解决方法?

解决方案

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

这篇关于electron dialog模块的showMessageBox添加checkBox问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆