使用带有节点的简单 js 提示符到电子应用程序

Use simple js prompt with node to electron app

我有一个被电子包裹的 Angular 应用程序。另外,我使用 node.js 获取 MySQL 数据并通过 electron 将其提供给 angularJs。 在我的项目中,没有稳定的数据库,所以我必须从客户端更改数据库凭据,它应该对特定客户端有效。

比如我有这些默认凭据:

{ 
    "host":"localhost", 
    "username":"root",
    "password":"123",
    "database":"mydata"
}

现在,当我将此应用程序移动到客户端时,应用程序首先尝试使用默认凭据连接到数据库,如果失败,它应该要求用户提供新的凭据,并且应该将其保存(可能作为 json 文件!).

我尝试了 npm 的提示,它只使用命令行就可以正常工作,我想要在 electron build 应用程序中有一个提示对话框!我怎样才能实现?

您可以在您的节点文件中使用它。

命令:

npm install electron-prompt

代码:

const prompt = require('electron-prompt');

prompt({
    title: 'Prompt example',
    label: 'URL:',
    value: 'http://example.org',
    inputAttrs: { // attrs to be set if using 'input'
        type: 'url'
    },
    type: 'select', // 'select' or 'input, defaults to 'input'
    selectOptions: { // select options if using 'select' type
        'value 1': 'Display Option 1',
        'value 2': 'Display Option 2',
        'value 3': 'Display Option 3'
    }
})
.then((r) => {
    console.log('result', r); // null if window was closed, or user clicked Cancel
})
.catch(console.error);