Skip to content

Commit

Permalink
✨ Add miniplayer to custom keys
Browse files Browse the repository at this point in the history
  • Loading branch information
adlerluiz committed Aug 19, 2020
1 parent 71e800e commit f0bb826
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 42 deletions.
38 changes: 26 additions & 12 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,6 @@ function createWindow() {
})

mainWindow.on('show', function () {
//globalShortcut.unregister('CmdOrCtrl+M')

mediaControl.createThumbar(mainWindow, infoPlayerProvider.getAllInfo())
})

Expand Down Expand Up @@ -595,10 +593,6 @@ function createWindow() {
}
)

electronLocalshortcut.register(view, 'CmdOrCtrl+M', () => {
ipcMain.emit('window', { command: 'show-miniplayer' })
})

// GLOBAL
ipcMain.on('change-accelerator', (dataMain, dataRenderer) => {
if (dataMain.type != undefined) {
Expand Down Expand Up @@ -690,6 +684,27 @@ function createWindow() {
mediaControl.volumeDown(view)
})
break

case 'miniplayer-open-close':
registerGlobalShortcut(args.newValue, () => {
try {
if (miniplayer) {
miniplayer.close()
miniplayer = undefined
mainWindow.show()
} else {
ipcMain.emit('window', {
command: 'show-miniplayer',
})
}
} catch {
writeLog({
type: 'warn',
data: 'error on try open/close miniplayer',
})
}
})
break
}
})

Expand Down Expand Up @@ -731,6 +746,11 @@ function createWindow() {
newValue: settingsAccelerator['media-volume-down'],
})

ipcMain.emit('change-accelerator', {
type: 'miniplayer-open-close',
newValue: settingsAccelerator['miniplayer-open-close'],
})

globalShortcut.register('MediaPlayPause', function () {
checkDoubleTapPlayPause()
})
Expand Down Expand Up @@ -1132,12 +1152,6 @@ function createWindow() {
})

mainWindow.hide()

/*globalShortcut.register('CmdOrCtrl+M', function () {
miniplayer.close()
miniplayer = undefined
mainWindow.show()
})*/
}
}

Expand Down
9 changes: 3 additions & 6 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"LABEL_SETTINGS_TAB_APPEARENCE": "Appearance",
"LABEL_SETTINGS_TAB_GENERAL": "General",
"LABEL_SETTINGS_TAB_GENERAL_AUDIO_NO_DEVICES_FOUND": "No devices found",
"LABEL_SETTINGS_TAB_GENERAL_COMPANION_SERVER": "Remote Control",
"LABEL_SETTINGS_TAB_GENERAL_COMPANION_SERVER": "Companion Server",
"LABEL_SETTINGS_TAB_GENERAL_COMPANION_SERVER_INFO": "Click here and scan QR Code",
"LABEL_SETTINGS_TAB_GENERAL_COMPANION_SERVER_PROTECT": "Protect remote control with password",
"LABEL_SETTINGS_TAB_GENERAL_COMPANION_SERVER_PROTECT": "Protect companion with password",
"LABEL_SETTINGS_TAB_GENERAL_CONTINUE_WHERE_LEFT_OF": "Continue where you left off",
"LABEL_SETTINGS_TAB_GENERAL_CUSTOM_THEME": "Custom theme",
"LABEL_SETTINGS_TAB_GENERAL_DISABLE_HARDWARE_ACCELERATION": "Disable hardware acceleration",
Expand All @@ -52,10 +52,6 @@
"LABEL_SETTINGS_TAB_MINIPLAYER_ALWAYS_SHOW_CONTROLS": "Always show controls",
"LABEL_SETTINGS_TAB_MINIPLAYER_PAINT_CONTROLS": "Paint controls with album color",
"LABEL_SETTINGS_TAB_MINIPLAYER_RESIZABLE": "Allow resizing",
"LABEL_SETTINGS_TAB_MINIPLAYER_SELECT_SIZE": "Miniplayer size",
"LABEL_SETTINGS_TAB_MINIPLAYER_SELECT_SIZE_LARGE": "Large",
"LABEL_SETTINGS_TAB_MINIPLAYER_SELECT_SIZE_NORMAL": "Normal",
"LABEL_SETTINGS_TAB_MINIPLAYER_SELECT_SIZE_SMALL": "Small",
"LABEL_SETTINGS_TAB_MINIPLAYER_SHOW_TASK": "Show on taskbar",
"LABEL_SETTINGS_TAB_RAINMETER_WEB_NOW_PLAYING": "Rainmeter (WebNowPlaying)",
"LABEL_SETTINGS_TAB_READ_CLIPBOARD": "Read clipboard for youtube links",
Expand All @@ -76,6 +72,7 @@
"MEDIA_CONTROL_THUMBS_UP": "Thumbs Up",
"MEDIA_CONTROL_VOLUME_DOWN": "Decrease volume",
"MEDIA_CONTROL_VOLUME_UP": "Increase volume",
"MEDIA_CONTROL_MINIPLAYER": "Open/Close Miniplayer",
"LABEL_SETTINGS_TAB_INTEGRATION_WINDOWS10_MEDIA_SERVICE": "Enable Windows 10 media service",
"LABEL_SETTINGS_TAB_INTEGRATION_WINDOWS10_MEDIA_SERVICE_SHOW_INFO": "Show track information next to the Windows 10 volume bar",
"LABEL_NOTIFICATION_LIKED": "You liked this song",
Expand Down
1 change: 1 addition & 0 deletions src/locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"MEDIA_CONTROL_THUMBS_UP": "Gostei",
"MEDIA_CONTROL_VOLUME_DOWN": "Diminuir volume",
"MEDIA_CONTROL_VOLUME_UP": "Aumentar volume",
"MEDIA_CONTROL_MINIPLAYER": "Abrir/Fechar Miniplayer",
"LABEL_SETTINGS_TAB_INTEGRATION_WINDOWS10_MEDIA_SERVICE": "Habilitar serviço de mídia do Windows 10",
"LABEL_SETTINGS_TAB_INTEGRATION_WINDOWS10_MEDIA_SERVICE_SHOW_INFO": "Mostrar informação da faixa ao lado da barra de volume do Windows 10",
"LABEL_NOTIFICATION_LIKED": "Você gostou desta música",
Expand Down
1 change: 1 addition & 0 deletions src/locales/scaffold.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"MEDIA_CONTROL_THUMBS_UP": "Thumbs Up",
"MEDIA_CONTROL_VOLUME_DOWN": "Decrease volume",
"MEDIA_CONTROL_VOLUME_UP": "Increase volume",
"MEDIA_CONTROL_MINIPLAYER": "Open/Close Miniplayer",
"LABEL_SETTINGS_TAB_INTEGRATION_WINDOWS10_MEDIA_SERVICE": "Enable Windows 10 media service",
"LABEL_SETTINGS_TAB_INTEGRATION_WINDOWS10_MEDIA_SERVICE_SHOW_INFO": "Show track information next to the Windows 10 volume bar",
"LABEL_NOTIFICATION_LIKED": "You liked this song",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,6 @@ input[type=range]+.thumb {
padding: 0 7px;
}

