Browse Source

Add taskbar controls for Windows (#32)

master
jeffvli 3 years ago
committed by Jeff
parent
commit
322ee6d1fe
  1. BIN
      assets/pause-circle.png
  2. BIN
      assets/play-circle.png
  3. BIN
      assets/skip-next.png
  4. BIN
      assets/skip-previous.png
  5. 139
      src/main.dev.js

BIN
assets/pause-circle.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 896 B

BIN
assets/play-circle.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 971 B

BIN
assets/skip-next.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 479 B

BIN
assets/skip-previous.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 524 B

139
src/main.dev.js

@ -28,6 +28,8 @@ import playQueueReducer, {
import multiSelectReducer from './redux/multiSelectSlice';
import MenuBuilder from './menu';
const isWindows = process.platform === 'win32';
export const store = configureStore({
reducer: {
player: playerReducer,
@ -101,95 +103,82 @@ const createWindow = async () => {
frame: false,
});
if (settings.getSync('globalMediaHotkeys')) {
globalShortcut.register('MediaStop', () => {
const storeValues = store.getState();
const currentEntryList = storeValues.playQueue.shuffle ? 'shuffledEntry' : 'entry';
const stop = () => {
const storeValues = store.getState();
const currentEntryList = storeValues.playQueue.shuffle ? 'shuffledEntry' : 'entry';
if (storeValues.playQueue[currentEntryList].length > 0) {
store.dispatch(clearPlayQueue());
if (storeValues.playQueue[currentEntryList].length > 0) {
store.dispatch(clearPlayQueue());
store.dispatch(setStatus('PAUSED'));
setTimeout(() => store.dispatch(resetPlayer()), 200);
}
};
const playPause = () => {
const storeValues = store.getState();
const currentEntryList = storeValues.playQueue.shuffle ? 'shuffledEntry' : 'entry';
if (storeValues.playQueue[currentEntryList].length > 0) {
if (storeValues.player.status === 'PAUSED') {
store.dispatch(setStatus('PLAYING'));
} else {
store.dispatch(setStatus('PAUSED'));
setTimeout(() => store.dispatch(resetPlayer()), 200);
}
}
};
const nextTrack = () => {
const storeValues = store.getState();
const currentEntryList = storeValues.playQueue.shuffle ? 'shuffledEntry' : 'entry';
if (storeValues.playQueue[currentEntryList].length > 0) {
store.dispatch(resetPlayer());
store.dispatch(incrementCurrentIndex('usingHotkey'));
store.dispatch(setStatus('PLAYING'));
}
};
const previousTrack = () => {
const storeValues = store.getState();
const currentEntryList = storeValues.playQueue.shuffle ? 'shuffledEntry' : 'entry';
if (storeValues.playQueue[currentEntryList].length > 0) {
store.dispatch(resetPlayer());
store.dispatch(decrementCurrentIndex('usingHotkey'));
store.dispatch(fixPlayer2Index());
store.dispatch(setStatus('PLAYING'));
}
};
if (settings.getSync('globalMediaHotkeys')) {
globalShortcut.register('MediaStop', () => {
stop();
});
globalShortcut.register('MediaPlayPause', () => {
const storeValues = store.getState();
const currentEntryList = storeValues.playQueue.shuffle ? 'shuffledEntry' : 'entry';
if (storeValues.playQueue[currentEntryList].length > 0) {
if (storeValues.player.status === 'PAUSED') {
store.dispatch(setStatus('PLAYING'));
} else {
store.dispatch(setStatus('PAUSED'));
}
}
playPause();
});
globalShortcut.register('MediaNextTrack', () => {
const storeValues = store.getState();
const currentEntryList = storeValues.playQueue.shuffle ? 'shuffledEntry' : 'entry';
if (storeValues.playQueue[currentEntryList].length > 0) {
store.dispatch(resetPlayer());
store.dispatch(incrementCurrentIndex('usingHotkey'));
store.dispatch(setStatus('PLAYING'));
}
nextTrack();
});
globalShortcut.register('MediaPreviousTrack', () => {
const storeValues = store.getState();
const currentEntryList = storeValues.playQueue.shuffle ? 'shuffledEntry' : 'entry';
if (storeValues.playQueue[currentEntryList].length > 0) {
store.dispatch(resetPlayer());
store.dispatch(decrementCurrentIndex('usingHotkey'));
store.dispatch(fixPlayer2Index());
store.dispatch(setStatus('PLAYING'));
}
previousTrack();
});
} else {
electronLocalshortcut.register(mainWindow, 'MediaStop', () => {
const storeValues = store.getState();
const currentEntryList = storeValues.playQueue.shuffle ? 'shuffledEntry' : 'entry';
if (storeValues.playQueue[currentEntryList].length > 0) {
store.dispatch(clearPlayQueue());
store.dispatch(setStatus('PAUSED'));
setTimeout(() => store.dispatch(resetPlayer()), 200);
}
stop();
});
electronLocalshortcut.register(mainWindow, 'MediaPlayPause', () => {
const storeValues = store.getState();
const currentEntryList = storeValues.playQueue.shuffle ? 'shuffledEntry' : 'entry';
if (storeValues.playQueue[currentEntryList].length > 0) {
if (storeValues.player.status === 'PAUSED') {
store.dispatch(setStatus('PLAYING'));
} else {
store.dispatch(setStatus('PAUSED'));
}
}
playPause();
});
electronLocalshortcut.register(mainWindow, 'MediaNextTrack', () => {
const storeValues = store.getState();
const currentEntryList = storeValues.playQueue.shuffle ? 'shuffledEntry' : 'entry';
if (storeValues.playQueue[currentEntryList].length > 0) {
store.dispatch(resetPlayer());
store.dispatch(incrementCurrentIndex('usingHotkey'));
store.dispatch(setStatus('PLAYING'));
}
nextTrack();
});
electronLocalshortcut.register(mainWindow, 'MediaPreviousTrack', () => {
const storeValues = store.getState();
const currentEntryList = storeValues.playQueue.shuffle ? 'shuffledEntry' : 'entry';
if (storeValues.playQueue[currentEntryList].length > 0) {
store.dispatch(resetPlayer());
store.dispatch(decrementCurrentIndex('usingHotkey'));
store.dispatch(fixPlayer2Index());
store.dispatch(setStatus('PLAYING'));
}
previousTrack();
});
}
@ -206,6 +195,26 @@ const createWindow = async () => {
} else {
mainWindow.show();
mainWindow.focus();
if (isWindows) {
mainWindow.setThumbarButtons([
{
tooltip: 'Previous Track',
icon: getAssetPath('skip-previous.png'),
click: () => previousTrack(),
},
{
tooltip: 'Play/Pause',
icon: getAssetPath('play-circle.png'),
click: () => playPause(),
},
{
tooltip: 'Next Track',
icon: getAssetPath('skip-next.png'),
click: () => nextTrack(),
},
]);
}
}
});

Loading…
Cancel
Save