python-eel/Eel

Using Eel from Electron main process?

Open

#659 建立於 2023年2月7日

在 GitHub 查看
 (0 留言) (0 反應) (0 負責人)Python (570 fork)batch import
help wanted

倉庫指標

Star
 (5,980 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

Describe the problem I'd like to be able to communicate between Python and the Electron main process (in addition to between Python and the Electron renderer process). I've got it working just fine with the renderer process, but can't find a way to import Eel to the main electron process. I tried introducing delays to avoid race conditions, but to no avail.

Error (in Electron alert before startup):

Error: Cannot find module 'http://localhost:8080/eel.js'

Code snippet(s)

import eel

eel.init("src")

@eel.expose
def say_hello_py(_from):
    print(f"hello from {_from}!")
    
say_hello_py("Python world")
eel.say_hello_js("Python calling to JS")

electron_path = "node_modules/.bin/electron"

eel.start(
    {"port": 3000},
    mode="custom",
    host="localhost",
    port=8080,
    cmdline_args=[electron_path, "."],
)```

```javascript

const {app, BrowserWindow, dialog } = require('electron')

let eel
let appInstance

// @TODO: load env from env
let DEBUG = true
let WAIT = 0

setTimeout(() => { configure(); run(); }, 3 * 1000)

class App {
  // window setup here
  // want to call to Python
}

function configure() {
    require('http://localhost:8080/eel.js')
}

function run() {
    appInstance = new App()
}

貢獻者指南