Skip to content

A full-featured download manager.

fix: check app is running in dmg

Dr_rOotf0a6eb7ffe40
diff --git a/src/main/Application.js b/src/main/Application.js
index ac158d84..7147bea4 100644
--- a/src/main/Application.js
+++ b/src/main/Application.js
@@ -20,14 +20,14 @@ export default class Application extends EventEmitter {
this.configManager = new ConfigManager()
+ this.windowManager = new WindowManager()
+
this.engine = new Engine({
systemConfig: this.configManager.getSystemConfig(),
userConfig: this.configManager.getUserConfig()
})
this.startEngine()
- this.windowManager = new WindowManager()
-
this.menuManager = new MenuManager()
this.menuManager.setup(this.locale)
diff --git a/src/main/index.js b/src/main/index.js
index 2539cf6d..3298cda4 100644
--- a/src/main/index.js
+++ b/src/main/index.js
@@ -2,13 +2,17 @@ import { app } from 'electron'
import is from 'electron-is'
import logger from './core/Logger'
+import {
+ isRunningInDmg,
+ moveAppToApplicationsFolder
+} from './utils/index'
import Application from './Application'
if (process.env.NODE_ENV !== 'development') {
global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
}
-function init () {
+function _init () {
let openURL = null
if (!is.mas()) {
app.on('open-url', (event, url) => {
@@ -48,6 +52,14 @@ function init () {
})
}
+function init () {
+ if (isRunningInDmg()) {
+ moveAppToApplicationsFolder()
+ return
+ }
+ _init()
+}
+
// Mac App Store Sandboxed App Not support requestSingleInstanceLock
if (is.mas()) {
init()
diff --git a/src/main/utils/index.js b/src/main/utils/index.js
index 7f9d513e..03565319 100644
--- a/src/main/utils/index.js
+++ b/src/main/utils/index.js
@@ -1,4 +1,5 @@
import { app } from 'electron'
+import is from 'electron-is'
import { resolve } from 'path'
import logger from '../core/Logger'
import engineBinMap from '../configs/engine'
@@ -33,3 +34,27 @@ export function transformConfig (config) {
}
return result
}
+
+export function isRunningInDmg () {
+ if (!is.macOS()) {
+ return false
+ }
+ const appPath = app.getAppPath()
+ const result = appPath.startsWith('/Volumes/')
+ return result
+}
+
+export function moveAppToApplicationsFolder () {
+ return new Promise((resolve, reject) => {
+ try {
+ const result = app.moveToApplicationsFolder()
+ if (result) {
+ resolve(result)
+ } else {
+ reject(new Error('应用程序移动失败'))
+ }
+ } catch (err) {
+ reject(err)
+ }
+ })
+}