1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2025-02-03 10:47:34 +01:00

Add auto launch method

This commit is contained in:
AkiraFukushima 2019-09-23 19:31:25 +09:00
parent 5d6825a7e5
commit b990229cc1
3 changed files with 54 additions and 0 deletions

33
package-lock.json generated
View File

@ -1912,6 +1912,12 @@
"resolved": "https://registry.npmjs.org/@trodi/electron-splashscreen/-/electron-splashscreen-0.3.4.tgz",
"integrity": "sha512-nYF+sfNIEUhZPyzYUOpcqyCZoDYmMfZq8jLhEolvQFSVwrJ7gAlPhhMxpuw/qpCzPErUkFLEtdGGvK1tGtLuvQ=="
},
"@types/auto-launch": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@types/auto-launch/-/auto-launch-5.0.1.tgz",
"integrity": "sha512-+KQ+/koZ7sJXnf5cnCANofY6yXAdYJNEoVZEuWcwJfuWbUp9u6l09I7KhwD+ivU+cdz7JId4V5ukxscWtHdSuw==",
"dev": true
},
"@types/babel__core": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.0.tgz",
@ -2971,6 +2977,11 @@
"default-require-extensions": "^2.0.0"
}
},
"applescript": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/applescript/-/applescript-1.0.0.tgz",
"integrity": "sha1-u4evVoytA0pOSMS9r2Bno6JwExc="
},
"aproba": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz",
@ -3242,6 +3253,18 @@
"integrity": "sha1-0IiFvmubv5Q5/gh8dihyRfCoFFA=",
"dev": true
},
"auto-launch": {
"version": "5.0.5",
"resolved": "https://registry.npmjs.org/auto-launch/-/auto-launch-5.0.5.tgz",
"integrity": "sha512-ppdF4mihhYzMYLuCcx9H/c5TUOCev8uM7en53zWVQhyYAJrurd2bFZx3qQVeJKF2jrc7rsPRNN5cD+i23l6PdA==",
"requires": {
"applescript": "^1.0.0",
"mkdirp": "^0.5.1",
"path-is-absolute": "^1.0.0",
"untildify": "^3.0.2",
"winreg": "1.2.4"
}
},
"autoprefixer": {
"version": "9.6.1",
"resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-9.6.1.tgz",
@ -21060,6 +21083,11 @@
}
}
},
"untildify": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/untildify/-/untildify-3.0.3.tgz",
"integrity": "sha512-iSk/J8efr8uPT/Z4eSUywnqyrQU7DSdMfdqK4iWEaUVVmcP5JcnpRqmVMwcwcnmI1ATFNgC5V90u09tBynNFKA=="
},
"unused-filename": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unused-filename/-/unused-filename-1.0.0.tgz",
@ -22477,6 +22505,11 @@
}
}
},
"winreg": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/winreg/-/winreg-1.2.4.tgz",
"integrity": "sha1-ugZWKbepJRMOFXeRCM9UCZDpjRs="
},
"wordwrap": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz",

View File

@ -163,6 +163,7 @@
"@trodi/electron-splashscreen": "^0.3.4",
"about-window": "^1.13.1",
"animate.css": "^3.7.0",
"auto-launch": "^5.0.5",
"axios": "^0.18.1",
"boom": "^7.3.0",
"deep-extend": "^0.6.0",
@ -208,6 +209,7 @@
"@babel/preset-env": "^7.4.3",
"@babel/runtime": "^7.4.3",
"@mapbox/stylelint-processor-arbitrary-tags": "^0.2.0",
"@types/auto-launch": "^5.0.1",
"@types/electron-json-storage": "^4.0.0",
"@types/i18next": "^12.1.0",
"@types/jest": "^24.0.15",

View File

@ -24,6 +24,7 @@ import { initSplashScreen, Config } from '@trodi/electron-splashscreen'
import openAboutWindow from 'about-window'
import { Status, Notification as RemoteNotification, Account as RemoteAccount } from 'megalodon'
import sanitizeHtml from 'sanitize-html'
import AutoLaunch from 'auto-launch'
import pkg from '~/package.json'
import Authentication from './auth'
@ -107,6 +108,8 @@ const splashURL =
// https://github.com/louischatriot/nedb/issues/459
const userData = app.getPath('userData')
const appPath = app.getPath('exe')
const accountDBPath = process.env.NODE_ENV === 'production' ? userData + '/db/account.db' : 'account.db'
let accountDB = new Datastore({
filename: accountDBPath,
@ -458,6 +461,22 @@ ipcMain.on('remove-all-accounts', (event: Event) => {
})
})
ipcMain.on('change-auto-launch', (event: Event, enable: boolean) => {
const launcher = new AutoLaunch({
name: 'Whalebird',
path: appPath
})
launcher.isEnabled().then(enabled => {
if (!enabled && enable) {
launcher.enable()
} else if (enabled && !enable) {
launcher.disable()
}
event.sender.send('response-change-auto-launch', enable)
return
})
})
// badge
ipcMain.on('reset-badge', () => {
if (process.platform === 'darwin') {