Skip to content

Commit

Permalink
Merge pull request #595 from responsively-org/feature/macos-move-to-a…
Browse files Browse the repository at this point in the history
…pplications

Feature/macos move to applications
  • Loading branch information
manojVivek authored May 20, 2021
2 parents c5e7418 + 9f263c1 commit 8ac1411
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions desktop-app/app/constants/settingKeys.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const ACTIVE_DEVICES = 'activeDevices';
export const CUSTOM_DEVICES = 'customDevices';
export const USER_PREFERENCES = 'userPreferences';
export const CAN_PROMPT_MOVE_TO_APPLICATIONS = 'canPromptMoveToApplications';
export const NETWORK_CONFIGURATION = 'networkConfiguration';
export const BOOKMARKS = 'bookmarks';
export const STATUS_BAR_VISIBILITY = 'statusBarVisibility';
Expand Down
19 changes: 19 additions & 0 deletions desktop-app/app/main.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ import {initMainShortcutManager} from './shortcut-manager/main-shortcut-manager'
import {appUpdater} from './app-updater';
import trimStart from 'lodash/trimStart';
import isURL from 'validator/lib/isURL';
import {
confirmMove,
conflictHandler,
movingFailed,
} from './move-to-applications';
import {
initBrowserSync,
getBrowserSyncHost,
Expand Down Expand Up @@ -252,6 +257,19 @@ app.on('ready', async () => {
if (hasActiveWindow) {
return;
}
if (
process.platform === 'darwin' &&
!app.isInApplicationsFolder() &&
(await confirmMove(dialog))
) {
try {
app.moveToApplicationsFolder({
conflictHandler: conflictHandler.bind(this, dialog),
});
} catch (e) {
movingFailed(dialog);
}
}
// Set theme based on user preference
const themeSource = (settings.get(USER_PREFERENCES) || {}).theme;
if (themeSource) {
Expand Down Expand Up @@ -330,6 +348,7 @@ const createWindow = async () => {
nodeIntegrationInWorker: true,
webviewTag: true,
enableRemoteModule: true,
contextIsolation: false,
},
titleBarStyle: 'hidden',
icon: iconPath,
Expand Down
61 changes: 61 additions & 0 deletions desktop-app/app/move-to-applications.js
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};

0 comments on commit 8ac1411

Please sign in to comment.