Browse Source

Improve tray functionality (#225)

- Add playback buttons
- Move configs to redux state
master
jeffvli 3 years ago
parent
commit
880e6ae6e1
  1. 4
      src/__tests__/App.test.tsx
  2. 21
      src/components/settings/ConfigPanels/WindowConfig.tsx
  3. 36
      src/main.dev.js
  4. 13
      src/redux/configSlice.ts

4
src/__tests__/App.test.tsx

@ -409,6 +409,10 @@ const configState: ConfigPage = {
type: 'local', type: 'local',
}, },
}, },
window: {
minimizeToTray: false,
exitToTray: false,
},
}; };
const favoriteState: FavoritePage = { const favoriteState: FavoritePage = {

21
src/components/settings/ConfigPanels/WindowConfig.tsx

@ -1,14 +1,17 @@
import React, { useState } from 'react'; import React from 'react';
import settings from 'electron-settings'; import settings from 'electron-settings';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { ConfigOptionDescription, ConfigPanel } from '../styled'; import { ConfigOptionDescription, ConfigPanel } from '../styled';
import { StyledToggle } from '../../shared/styled'; import { StyledToggle } from '../../shared/styled';
import ConfigOption from '../ConfigOption'; import ConfigOption from '../ConfigOption';
import { setWindow } from '../../../redux/configSlice';
import { useAppDispatch, useAppSelector } from '../../../redux/hooks';
const WindowConfig = ({ bordered }: any) => { const WindowConfig = ({ bordered }: any) => {
const { t } = useTranslation(); const { t } = useTranslation();
const [minimizeToTray, setMinimizeToTray] = useState(Boolean(settings.getSync('minimizeToTray'))); const dispatch = useAppDispatch();
const [exitToTray, setExitToTray] = useState(Boolean(settings.getSync('exitToTray'))); const config = useAppSelector((state) => state.config);
return ( return (
<ConfigPanel bordered={bordered} header={t('Window')}> <ConfigPanel bordered={bordered} header={t('Window')}>
<ConfigOptionDescription> <ConfigOptionDescription>
@ -22,11 +25,11 @@ const WindowConfig = ({ bordered }: any) => {
description={t('Minimizes to the system tray.')} description={t('Minimizes to the system tray.')}
option={ option={
<StyledToggle <StyledToggle
defaultChecked={minimizeToTray} defaultChecked={config.window.minimizeToTray}
checked={minimizeToTray} checked={config.window.minimizeToTray}
onChange={(e: boolean) => { onChange={(e: boolean) => {
settings.setSync('minimizeToTray', e); settings.setSync('minimizeToTray', e);
setMinimizeToTray(e); dispatch(setWindow({ minimizeToTray: e }));
}} }}
/> />
} }
@ -37,11 +40,11 @@ const WindowConfig = ({ bordered }: any) => {
description={t('Exits to the system tray.')} description={t('Exits to the system tray.')}
option={ option={
<StyledToggle <StyledToggle
defaultChecked={exitToTray} defaultChecked={config.window.exitToTray}
checked={exitToTray} checked={config.window.exitToTray}
onChange={(e: boolean) => { onChange={(e: boolean) => {
settings.setSync('exitToTray', e); settings.setSync('exitToTray', e);
setExitToTray(e); dispatch(setWindow({ exitToTray: e }));
}} }}
/> />
} }

36
src/main.dev.js

@ -22,6 +22,7 @@ import { forwardToRenderer, triggerAlias, replayActionMain } from 'electron-redu
import playerReducer from './redux/playerSlice'; import playerReducer from './redux/playerSlice';
import playQueueReducer, { toggleShuffle, toggleRepeat, setVolume } from './redux/playQueueSlice'; import playQueueReducer, { toggleShuffle, toggleRepeat, setVolume } from './redux/playQueueSlice';
import multiSelectReducer from './redux/multiSelectSlice'; import multiSelectReducer from './redux/multiSelectSlice';
import configReducer from './redux/configSlice';
import MenuBuilder from './menu'; import MenuBuilder from './menu';
import { isWindows, isWindows10, isMacOS, isLinux } from './shared/utils'; import { isWindows, isWindows10, isMacOS, isLinux } from './shared/utils';
import setDefaultSettings from './components/shared/setDefaultSettings'; import setDefaultSettings from './components/shared/setDefaultSettings';
@ -38,6 +39,7 @@ export const store = configureStore({
player: playerReducer, player: playerReducer,
playQueue: playQueueReducer, playQueue: playQueueReducer,
multiSelect: multiSelectReducer, multiSelect: multiSelectReducer,
config: configReducer,
}, },
middleware: [triggerAlias, forwardToRenderer], middleware: [triggerAlias, forwardToRenderer],
}); });
@ -535,7 +537,7 @@ const createWindow = async () => {
}); });
mainWindow.on('minimize', (event) => { mainWindow.on('minimize', (event) => {
if (settings.getSync('minimizeToTray')) { if (store.getState().config.window.minimizeToTray) {
event.preventDefault(); event.preventDefault();
mainWindow.hide(); mainWindow.hide();
} }
@ -557,7 +559,7 @@ const createWindow = async () => {
}); });
mainWindow.on('close', (event) => { mainWindow.on('close', (event) => {
if (!exitFromTray && settings.getSync('exitToTray')) { if (!exitFromTray && store.getState().config.window.exitToTray) {
event.preventDefault(); event.preventDefault();
mainWindow.hide(); mainWindow.hide();
} }
@ -650,6 +652,33 @@ const createTray = () => {
tray = isLinux() ? new Tray(getAssetPath('icon.png')) : new Tray(getAssetPath('icon.ico')); tray = isLinux() ? new Tray(getAssetPath('icon.png')) : new Tray(getAssetPath('icon.ico'));
const contextMenu = Menu.buildFromTemplate([ const contextMenu = Menu.buildFromTemplate([
{
label: 'Play/Pause',
click: () => {
playPause();
},
},
{
label: 'Next Track',
click: () => {
nextTrack();
},
},
{
label: 'Previous Track',
click: () => {
previousTrack();
},
},
{
label: 'Stop',
click: () => {
stop();
},
},
{
type: 'separator',
},
{ {
label: 'Open main window', label: 'Open main window',
click: () => { click: () => {
@ -658,9 +687,6 @@ const createTray = () => {
createWinThumbnailClip(); createWinThumbnailClip();
}, },
}, },
{
type: 'separator',
},
{ {
label: 'Quit Sonixd', label: 'Quit Sonixd',
click: () => { click: () => {

13
src/redux/configSlice.ts

@ -58,6 +58,10 @@ export interface ConfigPage {
type: 'web' | 'local'; type: 'web' | 'local';
}; };
}; };
window: {
minimizeToTray: boolean;
exitToTray: boolean;
};
serverType: Server; serverType: Server;
} }
@ -197,6 +201,10 @@ const initialState: ConfigPage = {
type: parsedSettings.obs.type || 'local', type: parsedSettings.obs.type || 'local',
}, },
}, },
window: {
minimizeToTray: Boolean(parsedSettings.minimizeToTray),
exitToTray: Boolean(parsedSettings.exitToTray),
},
serverType: parsedSettings.serverType, serverType: parsedSettings.serverType,
}; };
@ -215,6 +223,10 @@ const configSlice = createSlice({
}; };
}, },
setWindow: (state, action: PayloadAction<any>) => {
state.window = { ...state.window, ...action.payload };
},
setPageSort: ( setPageSort: (
state, state,
action: PayloadAction<{ action: PayloadAction<{
@ -341,5 +353,6 @@ export const {
setDiscord, setDiscord,
setOBS, setOBS,
setSidebar, setSidebar,
setWindow,
} = configSlice.actions; } = configSlice.actions;
export default configSlice.reducer; export default configSlice.reducer;

Loading…
Cancel
Save