Giter VIP home page Giter VIP logo

Comments (5)

holidaycottages avatar holidaycottages commented on June 17, 2024 1

Worked it out, wasnt reading properly

from electron-progressbar.

AndersonMamede avatar AndersonMamede commented on June 17, 2024

Hi there!

I've just created an example for you with buttons to show/hide the progressbar.

In case you can't make it work, please paste your code here so I can take a look.

main.js:

const {app, BrowserWindow, ipcMain} = require('electron');
const ProgressBar = require('electron-progressbar');

let mainWindow;
let progressBar;

function loadApp () {
  mainWindow = new BrowserWindow({
    width : 300,
    height : 200
  });
  
  mainWindow.loadURL(`file://${__dirname}/test_page.html`);
};

function showProgressbar () {
  if (progressBar) {
    return;
  }
  
  progressBar = new ProgressBar({
    text: 'Preparing data...',
    detail: 'Wait...'
  });
  
  progressBar
    .on('completed', function() {
      progressBar.detail = 'Task completed. Exiting...';
      progressBar = null;
    });
  
  // launch the task...
  // launchTask();
}

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

function init () {
  loadApp();
  
  ipcMain.on('show-progressbar', showProgressbar);
  
  ipcMain.on('set-progressbar-completed', setProgressbarCompleted);
}

app.on("ready", init);

test_page.html:

<!DOCTYPE html>
<html>
	<head>
		<title>Test</title>
	</head>
	<body>
		<div style="text-align:center">
			Test page<br><br>
			<button id="show-progressbar">Show progressbar</button><br><br>
			<button id="set-progressbar-completed">Set progressbar completed</button>
		</div>
		<script>
			const ipc = require('electron').ipcRenderer;
			
			document.querySelector('#show-progressbar').addEventListener('click', function(){
				ipc.send('show-progressbar');
			});
			
			document.querySelector('#set-progressbar-completed').addEventListener('click', function(){
				ipc.send('set-progressbar-completed');
			});
		</script>
	</body>
</html>

from electron-progressbar.

holidaycottages avatar holidaycottages commented on June 17, 2024

Thank you so much. Got it working.

I have changed it so I can pass in a maxValue, which works, but then I added another function to update the progress, as in my button on click it loops around processing some images, I want to update the progress bar when each one is complete, currently it just pops up and says Wait... as per the setup and then disappears when the loop is done.

Any ideas?

from electron-progressbar.

AndersonMamede avatar AndersonMamede commented on June 17, 2024

You can pass multiple parameters to the send function:

ipc.send('set-progressbar-value', {value:9});

And then you can set the progress bar's value like this (inside your "main.js", for example):

progressBar.value = x;

from electron-progressbar.

AndersonMamede avatar AndersonMamede commented on June 17, 2024

Glad you got it working! =)

from electron-progressbar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.