feat: more operations for close | 为关闭app操作提供更多选项 (#918)

* feat: more operations for close

* remove minimizeToTray form initLocalStorage

Co-authored-by: qier222 <qier222@outlook.com>
Co-authored-by: qier222 <qier2222@gmail.com>
This commit is contained in:
memorydream 2021-09-25 15:41:25 +08:00 committed by qier222
parent 8b089e6cf4
commit 17ef0e927c
No known key found for this signature in database
GPG Key ID: 9C85007ED905F14D
8 changed files with 91 additions and 43 deletions

View File

@ -201,14 +201,15 @@ class Background {
this.window.on('close', e => {
log('windows close event');
if (this.willQuitApp) {
let closeOpt = this.store.get('settings.closeAppOption');
if (this.willQuitApp && (closeOpt === 'exit' || closeOpt === 'ask')) {
/* the user tried to quit the app */
this.window = null;
app.quit();
} else {
/* the user only tried to close the window */
e.preventDefault();
this.window.hide();
this.window.minimize();
}
});
@ -223,7 +224,7 @@ class Background {
this.window.on('minimize', () => {
if (
['win32', 'linux'].includes(process.platform) &&
this.store.get('settings.minimizeToTray')
this.store.get('settings.closeAppOption') === 'minimizeToTray'
) {
this.window.hide();
}

View File

@ -39,30 +39,21 @@ export function initIpcMain(win, store) {
ipcMain.on('close', e => {
if (process.platform == 'darwin') {
win.hide();
exitAsk(e);
return;
}
let closeOpt = store.get('settings.closeAppOption');
if (closeOpt === 'exit') {
win = null;
//app.quit();
app.exit(); //exit()直接关闭客户端不会执行quit();
} else if (closeOpt === 'minimize' || closeOpt === 'minimizeToTray') {
e.preventDefault(); //阻止默认行为
win.minimize(); //调用 最小化实例方法
} else {
exitAsk(e);
}
e.preventDefault(); //阻止默认行为
dialog
.showMessageBox({
type: 'info',
title: 'Information',
cancelId: 2,
defaultId: 0,
message: '确定要关闭吗?',
buttons: ['最小化', '直接退出'],
})
.then(result => {
if (result.response == 0) {
e.preventDefault(); //阻止默认行为
win.minimize(); //调用 最小化实例方法
} else if (result.response == 1) {
win = null;
//app.quit();
app.exit(); //exit()直接关闭客户端不会执行quit();
}
})
.catch(err => {
log(err);
});
});
ipcMain.on('minimize', () => {
@ -156,4 +147,30 @@ export function initIpcMain(win, store) {
globalShortcut.unregisterAll();
registerGlobalShortcut(win, store);
});
const exitAsk = e => {
e.preventDefault(); //阻止默认行为
dialog
.showMessageBox({
type: 'info',
title: 'Information',
cancelId: 2,
defaultId: 0,
message: '确定要关闭吗?',
buttons: ['最小化', '直接退出'],
})
.then(result => {
if (result.response == 0) {
e.preventDefault(); //阻止默认行为
win.minimize(); //调用 最小化实例方法
} else if (result.response == 1) {
win = null;
//app.quit();
app.exit(); //exit()直接关闭客户端不会执行quit();
}
})
.catch(err => {
log(err);
});
};
}

View File

@ -151,7 +151,6 @@ export default {
clearSongsCache: 'Clear Songs Cache',
cacheCount: 'Cached {song} songs ({size})',
showLyricsTranslation: 'Show lyrics translation',
minimizeToTray: 'Minimize to tray',
showPlaylistsByAppleMusic: 'Show playlists by Apple Music',
enableDiscordRichPresence: 'Enable Discord Rich Presence',
enableGlobalShortcut: 'Enable Global Shortcut',
@ -162,6 +161,13 @@ export default {
on: 'On',
dynamic: 'Dynamic (High GPU usage)',
},
closeAppOption: {
text: 'Close App...',
ask: 'Ask',
exit: 'Exit',
minimize: 'Minimize',
minimizeToTray: 'Minimize to tray',
},
},
contextMenu: {
play: 'Play',

View File

@ -147,7 +147,6 @@ export default {
clearSongsCache: 'Müzik çerezlerini temizle',
cacheCount: 'Çerezlenen {song} Müzikler ({size})',
showLyricsTranslation: 'Müzik sözlerinin çevirilerini göster',
minimizeToTray: 'Küçült',
showPlaylistsByAppleMusic: "Apple Music'in Çalma Listelerini Göster",
enableDiscordRichPresence: 'Discord gösterimini aktifleştir',
showLibraryDefault: 'Kitaplık Varsayılanını göster',
@ -157,6 +156,13 @@ export default {
on: 'açık',
dynamic: 'dinamik(Yüksek GPU kullanımı)',
},
closeAppOption: {
text: 'Close App...',
ask: 'Ask',
exit: 'Exit',
minimize: 'Minimize',
minimizeToTray: 'Küçült',
},
},
contextMenu: {
play: 'Oynat',

View File

@ -152,7 +152,6 @@ export default {
clearSongsCache: '清除歌曲缓存',
cacheCount: '已缓存 {song} 首 ({size})',
showLyricsTranslation: '显示歌词翻译',
minimizeToTray: '最小化到托盘',
showPlaylistsByAppleMusic: '首页显示来自 Apple Music 的歌单',
enableDiscordRichPresence: '启用 Discord Rich Presence',
enableGlobalShortcut: '启用全局快捷键',
@ -163,6 +162,13 @@ export default {
on: '打开',
dynamic: '动态GPU 占用较高)',
},
closeAppOption: {
text: '关闭主面板时...',
ask: '询问',
exit: '退出',
minimize: '最小化',
minimizeToTray: '最小化到托盘',
},
},
contextMenu: {
play: '播放',

View File

@ -159,6 +159,13 @@ export default {
on: '開啟',
dynamic: '動態GPU 占用較高)',
},
closeAppOption: {
text: '關閉主面板時...',
ask: '詢問',
exit: '退出',
minimize: '最小化',
minimizeToTray: '最小化到系統列',
},
},
contextMenu: {
play: '播放',

View File

@ -22,7 +22,7 @@ let localStorage = {
nyancatStyle: false,
showLyricsTranslation: true,
lyricsBackground: true,
minimizeToTray: false,
closeAppOption: 'ask',
enableDiscordRichPresence: false,
enableGlobalShortcut: true,
showLibraryDefault: false,

View File

@ -285,18 +285,23 @@
<h3>其他</h3>
<div v-if="isElectron && !isMac" class="item">
<div class="left">
<div class="title">{{ $t('settings.minimizeToTray') }}</div>
<div class="title"> {{ $t('settings.closeAppOption.text') }} </div>
</div>
<div class="right">
<div class="toggle">
<input
id="minimize-to-tray"
v-model="minimizeToTray"
type="checkbox"
name="minimize-to-tray"
/>
<label for="minimize-to-tray"></label>
</div>
<select v-model="closeAppOption">
<option value="ask">
{{ $t('settings.closeAppOption.ask') }}
</option>
<option value="exit">
{{ $t('settings.closeAppOption.exit') }}
</option>
<option value="minimize">
{{ $t('settings.closeAppOption.minimize') }}
</option>
<option value="minimizeToTray">
{{ $t('settings.closeAppOption.minimizeToTray') }}
</option>
</select>
</div>
</div>
@ -723,13 +728,13 @@ export default {
});
},
},
minimizeToTray: {
closeAppOption: {
get() {
return this.settings.minimizeToTray;
return this.settings.closeAppOption;
},
set(value) {
this.$store.commit('updateSettings', {
key: 'minimizeToTray',
key: 'closeAppOption',
value,
});
},