Merge pull request #1049 from h3poteto/iss-948

refs #948 Through auto-launch in darwin
This commit is contained in:
AkiraFukushima 2019-09-26 23:20:59 +09:00 committed by GitHub
commit 42e62dc135
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 19 deletions

View File

@ -142,10 +142,18 @@ const accountCache = new AccountCache(accountCachePath)
const soundBasePath =
process.env.NODE_ENV === 'development' ? path.join(__dirname, '../../build/sounds/') : path.join(process.resourcesPath!, 'build/sounds/')
const launcher = new AutoLaunch({
name: 'Whalebird',
path: appPath
})
let launcher: AutoLaunch | null = null
// On MAS build, auto launch is not working.
// We have to use Launch Agent: https://github.com/Teamwork/node-auto-launch/issues/43
// But it is too difficult to build, and Slack does not provide this function in MAS build.
// Therefore I don't provide this function for MacOS.
if (process.platform !== 'darwin') {
launcher = new AutoLaunch({
name: 'Whalebird',
path: appPath
})
}
async function listAccounts(): Promise<Array<LocalAccount>> {
try {
@ -467,14 +475,18 @@ ipcMain.on('remove-all-accounts', (event: Event) => {
})
ipcMain.on('change-auto-launch', (event: Event, enable: boolean) => {
launcher.isEnabled().then(enabled => {
if (!enabled && enable) {
launcher.enable()
} else if (enabled && !enable) {
launcher.disable()
}
event.sender.send('response-change-auto-launch', enable)
})
if (launcher) {
launcher.isEnabled().then(enabled => {
if (!enabled && enable && launcher) {
launcher.enable()
} else if (enabled && !enable && launcher) {
launcher.disable()
}
event.sender.send('response-change-auto-launch', enable)
})
} else {
event.sender.send('response-change-auto-launch', false)
}
})
// badge
@ -882,7 +894,10 @@ ipcMain.on('toot-action-sound', () => {
// preferences
ipcMain.on('get-preferences', async (event: Event) => {
const preferences = new Preferences(preferencesDBPath)
const enabled = await launcher.isEnabled()
let enabled = false
if (launcher) {
enabled = await launcher.isEnabled()
}
await preferences
.update({
general: {

View File

@ -24,7 +24,7 @@
<el-switch id="hideAllAttachments" v-model="timeline_hide_attachments" active-color="#13ce66"> </el-switch>
</el-form-item>
</el-form>
<el-form class="other section" label-position="right" label-width="250px" size="small">
<el-form class="other section" label-position="right" label-width="250px" size="small" v-if="notDarwin">
<h3>{{ $t('preferences.general.other.title') }}</h3>
<el-form-item for="launch" :label="$t('preferences.general.other.launch')">
<el-switch id="launch" v-model="other_launch" active-color="#13ce66"> </el-switch>
@ -34,14 +34,15 @@
</template>
<script>
import { mapState } from 'vuex'
import { mapState, mapGetters } from 'vuex'
export default {
name: 'general',
computed: {
...mapState({
loading: state => state.Preferences.General.loading
...mapState('Preferences/General', {
loading: state => state.loading
}),
...mapGetters('Preferences/General', ['notDarwin']),
sound_fav_rb: {
get() {
return this.$store.state.Preferences.General.general.sound.fav_rb

View File

@ -1,5 +1,5 @@
import { ipcRenderer } from 'electron'
import { Module, MutationTree, ActionTree } from 'vuex'
import { Module, MutationTree, ActionTree, GetterTree } from 'vuex'
import { RootState } from '@/store'
import { Sound } from '~/src/types/sound'
import { Timeline } from '~/src/types/timeline'
@ -139,9 +139,16 @@ const actions: ActionTree<GeneralState, RootState> = {
}
}
const getters: GetterTree<GeneralState, RootState> = {
notDarwin: () => {
return process.platform !== 'darwin'
}
}
export default {
namespaced: true,
state: state,
mutations: mutations,
actions: actions
actions: actions,
getters: getters
} as Module<GeneralState, RootState>