python-eel/Eel

Using Eel from Electron main process?

Open

#659 opened on Feb 7, 2023

View on GitHub
 (0 comments) (0 reactions) (0 assignees)Python (5,980 stars) (570 forks)batch import
help wanted

Description

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()
}

Contributor guide