0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

electronでファイル読み込み

0
Posted at
git clone  https://github.com/electron/electron-quick-start-typescript
cd electron-quick-start-typescript
yarn
yarn dev

nodeIntegrationを有効にする(セキュリティ的に良くないけど通信にしないので良いとする)

main.ts
抜粋...
  const mainWindow = new BrowserWindow({
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, "preload.js"),
      nodeIntegration: true
    },
    width: 800,
  });

index.html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Hello World!</title>
  </head>
  <body>

    <input id="csvLoad" type="button" value="読み込み"/>
    <script> var exports = {}; </script>
    <script src="./dist/renderer.js"></script>
  </body>
</html>

buttonのイベントをトリガーにファイルを読み込みログに出す

renderer.ts
import * as fs from 'fs';

const button = document.getElementById('csvLoad')
if (button !== null) {
    button.onclick = () => {
        a();
    }
}


const a = () => {
    fs.readFile('text file path', (error, data) => {
        console.log(data.toString())
    })
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?