#How do I export functions as electron modules?

38 messages · Page 1 of 1 (latest)

rustic jackal
#

With es import/export

ocean epoch
#

Like this?

function startDrag(e) {
    isDragging = true;
    initialX = e.screenX;
    initialY = e.screenY;
}
// Exporter la fonction startDrag
export { startDrag };
rustic jackal
#

Like this

ocean epoch
#

Okk so then I did this:

import { startDrag } from './startDrag.js';
document.getElementById('custom-titlebar').addEventListener('mousedown', (e) => {
startDrag(e);
});

But still nothing

rustic jackal
#

Errors?

ocean epoch
#

No, I don't have any error messages, but I do have the usual drag behavior.

rustic jackal
#

But your code do nothing

#

What supposed to be?

ocean epoch
#

I have to go I'll answer later

ocean epoch
rustic jackal
#

You cant say what supposed to be?

#

If you enable node integration you can use require

ocean epoch
#

This ?

mainWindow = new BrowserWindow({
width: width,
height: height,
frame: false,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
webviewTag: true,
},
icon: 'src/assets/logo.png',
});

rustic jackal
#

This

ocean epoch
#

This is already the case, in fact the drag function allows me to create my own custom title bar.

rustic jackal
#

So?

#

Atm your function do nothing

ocean epoch
#

Except that I have 400 lines of javascript code in disarray so I want to create different little module to lighten all that except that as I showed you when I'm in a file appart it does not work properly for example my ipc.send does not work when another end does not work.

#

I use this :

document.getElementById('custom-titlebar').addEventListener('mousedown', (e) => {
startDrag(e);
});

#

This way, I can create a custom title bar by moving the window.

rustic jackal
#

Why do you think it doesnt work?

ocean epoch
#

Because when I'm in an appart file I can't move the window or click on my buttons.

rustic jackal
#

Show me devtools console

ocean epoch
rustic jackal
#

Replace it to require again

ocean epoch
#

What ?

rustic jackal
#

#1145312963658514483 message

#

To this

ocean epoch
#

Okay, I'll try.

#

He can't find it

rustic jackal
#

.js in the end

ocean epoch
#

Okay

rustic jackal
#

./js/

ocean epoch
#

Okay

#

Yes, thank you!