mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-11 10:12:00 +08:00
Merge electron-lets-move into application (main process)
This commit is contained in:
parent
a028717a85
commit
50bb99d890
4 changed files with 42 additions and 60 deletions
|
@ -48,7 +48,9 @@ export default class UpdateNotification extends React.Component {
|
||||||
return (
|
return (
|
||||||
<Notification
|
<Notification
|
||||||
priority="4"
|
priority="4"
|
||||||
title={`An update to Mailspring is available ${version ? `(${version})` : ''}`}
|
title={`An update to Mailspring is available ${version
|
||||||
|
? `(${version.replace('Mailspring', '').trim()})`
|
||||||
|
: ''}`}
|
||||||
subtitle="View changelog"
|
subtitle="View changelog"
|
||||||
subtitleAction={this._onViewChangelog}
|
subtitleAction={this._onViewChangelog}
|
||||||
icon="volstead-upgrade.png"
|
icon="volstead-upgrade.png"
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
import { moveToApplications } from 'electron-lets-move';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We want to make sure that people have installed the app in a
|
|
||||||
* reasonable location.
|
|
||||||
*
|
|
||||||
* On the Mac, you can accidentally run the app from the DMG. If you do
|
|
||||||
* this, it will no longer auto-update. It's also common for Mac users to
|
|
||||||
* leave their app in the /Downloads folder (which frequently gets
|
|
||||||
* erased!).
|
|
||||||
*/
|
|
||||||
export function activate() {
|
|
||||||
if (AppEnv.inDevMode() || AppEnv.inSpecMode()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (AppEnv.config.get('askedAboutAppMove')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
moveToApplications(function(err, moved) {
|
|
||||||
if (err) {
|
|
||||||
// log error, something went wrong whilst moving the app.
|
|
||||||
}
|
|
||||||
if (!moved) {
|
|
||||||
// the user asked not to move the app, it's up to the parent application
|
|
||||||
// to store this information and not hassle them again.
|
|
||||||
AppEnv.config.set('askedAboutAppMove', true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function deactivate() {}
|
|
|
@ -1,13 +0,0 @@
|
||||||
{
|
|
||||||
"name": "verify-install-location",
|
|
||||||
"main": "./lib/main",
|
|
||||||
"version": "0.0.1",
|
|
||||||
"description": "Verifies the install location and moves the app to Applications",
|
|
||||||
"license": "GPL-3.0",
|
|
||||||
"engines": {
|
|
||||||
"mailspring": "*"
|
|
||||||
},
|
|
||||||
"windowTypes": {
|
|
||||||
"default": true
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,7 @@
|
||||||
/* eslint global-require: "off" */
|
/* eslint global-require: "off" */
|
||||||
|
|
||||||
import { BrowserWindow, Menu, app, ipcMain, dialog, powerMonitor } from 'electron';
|
import { BrowserWindow, Menu, app, ipcMain, dialog, powerMonitor } from 'electron';
|
||||||
|
import { moveToApplications } from 'electron-lets-move';
|
||||||
|
|
||||||
import fs from 'fs-plus';
|
import fs from 'fs-plus';
|
||||||
import url from 'url';
|
import url from 'url';
|
||||||
|
@ -72,6 +73,9 @@ export default class Application extends EventEmitter {
|
||||||
initializeInBackground = false;
|
initializeInBackground = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.oneTimeMoveToApplications();
|
||||||
|
await this.oneTimeAddToDock();
|
||||||
|
|
||||||
this.autoUpdateManager = new AutoUpdateManager(version, config, specMode);
|
this.autoUpdateManager = new AutoUpdateManager(version, config, specMode);
|
||||||
this.applicationMenu = new ApplicationMenu(version);
|
this.applicationMenu = new ApplicationMenu(version);
|
||||||
this.windowManager = new WindowManager({
|
this.windowManager = new WindowManager({
|
||||||
|
@ -95,19 +99,6 @@ export default class Application extends EventEmitter {
|
||||||
} else {
|
} else {
|
||||||
app.setAsDefaultProtocolClient('mailspring');
|
app.setAsDefaultProtocolClient('mailspring');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.platform === 'darwin') {
|
|
||||||
const addedToDock = config.get('addedToDock');
|
|
||||||
const appPath = process.argv[0];
|
|
||||||
if (!addedToDock && appPath.includes('/Applications/') && appPath.includes('.app/')) {
|
|
||||||
proc.exec(
|
|
||||||
`defaults write com.apple.dock persistent-apps -array-add "<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>${appPath.split(
|
|
||||||
'.app/'
|
|
||||||
)[0]}.app/</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"`
|
|
||||||
);
|
|
||||||
config.set('addedToDock', true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getMainWindow() {
|
getMainWindow() {
|
||||||
|
@ -160,6 +151,41 @@ export default class Application extends EventEmitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async oneTimeMoveToApplications() {
|
||||||
|
if (this.devMode || this.specMode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.config.get('askedAboutAppMove')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await moveToApplications();
|
||||||
|
this.config.set('askedAboutAppMove', true);
|
||||||
|
} catch (err) {
|
||||||
|
dialog.showMessageBox({
|
||||||
|
type: 'warning',
|
||||||
|
buttons: ['Okay'],
|
||||||
|
message: `We encountered a problem moving to the Applications folder. Try quitting the application and moving it manually.`,
|
||||||
|
detail: err.toString(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async oneTimeAddToDock() {
|
||||||
|
if (process.platform !== 'darwin') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const addedToDock = this.config.get('addedToDock');
|
||||||
|
const appPath = process.argv[0];
|
||||||
|
if (!addedToDock && appPath.includes('/Applications/') && appPath.includes('.app/')) {
|
||||||
|
const appBundlePath = appPath.split('.app/')[0];
|
||||||
|
proc.exec(
|
||||||
|
`defaults write com.apple.dock persistent-apps -array-add "<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>${appBundlePath}.app/</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"`
|
||||||
|
);
|
||||||
|
this.config.set('addedToDock', true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// On Windows, removing a file can fail if a process still has it open. When
|
// On Windows, removing a file can fail if a process still has it open. When
|
||||||
// we close windows and log out, we need to wait for these processes to completely
|
// we close windows and log out, we need to wait for these processes to completely
|
||||||
// exit and then delete the file. It's hard to tell when this happens, so we just
|
// exit and then delete the file. It's hard to tell when this happens, so we just
|
||||||
|
|
Loading…
Reference in a new issue