首先、选中文件

使用:electron的remote模块的dialog

Electron对磁盘文件的处理

  const onImport = () => {
      const { dialog } = remote
      let that = this
      dialog.showOpenDialog({title: '你好,文件导入', filters: [{name: 'wallet', extensions: ['wallet']}]}, function (filePaths) {
        if (filePaths) {
          if (filePaths.length > 0) {
            that.setState({
            recoverAccountFrm: Object.assign(that.state.recoverAccountFrm, {accountPrivatekeyFilePath: filePaths[0]})
          })
          } else {
            message.warning('选择文件为空!');
          }
        } else {
          message.warning('选择文件为空!');
        }
      })
    }

选中的是文件的路径,

filePaths[0] ===》 C:\Users\blockchain\Documents\err.wallet

第二步、处理文件:node.js 的fs

先从渲染进程中把文件的路径传入主进程中由主进程去处理,如何传入点这里

原因是,渲染进程是运行在浏览器环境,主进程是node环境)

openWallet(walletName) {
        const walletPath = this.getWalletPath(walletName);
        this.db = new Database(walletPath);
        const init = fs.readFileSync(path.join(__dirname,'migrate','init.sql'), 'utf8');
        this.db.exec(init);
    }

然后在主进程中就可以随意的使用fs模块去处理文件了

相关文章:

  • 2021-04-12
  • 2021-05-31
  • 2021-10-01
  • 2021-12-05
  • 2022-01-18
  • 2021-08-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-09
  • 2021-11-13
  • 2021-06-05
  • 2022-03-05
  • 2021-09-04
  • 2021-04-29
  • 2021-12-20
相关资源
相似解决方案