Browse Source

Added audio device switching to the tray icon context menu (because that kind of thing is damm cool)

reviewable/pr190/r10
Samuel Attard 6 years ago
parent
commit
b51e20e6c7
  1. 1
      src/inject/rendererEmitter.js
  2. 18
      src/inject/settings/audioSelection.js
  3. 64
      src/main/features/core/tray.js

1
src/inject/rendererEmitter.js

@ -62,6 +62,7 @@ class Emitter {
event,
details,
});
ipcRenderer.send(event, details);
} else {
this.q.push(this.fireAtAll.bind(this, event, details));
}

18
src/inject/settings/audioSelection.js

@ -7,10 +7,24 @@ Emitter.on('audiooutput:list', (event, d) => {
$('#audioOutputSelect option').remove();
devices.forEach((device) => {
if (device.kind === 'audiooutput') {
let label = device.label;
if (!label) {
switch (device.deviceId) {
case 'default':
label = 'System Default';
break;
case 'communications':
label = 'System Default Communications';
break;
default:
label = 'Unknown Device';
break;
}
}
const opt = $('<option></option>');
opt.attr('value', device.deviceId);
opt.text(device.label === '' ? 'Default Device' : device.label);
if (device.label === Settings.get('audiooutput')) {
opt.text(label);
if (label === Settings.get('audiooutput')) {
opt.attr('selected', true);
}
$('#audioOutputSelect').append(opt);

64
src/main/features/core/tray.js

@ -6,15 +6,31 @@ import { showDesktopSettings } from './desktopSettings';
let appIcon = null;
const mainWindow = WindowManager.getAll('main')[0];
let audioDeviceMenu = [
{
label: 'Loading Devices...',
enabled: false,
},
];
appIcon = new Tray(path.resolve(`${__dirname}/../../../assets/img/main_tray.png`));
const contextMenu = Menu.buildFromTemplate([
{ label: 'Show', click: () => { mainWindow.setSkipTaskbar(false); mainWindow.show(); } },
{ label: 'Settings', click: () => { showDesktopSettings(); } },
{ type: 'separator' },
{ label: 'Quit', click: () => { global.quiting = true; app.quit(); } },
]);
const setContextMenu = () => {
const contextMenu = Menu.buildFromTemplate([
{ label: 'Show', click: () => { mainWindow.setSkipTaskbar(false); mainWindow.show(); } },
{
label: 'Audio Device',
submenu: audioDeviceMenu,
},
{ label: 'Settings', click: () => { showDesktopSettings(); } },
{ type: 'separator' },
{ label: 'Quit', click: () => { global.quiting = true; app.quit(); } },
]);
appIcon.setContextMenu(contextMenu);
};
setContextMenu();
appIcon.setToolTip('Google Play Music');
appIcon.setContextMenu(contextMenu);
appIcon.on('double-click', () => {
mainWindow.setSkipTaskbar(false);
mainWindow.show();
@ -28,3 +44,37 @@ app.on('before-quit', () => {
delete global.appIcon;
appIcon = null;
});
Emitter.on('audiooutput:list', (event, devices) => {
audioDeviceMenu = [];
devices.forEach((device) => {
if (device.kind === 'audiooutput') {
let label = device.label;
if (!label) {
switch (device.deviceId) {
case 'default':
label = 'System Default';
break;
case 'communications':
label = 'System Default Communications';
break;
default:
label = 'Unknown Device';
break;
}
}
audioDeviceMenu.push({
label,
type: 'radio',
click: () => {
Emitter.sendToGooglePlayMusic('audiooutput:set', device.deviceId);
Settings.set('audiooutput', label);
},
checked: (label === Settings.get('audiooutput')),
});
}
});
setContextMenu();
});
Emitter.sendToGooglePlayMusic('audiooutput:fetch');

Loading…
Cancel
Save