Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore more than one events for changing the main script file #48

Merged
merged 1 commit into from Jun 22, 2018
Merged

Ignore more than one events for changing the main script file #48

merged 1 commit into from Jun 22, 2018

Conversation

ghost
Copy link

@ghost ghost commented Apr 1, 2018

This PR makes it impossible to reload once app.quit() is cancelled, but it can be avoided at specifying hardResetMethod: 'exit'.

Fixes #46

@HeilTec
Copy link
Contributor

HeilTec commented Apr 4, 2018

This makes perfect sense.
Logical and minimal change to effect the desired function using the 'exit' method.

Still ... it would be nice if an implementation could be found that would allow all cases to work, even after canceling the 'quit' method.

Would a setTimeout be able to do the trick?

    const spawnAndQuit = () => {
      // Detaching child is useful when in Windows to let child
      // live after the parent is killed
      let child = spawn(eXecutable, [appPath], {
        detached: true,
        stdio: 'inherit'
      })
      child.unref()
      // Kamikaze!

      // In cases where an app overrides the default closing or quiting actions
      // firing an `app.quit()` may not actually quit the app. In these cases
      // you can use `app.exit()` to gracefully close the app.
      if (opts.hardResetMethod === 'exit') {
        app.exit()
      } else {
        app.quit()
      }
    }
    var resetEnqueued = null
    chokidar.watch(mainFile).on('change', () => {
        resetEnqueued && clearTimeout(resetEnqueued)
        resetEnqueued = setTimeout( () => {
          spawnAndQuit() // perhaps In-line current code directly here?
    }, 250) 

... or does the exit method cancel the timer?

@yan-foto
Copy link
Owner

yan-foto commented Apr 6, 2018

Thanks! Sorry for the late reply. This sounds great! Please give me a little bit time to merge it.
@HeilTec I am usually very carefull with timeouts. But it might be worth a try.

@ghost
Copy link
Author

ghost commented Apr 6, 2018

@HeilTec I didn't think of using setTimeout.
That seems a good idea, but the delay value should be larger than 250ms.

I did a quick test with two Windows 10 laptops.
In one, I changed the main script once and change event is fired twice at an around 300ms interval.
In other one, it's fired three times at around 600ms intervals.

It's necessary to consider that the delay of running quit method depends to PC performance.

@yan-foto yan-foto merged commit bd1ee8d into yan-foto:master Jun 22, 2018
@yan-foto
Copy link
Owner

I really suck at maintaining projects! More than 2 months for a simple merge 🙈 Sorry everyone!

@mscoobby
Copy link

mscoobby commented Jul 9, 2019

Is this going to be released as it's not in 1.4.0? Also consider #57 these two fixes many of the hardReset problems.

@yan-foto
Copy link
Owner

yan-foto commented Jul 9, 2019

@mscoobby in v1.4.0 instead of having two separate watchers (one for the main file and another for the rest), there is a single watcher. It is due to many requests from people wanting to have hard resets for every change and not only the main file.

@mscoobby
Copy link

mscoobby commented Jul 9, 2019

@yan-foto yes but using hardWatcher.on(... instead of hardWatcher.once(.. causes it to spawn 2 processes as pointed out in #46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hard resets result in spawning two electron processes
3 participants