-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #595 from responsively-org/feature/macos-move-to-a…
…pplications Feature/macos move to applications
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
conflict handler methods for moveToApplication event on mac | ||
https://www.electronjs.org/docs/api/app#appmovetoapplicationsfolderoptions-macos | ||
*/ | ||
|
||
// @flow | ||
|
||
import settings from 'electron-settings'; | ||
import {CAN_PROMPT_MOVE_TO_APPLICATIONS} from './constants/settingKeys'; | ||
|
||
let conflictMessage = 'An app of this name already exists'; | ||
const moveFailedMessage = 'Something went wrong while moving application'; | ||
|
||
const confirmMove: boolean = async dialog => { | ||
if (process.env.NODE_ENV !== 'production') { | ||
return false; | ||
} | ||
const canPrompt = settings.get(CAN_PROMPT_MOVE_TO_APPLICATIONS) ?? true; | ||
if (!canPrompt) { | ||
return false; | ||
} | ||
const {response, checkboxChecked} = await dialog.showMessageBox({ | ||
type: 'error', | ||
message: 'Move to Applications folder?', | ||
detail: | ||
'Responsively App should be in the Applications folder to be able to work properly.', | ||
checkboxLabel: `Don't ask me again`, | ||
buttons: ['Move', 'Cancel'], | ||
}); | ||
if (checkboxChecked) { | ||
settings.set(CAN_PROMPT_MOVE_TO_APPLICATIONS, false); | ||
} | ||
return response === 0; | ||
}; | ||
|
||
const conflictHandler = (conflictType, dialog) => { | ||
if (conflictType === 'exists' || conflictType === 'existsAndRunning') { | ||
conflictMessage = | ||
conflictType === 'existsAndRunning' | ||
? `${conflictMessage} and running` | ||
: conflictMessage; | ||
|
||
return ( | ||
dialog.showMessageBoxSync({ | ||
type: 'question', | ||
buttons: ['Halt Move', 'Continue Move'], | ||
defaultId: 0, | ||
message: conflictMessage, | ||
}) === 1 | ||
); | ||
} | ||
}; | ||
|
||
const movingFailed = dialog => { | ||
dialog.showMessageBoxSync({ | ||
type: 'error', | ||
message: moveFailedMessage, | ||
}); | ||
}; | ||
|
||
export {conflictHandler, movingFailed, confirmMove}; |