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
New makeSingleInstance API #12782
Merged
Merged
New makeSingleInstance API #12782
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
01bef05
Refactor app.makeSingleInstance
MarshallOfSound cc3062a
Fix spec, we don't need process.nextTick hacks any more
MarshallOfSound 24667e1
Make deprecation TODO for the return value of makeSingleInstance
MarshallOfSound 0e83284
Refactor makeSingleInstance to requestSingleInstanceLock and add appr…
MarshallOfSound 067234e
I swear this isn't tricking the linter
MarshallOfSound 85e3d16
Make const
MarshallOfSound d9b6a24
Add deprecation warnings for release, and add to planned-breaking-cha…
MarshallOfSound File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,21 @@ for (let name of events) { | |
}) | ||
} | ||
|
||
// TODO(MarshallOfSound): Remove in 4.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be added to docs/tutorial/planned-breaking-changes.md |
||
app.releaseSingleInstance = () => { | ||
deprecate.warn('app.releaseSingleInstance(cb)', 'app.releaseSingleInstanceLock()') | ||
app.releaseSingleInstanceLock() | ||
} | ||
|
||
// TODO(MarshallOfSound): Remove in 4.0 | ||
app.makeSingleInstance = (oldStyleFn) => { | ||
deprecate.warn('app.makeSingleInstance(cb)', 'app.requestSingleInstanceLock() and app.on(\'second-instance\', cb)') | ||
if (oldStyleFn && typeof oldStyleFn === 'function') { | ||
app.on('second-instance', (event, ...args) => oldStyleFn(...args)) | ||
} | ||
return !app.requestSingleInstanceLock() | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs a deprecate mesage for |
||
// Wrappers for native classes. | ||
const {DownloadItem} = process.atomBinding('download_item') | ||
Object.setPrototypeOf(DownloadItem.prototype, EventEmitter.prototype) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const {app} = require('electron') | ||
|
||
app.once('ready', () => { | ||
console.log('started') // ping parent | ||
}) | ||
|
||
const shouldExit = app.makeSingleInstance(() => { | ||
setImmediate(() => app.exit(0)) | ||
}) | ||
|
||
if (shouldExit) { | ||
app.exit(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "electron-app-singleton", | ||
"main": "main.js" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not to beat a dead horse, but what is the use case for this method being public API? 😃
I'm not completely opposed to this; more like I need help understanding who would use this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example: A helper module for handling opening files in an Electron app, will need to know whether to expect
second-instance
events or whether to handle multiple instances 👍Basically helpful for third party modules that devs might use, not first party code inside apps.