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. 91
      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

91
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,8 +103,7 @@ const createWindow = async () => {
frame: false,
});
if (settings.getSync('globalMediaHotkeys')) {
globalShortcut.register('MediaStop', () => {
const stop = () => {
const storeValues = store.getState();
const currentEntryList = storeValues.playQueue.shuffle ? 'shuffledEntry' : 'entry';
@ -111,9 +112,9 @@ const createWindow = async () => {
store.dispatch(setStatus('PAUSED'));
setTimeout(() => store.dispatch(resetPlayer()), 200);
}
});
};
globalShortcut.register('MediaPlayPause', () => {
const playPause = () => {
const storeValues = store.getState();
const currentEntryList = storeValues.playQueue.shuffle ? 'shuffledEntry' : 'entry';
@ -124,9 +125,9 @@ const createWindow = async () => {
store.dispatch(setStatus('PAUSED'));
}
}
});
};
globalShortcut.register('MediaNextTrack', () => {
const nextTrack = () => {
const storeValues = store.getState();
const currentEntryList = storeValues.playQueue.shuffle ? 'shuffledEntry' : 'entry';
if (storeValues.playQueue[currentEntryList].length > 0) {
@ -134,9 +135,9 @@ const createWindow = async () => {
store.dispatch(incrementCurrentIndex('usingHotkey'));
store.dispatch(setStatus('PLAYING'));
}
});
};
globalShortcut.register('MediaPreviousTrack', () => {
const previousTrack = () => {
const storeValues = store.getState();
const currentEntryList = storeValues.playQueue.shuffle ? 'shuffledEntry' : 'entry';
if (storeValues.playQueue[currentEntryList].length > 0) {
@ -145,51 +146,39 @@ const createWindow = async () => {
store.dispatch(fixPlayer2Index());
store.dispatch(setStatus('PLAYING'));
}
};
if (settings.getSync('globalMediaHotkeys')) {
globalShortcut.register('MediaStop', () => {
stop();
});
} 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);
}
globalShortcut.register('MediaPlayPause', () => {
playPause();
});
electronLocalshortcut.register(mainWindow, 'MediaPlayPause', () => {
const storeValues = store.getState();
const currentEntryList = storeValues.playQueue.shuffle ? 'shuffledEntry' : 'entry';
globalShortcut.register('MediaNextTrack', () => {
nextTrack();
});
if (storeValues.playQueue[currentEntryList].length > 0) {
if (storeValues.player.status === 'PAUSED') {
store.dispatch(setStatus('PLAYING'));
globalShortcut.register('MediaPreviousTrack', () => {
previousTrack();
});
} else {
store.dispatch(setStatus('PAUSED'));
}
}
electronLocalshortcut.register(mainWindow, 'MediaStop', () => {
stop();
});
electronLocalshortcut.register(mainWindow, 'MediaPlayPause', () => {
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