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>
master
memorydream 3 years ago committed by qier222
parent 8b089e6cf4
commit 17ef0e927c
No known key found for this signature in database
GPG Key ID: 9C85007ED905F14D

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

@ -39,30 +39,21 @@ export function initIpcMain(win, store) {
ipcMain.on('close', e => { ipcMain.on('close', e => {
if (process.platform == 'darwin') { if (process.platform == 'darwin') {
win.hide(); 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', () => { ipcMain.on('minimize', () => {
@ -156,4 +147,30 @@ export function initIpcMain(win, store) {
globalShortcut.unregisterAll(); globalShortcut.unregisterAll();
registerGlobalShortcut(win, store); 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);
});
};
} }

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

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

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

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

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

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

Loading…
Cancel
Save