Tracking NWJS progress bar while executing lengthy loop in JavaScript

I'm currently facing some challenges with JavaScript as I attempt to create a desktop application using NW.JS. The issue arises when I drag and drop a .xml file into my app, triggering a function that reads the XML, performs certain tasks, and saves a new file in .csv format. Everything works fine so far, but I now want to incorporate a progress bar that updates during the execution of the function...

I've experimented with setInterval and setTimeout(), yet I keep encountering the same outcome: nothing happens until the function completes.

Below is an excerpt of my code:

// Equivalent to $(document).ready();
function ready(fn) {
    if (document.readyState != 'loading'){
        fn();
    } else {
        document.addEventListener('DOMContentLoaded', fn);
    }
}

// Execute this code when the page has loaded
ready(function(){
    // prevent default behavior of changing page on dropped file
    window.ondragover = function(e) { e.preventDefault(); return false };
    // NOTE: ondrop events WILL NOT WORK without preventing default behavior in the ondragover event!
    window.ondrop = function(e) { e.preventDefault(); return false };

    var holder = document.getElementById('holder');
    holder.ondragover = function () { this.className = 'hover'; return false; };
    holder.ondragleave = function () { this.className = ''; return false; };
    holder.ondrop = function (e) {
        e.preventDefault();

        var file = e.dataTransfer.files[0],
        reader = new FileReader();
        reader.onload = function (event) {
########I'm doing stuff here to convert file and i want to update the progressbar##########

};
        reader.readAsText(file);
        //reader.readAsDataURL(file);

        return false;
    };
});

Thank you for your assistance.

Warm regards,

Answer №1

Upon experimentation with both NWJS and Electron, it became evident that the issue lies in extended processes causing the 'main' Chromium process to prevent rendering. To resolve this, I decided to create a separate child process for communication using Node's IPC. For further information, please refer to this detailed explanation.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When using React, appending a React Link tag to an existing list item may result in the addition of two objects instead of the desired

Trying to create a loop that checks if an object's date matches with a date on a calendar. If it does, I want to add a React Link tag to the respective li element. The loop logic works well, but the issue is when appending the Link tag using createTex ...

Get node extensions set up without the hassle of typing in commands

As part of my internship, I am tasked with setting up a node server for the company. I have successfully installed Node on my Windows computer and now need to install plugins such as:    - nodejs-webpack    - colors &n ...

Guide on Retrieving the Current URL in NodeJS

Currently, I am utilizing express in conjunction with node.js. In my setup, the following code is present: app.get('/callback', async function (req, res) { Whenever a user reaches the callback section of my website, I expect to receive the req ...

Node: Exploring folders through recursive traversal

Node.js is a new world to me, and I'm determined to grasp its async behavior and callback structure. Here's where I'm currently struggling: // IMPORT ------------------------------------------------------------------------ fs = r ...

Is your Firebase Google sign-in popup window flashing and not successfully signing in while using Vue.js?

After implementing the Google sign-in pop-up method in Vue.js, I encountered an issue where the live Google sign-in popup window kept flashing and never successfully signed in. However, this problem did not occur when testing locally. Below is the code fo ...

How can you navigate a self-referencing one-to-many table in Sequelize to find the parent, the parent of the parent, the parent of the parent of the parent, and

I have a model called DriveObject, which has a self-referencing foreign key named parentId For the backend, I am utilizing express and node.js In my code, I have defined the association as follows: driveObject.hasMany(driveObject, { as: 'Children&ap ...

What is the method for invoking an anonymous JavaScript object when its name is unknown?

I've been dynamically loading JavaScript modules with jQuery's getScript function. I want to be able to call an init method that all of these modules contain. Since the modules are loaded dynamically, I would rather not hard code their names. Is ...

Retrieving elements from the DOM using jQuery

UPDATE: JSFIDDLE link. My goal is to synchronize elements from DESKTOP 1 to MOBILE 1 (same for #2) in the fiddle. The error is appearing in the console. Go to DESKTOP 1 and choose NEW RATE from the dropdown list. Keep the console open to observe the issu ...

Guide on parsing JSON data received from the frontend

Here is the HTML code that I am working with: <div id="loginform"> <form class="loginIn" name="loginform"> <input type="text" name="login"> <input type="password" name="password"> <input type="submit" value="Войт ...

Issue with the Edit feature causing conflicts with the local storage and generating error messages

There seems to be an issue with my edit function that is causing it to override the local storage when I attempt to save and interfering with my delete function as well. I have searched through similar posts for a solution but have not been able to pinpo ...

Hide the search popup when the user clicks on the "find" button within the jqgrid

What is the solution to closing the search popup when clicking on the Find button? When I search for data in jqgrid and click on the Find button, the Search popup remains open even though the data has been filtered. How can I close the popup after searchin ...

Invoke the function of a React component prior to its rendering

When attempting to load an article from the database and set it as a component's state, I encounter an issue where the value of the loaded article's state is undefined. It seems like this problem arises because the function for loading data is be ...

Is it possible to execute ng-repeat on-click when ng-show evaluates to true?

I am currently facing an issue with my table that populates using ng-repeat. The table contains 100 rows, and clicking on any row reveals a new table (using ng-show) with more detailed product information. However, the performance of my web app is being af ...

Bringing back a string from an external Ajax call

Learning something new can be challenging, so please bear with me: I've set out to create an image gallery that features a main index page where users can select various project categories, a sub-index page for selecting specific projects within the ...

Having trouble with the input range slider on Chrome? No worries, it's working perfectly fine

I'm currently facing an issue with an input range slider that controls the position of an audio track. It seems to work perfectly in Firefox, but in Chrome, the slider gets stuck and doesn't move when dragged. There is a function in place that up ...

Exploring the differences between a callback function and an asynchronous

In the code snippet below, I have implemented handling for SIGINT and SIGTERM signals in a node.js application. // quit on ctrl+c when running docker in terminal process.on('SIGINT', async () => { console.info('Got SIGINT (aka ctrl+c in ...

Performance of obtaining image data

Is anyone else experiencing a significant lag when trying to retrieve the state of a single pixel on the canvas? Take a look at my JS code below: var state = ctx.getImageData(x,y,1,1).data; state = 'rgba(' + state[0] + ',' + state[1] ...

Utilizing the Aladin Lite application within a React application, despite not being specifically designed for React

I am interested in incorporating the Aladin Lite app into my React application. Typically, embedding the app in a div is straightforward when developing a website without React: <!-- include Aladin Lite CSS file in the head section of your page --> ...

Search for data in Mongoose by utilizing a query object that has been obtained from a query string

After extracting and parsing a querystring from a URL, I am able to map it into an object structure like this: { '$and': [ { length: { '$gt': '2' } }, { length: { '$lt': '55555' } } ] } This object is st ...

What is the best way to get the latest props in the midst of an async function?

There's a fascinating open-source project called react-share, where the ShareButton component offers a prop known as beforeOnClick for customization. I've utilized this beforeOnClick to upload images to our CDN before sharing, ensuring that only ...