.normalize {
.btn-normalize {
min-width: 70px;
}
42 changes: 29 additions & 13 deletions src/pages/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@
i18n="i18n_LABEL_ALSO"
></span>
<a
class="btn btn-small white black-text disable normalize"
class="btn btn-small white black-text disable btn-normalize"
>
<i
class="material-icons media-icons"
Expand Down Expand Up @@ -840,7 +840,7 @@
i18n="i18n_LABEL_ALSO"
></span>
<a
class="btn btn-small white black-text disable normalize"
class="btn btn-small white black-text disable btn-normalize"
>
<i
class="material-icons media-icons"
Expand Down Expand Up @@ -874,7 +874,7 @@
i18n="i18n_LABEL_ALSO"
></span>
<a
class="btn btn-small white black-text disable normalize"
class="btn btn-small white black-text disable btn-normalize"
>
<i
class="material-icons media-icons"
Expand Down Expand Up @@ -974,22 +974,38 @@
<tr>
<td>
<span
i18n="i18n_LABEL_SETTINGS_SHOW_HIDE_WINDOW"
i18n="i18n_MEDIA_CONTROL_MINIPLAYER"
></span>
</td>
<th>
<a
class="btn btn-small white black-text disable"
<button
id="btn-accelerator-miniplayer-open-close"
data-target="modalEditAccelerator"
class="modal-trigger waves-effect waves-light btn-small text-initial black-text white"
>
2x
<span
id="settings-accelerators_miniplayer-open-close"
></span>
<i
class="material-icons media-icons"
>play_arrow</i
>/<i
class="material-icons media-icons"
>pause</i
class="tiny material-icons left"
>edit</i
>
</a>
</button>
</th>
</tr>
<tr>
<td>
<span
i18n="i18n_LABEL_SETTINGS_SHOW_HIDE_WINDOW"
></span>
</td>
<th>
<span
i18n="i18n_MEDIA_CONTROL_PLAY_PAUSE"
></span>
<span class="shortcut-text"
>2x</span
>
<div
class="switch"
style="display: inline;"
Expand Down
12 changes: 12 additions & 0 deletions src/pages/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ function loadCustomKeys() {
).innerText = replaceAcceleratorText(
settingsAccelerators['media-volume-down']
)
document.querySelector(
'#settings-accelerators_miniplayer-open-close'
).innerText = replaceAcceleratorText(
settingsAccelerators['miniplayer-open-close']
)
}

function resetAcceleratorsText() {
Expand Down Expand Up @@ -517,6 +522,13 @@ document
resetAcceleratorsText()
})

document
.querySelector('#btn-accelerator-miniplayer-open-close')
.addEventListener('click', () => {
typeAcceleratorSelected = 'miniplayer-open-close'
resetAcceleratorsText()
})

document.querySelector('#saveAccelerator').addEventListener('click', () => {
ipc.send('change-accelerator', {
type: typeAcceleratorSelected,
Expand Down
18 changes: 8 additions & 10 deletions src/utils/defaultSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,14 @@ settingsProvider.setInitialValue('settings-accelerators', {

let accelerators = settingsProvider.get('settings-accelerators')
if (!accelerators['media-volume-up']) {
settingsProvider.set('settings-accelerators', {
'media-play-pause': 'CmdOrCtrl+Shift+Space',
'media-track-next': 'CmdOrCtrl+Shift+PageUp',
'media-track-previous': 'CmdOrCtrl+Shift+PageDown',
'media-track-like': 'CmdOrCtrl+Shift+L',
'media-track-dislike': 'CmdOrCtrl+Shift+D',
'media-volume-up': 'CmdOrCtrl+Shift+Up',
'media-volume-down': 'CmdOrCtrl+Shift+Down',
})
} else {
accelerators['media-volume-up'] = 'CmdOrCtrl+Shift+Up'
accelerators['media-volume-down'] = 'CmdOrCtrl+Shift+Down'
settingsProvider.set('settings-accelerators', accelerators)
}

if (!accelerators['miniplayer-open-close']) {
accelerators['miniplayer-open-close'] = 'CmdOrCtrl+Shift+M'
settingsProvider.set('settings-accelerators', accelerators)
}

settingsProvider.setInitialValue('has-updated', false)
Expand Down

0 comments on commit f0bb826

Please sign in to comment.