electron-progressbar icon indicating copy to clipboard operation
electron-progressbar copied to clipboard

Progress bar not showing up

Open saurjk opened this issue 7 years ago • 6 comments

Hi, I saw the issue #9 , and did update the progress bar to version 1.2.0, however, I have the same issue, well not exactly the same. When I create a new progress bar on App Ready, it shows the progress bar and it's ok. However, when I start it later, as shown in the following code, I just get a blank window.

Node: 10.15.0 Electron: 4.0.4 electron-progressbar: 1.2.0

Output: capture

In Addition to the previous, it shows up when the Task is completed.

untitled

Code:


const { app, BrowserWindow, Menu , ipcMain } = require('electron'),
    url = require('url'),
    path = require('path'),
    parser = require('./main/Parser'),
    ProgressBar = require('electron-progressbar');

// process.env.NODE_ENV = 'production';
process.env.NODE_ENV = 'development';

let mainWindow, progressBar;

app.on('ready', () => {
    mainWindow = new BrowserWindow({
        webPreferences: {
            nodeIntegration: false,
            preload: path.join(__dirname, 'assets/js/preload.js')
        }
    });

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

    mainWindow.on('closed', () => {
        app.quit();
    })

    // Build menut from template
    const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);
    //Insert Menu
    Menu.setApplicationMenu(mainMenu);
})

ipcMain.on('parse:logFiles', (e, item) => {
    parser.setLogFiles(item);
})

ipcMain.on('parse:options', async (e, item) => {
  
    showProgressbar();
    try {
        parser.setOptions(item);
        const {result, parsedFilePath} = await parser.startParse();
        console.log(`App: ${result}, Directory: ${parsedFilePath}`);
        mainWindow.webContents.send('parse:done', parsedFilePath);
        setProgressbarCompleted();
    } catch (error) {
        console.log(error);
    }
})

function showProgressbar () {
	if (progressBar) {
		return;
	}
	
	progressBar = new ProgressBar({
        title: 'Parsing',
		text: 'Parsing files...',
        detail: 'Wait...',
        options: {
            closeOnComplete: false
        },
		browserWindow: {
			parent: mainWindow
        }
	});
	
	progressBar
		.on('completed', function() {
			progressBar.detail = 'Task completed. Exiting...';
			progressBar = null;
		});
}

function setProgressbarCompleted () {
	if (progressBar) {
		progressBar.setCompleted();
	}
}

// Create menut template
const mainMenuTemplate = [
    {
        label: 'File',
        submenu: [
            {
                label: 'Quit',
                accelerator: process.platform === 'darwin' ? 'Command+Q' : 'Ctrl+Q',
                click() {
                    app.quit();
                }
            }
        ]
    }
];

// If mac, add empty object to menu
if (process.platform === 'darwin') {
    mainMenuTemplate.unshift({});
}

// Add developer tools item if not in production
if (process.env.NODE_ENV !== 'production') {
    mainMenuTemplate.push({
        label: 'Developer Tools',
        submenu: [
            {
                label: 'Toggle DevTools',
                accelerator: process.platform === 'darwin' ? 'Command+I' : 'Ctrl+I',
                click(item, focusedWindow) {
                    focusedWindow.toggleDevTools();
                }
            },
            {
                role: 'reload'
            }
        ]
    });
}

Also, even though I have set `` closeOnComplete: false, it still closes the dialog box.


saurjk avatar Feb 13 '19 09:02 saurjk

Hello brother, I solved this by including following code in the source code of electron progress bar, this code need to be included in the browser window code of

webPreferences: { nodeIntegration: true } So the chaged source code looks like this

browserWindow: { parent: null, modal: true, resizable: false, closable: false, minimizable: false, maximizable: false, width: 500, height: 170, webPreferences: { nodeIntegration: true } }

thepraveenpratap avatar May 09 '19 11:05 thepraveenpratap

@impraveensingh this fixed it for me 2, you should create a PR for it ;) gj

whiteadi avatar May 13 '19 13:05 whiteadi

You can just pass the node option along when creating the progress bar like so:

new ProgressBar({
    text: 'Preparing data...',
    detail: 'Wait...',
    browserWindow: {
        webPreferences: {
            nodeIntegration: true
        }
    }
})

Stanvoets avatar Jun 01 '19 18:06 Stanvoets

Correct format is:

new ProgressBar({
        text: 'Preparing data...',
        detail: 'Wait...',
        browserWindow: {
                webPreferences: {
                        nodeIntegration: true
                }
        }
})

aldyrosell avatar Dec 08 '20 09:12 aldyrosell

Hello guys,

Thank you all for figuring this out and for the contribution!

I'm updating electron-progressbar and making nodeIntegration enabled by default (I just merged #14 ) as I can see it's a common issue :)

AndersonMamede avatar Dec 08 '20 21:12 AndersonMamede

electron-progressbar v2.0.0 has just been released and includes the above mentioned changes (enable nodeIntegration by default). See changelog here

AndersonMamede avatar Dec 09 '20 00:12 AndersonMamede