feat: app.moveToApplicationsFolder conflict handling (#18916)
Resolves #18805. We want to keep default move conflict handling behavior in that it's still what most users would expect, but there exist edge cases in which users may not want to be forced into that behavior. This thus introduces an optional conflict handler that allows developers access to more granular move actions. They could now allow the user to choose whether to delete an existing app in favor of the current one being moved, or whether to quit the current app and focus on the existing one should it both exist and be running. I added a fair amount of new documentation outlining this behavior, but if there are things users may benefit from seeing examples of or nuances that should be added please leave feedback!
This commit is contained in:
parent
0db6789210
commit
f6a29707b6
4 changed files with 86 additions and 9 deletions
|
@ -1223,7 +1223,11 @@ This method can only be called before app is ready.
|
|||
Returns `Boolean` - Whether the application is currently running from the
|
||||
systems Application folder. Use in combination with `app.moveToApplicationsFolder()`
|
||||
|
||||
### `app.moveToApplicationsFolder()` _macOS_
|
||||
### `app.moveToApplicationsFolder([options])` _macOS_
|
||||
|
||||
* `options` Object (optional)
|
||||
* `conflictHandler` Function<Boolean> (optional) - A handler for potential conflict in move failure.
|
||||
* `conflictType` String - the type of move conflict encountered by the handler; can be `exists` or `existsAndRunning`, where `exists` means that an app of the same name is present in the Applications directory and `existsAndRunning` means both that it exists and that it's presently running.
|
||||
|
||||
Returns `Boolean` - Whether the move was successful. Please note that if
|
||||
the move is successful, your application will quit and relaunch.
|
||||
|
@ -1236,7 +1240,28 @@ the user to confirm the operation, you may do so using the
|
|||
move to fail. For instance if the user cancels the authorization dialog, this
|
||||
method returns false. If we fail to perform the copy, then this method will
|
||||
throw an error. The message in the error should be informative and tell
|
||||
you exactly what went wrong
|
||||
you exactly what went wrong.
|
||||
|
||||
By default, if an app of the same name as the one being moved exists in the Applications directory and is _not_ running, the existing app will be trashed and the active app moved into its place. If it _is_ running, the pre-existing running app will assume focus and the the previously active app will quit itself. This behavior can be changed by providing the optional conflict handler, where the boolean returned by the handler determines whether or not the move conflict is resolved with default behavior. i.e. returning `false` will ensure no further action is taken, returning `true` will result in the default behavior and the method continuing.
|
||||
|
||||
For example:
|
||||
|
||||
```js
|
||||
app.moveToApplicationsFolder({
|
||||
conflictHandler: (conflictType) => {
|
||||
if (conflictType === 'exists') {
|
||||
return dialog.showMessageBoxSync({
|
||||
type: 'question',
|
||||
buttons: ['Halt Move', 'Continue Move'],
|
||||
defaultId: 0,
|
||||
message: 'An app of this name already exists'
|
||||
}) === 1
|
||||
}
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Would mean that if an app already exists in the user directory, if the user chooses to 'Continue Move' then the function would continue with its default behavior and the existing app will be trashed and the active app moved into its place.
|
||||
|
||||
## Properties
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue