Electron JS problem


#1

I am making program and I want to make a button to change the program theme. The problem is that the code I wrote doesn’t work for me but works for my friend…
this is my code:

const electron = require(“electron”);
const url = require(“url”);
const path = require(“path”);
const {app, BrowserWindow, Menu, File, dialog , ipcMain} = electron;
const fs = require(‘fs’);
const marked = require(‘marked’);

let mainWindow;
let addWindow;

app.on(“ready”, function() {

mainWindow = new BrowserWindow({});

mainWindow.loadURL(url.format({
pathname: path.join(__dirname, “mainWindow.html”),
protocol: “file”,
slashes: true
}));

const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);

Menu.setApplicationMenu(mainMenu)

});

function createFileImplementor() {
let content = " ";

  dialog.showSaveDialog((filename) => {
    if(filename === undefined) {
      nameWindowFile = new BrowserWindow({
        width: 1000,
        height: 600,
        title: "Please Name the File"
      });
    }
    fs.writeFile(filename, content, (err) => {
      if(err) {
        alert("Error:" + err.message);
        return;
      }
    });
  });

}

function createAddWindow() {
addWindow = new BrowserWindow({});

mainWindow.loadURL(url.format({
  pathname: path.join(__dirname, "mainWindow.html"),
  protocol: "file",
  slashes: true
}));

}

const mainMenuTemplate = [
{
label: “File”,
submenu: [

    {label: "New Window",
    accelerator: process.platform == "win32" ? "Ctrl+Shift+N" : "Command+Shift+N",
    click(){
      createAddWindow();
    }
    },

    {label: "New File",
    accelerator: process.platform == "win32" ? "Ctrl+N" : "Command+N",
    click() {
      createFileImplementor();
    }
    },

    {label: "Open File"},

    {label: "Open Folder"},

    {label: "Add Project"},

    {label: "Reopen Project"},

    {label: "Reopen Last Project"},

    {
      label: "Exit",
      accelerator: process.platform == "win32" ? "Ctrl+Q" : "Command+Q",
      click() {
        app.quit();
      }
    },
    {
      label: "Change Theme",
      click()
      {
        changeTheme();
      }
    }
  ],

}
];

function changeTheme()
{
mainWindow.webContents.send(‘theme:change’);
}
this is my mainWindow.html file, sorry that it’s a link, when I tried to paste it in here it did weird things.


#2

Don’t forget to mark your code segments as code when posting them. You can use any GitHub-flavored markdown syntax, or use the </> button above the editor.


#3

thanks for that, any help?


#4

I am pretty sure I forgot how to edit the post… help with that?


#5

You might be too new to edit your first post.

I still can’t read the code, but it seems to me that you haven’t provided any details about your friend’s experience. What’s different between your computer and your friend’s computer?


#6

I will ask him now, it will take some time.


#7

The only difference is that my pc is much stronger.


#8

If there is a difference in results, there must be a difference in environment or input. If you locate that, you will be on the track to figuring out what’s going wrong.