Skip to content

TagSpaces is an offline, open source, document manager with tagging support

feature: implementing new theme support

Ilian Sapundshiev75fe47be9c9c
diff --git a/app/components/dialogs/settings/SettingsGeneral.tsx b/app/components/dialogs/settings/SettingsGeneral.tsx
index 6571be91b..2ee1ebd21 100644
--- a/app/components/dialogs/settings/SettingsGeneral.tsx
+++ b/app/components/dialogs/settings/SettingsGeneral.tsx
@@ -73,7 +73,7 @@ interface Props {
persistTagsInSidecarFile: boolean;
toggleShowUnixHiddenEntries: () => void;
setCurrentTheme: (theme: string) => void;
- setCurrentLightTheme: (theme: string) => void;
+ setCurrentRegularTheme: (theme: string) => void;
setCurrentDarkTheme: (theme: string) => void;
setLanguage: (language: string) => void;
setCheckForUpdates: (check: boolean) => void;
@@ -162,22 +162,26 @@ function SettingsGeneral(props: Props) {
>
{props.settings.supportedThemes.map(theme => (
<MenuItem key={theme} value={theme}>
- {theme}
+ {theme === 'light' && i18n.t('core:regularScheme')}
+ {theme === 'dark' && i18n.t('core:darkScheme')}
+ {theme === 'system' && i18n.t('core:systemScheme')}
</MenuItem>
))}
</Select>
</ListItem>
<ListItem className={classes.listItem}>
- <ListItemText primary={i18n.t('core:themeLightSelector')} />
+ <ListItemText primary={i18n.t('core:themeRegularSelector')} />
<Select
- data-tid="settingsCurrentLightThemeTID"
- value={props.settings.currentLightTheme}
- onChange={(event: any) => props.setCurrentLightTheme(event.target.value)}
- input={<Input id="themeLightSelector" />}
+ data-tid="settingsCurrentRegularThemeTID"
+ value={props.settings.currentRegularTheme}
+ onChange={(event: any) =>
+ props.setCurrentRegularTheme(event.target.value)
+ }
+ input={<Input id="themeRegularSelector" />}
>
- {props.settings.supportedLightThemes.map(theme => (
+ {props.settings.supportedRegularThemes.map(theme => (
<MenuItem key={theme} value={theme}>
- {theme}
+ {theme.charAt(0).toUpperCase() + theme.slice(1)}
</MenuItem>
))}
</Select>
@@ -187,12 +191,14 @@ function SettingsGeneral(props: Props) {
<Select
data-tid="settingsCurrentDarkThemeTID"
value={props.settings.currentDarkTheme}
- onChange={(event: any) => props.setCurrentDarkTheme(event.target.value)}
+ onChange={(event: any) =>
+ props.setCurrentDarkTheme(event.target.value)
+ }
input={<Input id="themeDarkSelector" />}
>
{props.settings.supportedDarkThemes.map(theme => (
<MenuItem key={theme} value={theme}>
- {theme}
+ {theme.charAt(0).toUpperCase() + theme.slice(1)}
</MenuItem>
))}
</Select>
diff --git a/app/containers/App.tsx b/app/containers/App.tsx
index 1437223b1..6e874f076 100644
--- a/app/containers/App.tsx
+++ b/app/containers/App.tsx
@@ -23,55 +23,103 @@ import {
createTheme,
ThemeProvider,
Theme,
- StyledEngineProvider,
- adaptV4Theme
+ StyledEngineProvider
} from '@mui/material/styles';
+import useMediaQuery from '@mui/material/useMediaQuery';
import AppConfig from '@tagspaces/tagspaces-platforms/AppConfig';
import i18n from '../services/i18n';
-import { getCurrentTheme } from '-/reducers/settings';
+import {
+ getCurrentTheme,
+ getDefaultRegularTheme,
+ getDefaultDarkTheme
+} from '-/reducers/settings';
declare module '@mui/styles/defaultTheme' {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface DefaultTheme extends Theme {}
}
-const lightTheme = createTheme(
- adaptV4Theme({
- palette: {
- mode: 'light', // Switching the dark mode on is a single property value change.
- primary: {
- light: AppConfig.lightThemeLightColor,
- main: AppConfig.lightThemeMainColor,
- dark: AppConfig.lightThemeMainColor,
- contrastText: '#ffffff'
- },
- secondary: {
- main: AppConfig.lightThemeMainColor
- },
- divider: '#ddd'
- // secondary: { main: '#cccccc', 200: '#ddd' }
- }
- })
-);
+const legacyTheme = createTheme({
+ palette: {
+ mode: 'light', // Switching the dark mode on is a single property value change.
+ primary: {
+ light: AppConfig.lightThemeLightColor,
+ main: AppConfig.lightThemeMainColor,
+ dark: AppConfig.lightThemeMainColor
+ },
+ secondary: {
+ main: AppConfig.lightThemeMainColor
+ },
+ divider: '#ddd'
+ }
+});
+
+const newlightTheme = createTheme({
+ palette: {
+ mode: 'light',
+ primary: {
+ light: '#a6def4',
+ main: '#3bc8ff',
+ dark: '#3bc8ff'
+ },
+ secondary: {
+ main: '#3bc8ff'
+ },
+ divider: '#ddd'
+ }
+});
+
+// https://mui.com/material-ui/customization/dark-mode/
+const darklegacyTheme = createTheme({
+ palette: {
+ mode: 'dark',
+ primary: {
+ light: AppConfig.darkThemeLightColor,
+ main: AppConfig.darkThemeMainColor,
+ dark: AppConfig.darkThemeMainColor
+ },
+ secondary: {
+ main: AppConfig.darkThemeMainColor
+ },
+ divider: '#555'
+ }
+});
+
+const darkblueTheme = createTheme({
+ palette: {
+ mode: 'dark',
+ primary: {
+ light: '#a6def4',
+ main: '#3bc8ff',
+ dark: '#3bc8ff'
+ },
+ secondary: {
+ main: '#3bc8ff'
+ },
+ divider: '#555'
+ }
+});
-const darkTheme = createTheme(
- adaptV4Theme({
- palette: {
- mode: 'dark',
- primary: {
- light: AppConfig.darkThemeLightColor,
- main: AppConfig.darkThemeMainColor,
- dark: AppConfig.darkThemeMainColor,
- contrastText: '#ffffff'
- },
- secondary: {
- main: AppConfig.darkThemeMainColor
- },
- divider: '#555'
- // secondary: { main: '#555', 200: '#777' }
+const draculaTheme = createTheme({
+ palette: {
+ mode: 'dark',
+ primary: {
+ light: '#503d50',
+ main: '#BD93F9',
+ dark: '#BD93F9'
+ },
+ secondary: {
+ main: '#BD93F9'
+ },
+ divider: '#555',
+ background: {
+ default: '#282A36'
+ },
+ text: {
+ primary: '#f8f8f2'
}
- })
-);
+ }
+});
// const lightBlueTheme = createMuiTheme({
// palette: {
@@ -93,14 +141,42 @@ const darkTheme = createTheme(
interface Props {
children: Object;
currentTheme: string;
+ defaultRegularTheme: string;
+ defaultDarkTheme: string;
}
function App(props: Props) {
- let theme;
- const systemDarkMode = window.matchMedia('(prefers-color-scheme: dark)')
- .matches;
- switch (props.currentTheme) {
+ let theme = legacyTheme;
+ let regularTheme = legacyTheme;
+ let darkTheme = darklegacyTheme;
+ const { currentTheme, defaultRegularTheme, defaultDarkTheme } = props;
+ const systemDarkMode = useMediaQuery('(prefers-color-scheme: dark)'); // window.matchMedia().matches;
+ switch (defaultRegularTheme) {
+ case 'legacy': {
+ regularTheme = legacyTheme;
+ break;
+ }
+ case 'newlight': {
+ regularTheme = newlightTheme;
+ break;
+ }
+ }
+ switch (defaultDarkTheme) {
+ case 'darklegacy': {
+ darkTheme = darklegacyTheme;
+ break;
+ }
+ case 'darkblue': {
+ darkTheme = darkblueTheme;
+ break;
+ }
+ case 'dracula': {
+ darkTheme = draculaTheme;
+ break;
+ }
+ }
+ switch (currentTheme) {
case 'light': {
- theme = lightTheme;
+ theme = regularTheme;
break;
}
case 'dark': {
@@ -108,11 +184,7 @@ function App(props: Props) {
break;
}
case 'system': {
- theme = systemDarkMode ? darkTheme : lightTheme;
- break;
- }
- default: {
- theme = lightTheme;
+ theme = systemDarkMode ? darkTheme : regularTheme;
break;
}
}
@@ -128,7 +200,9 @@ function App(props: Props) {
function mapStateToProps(state) {
return {
- currentTheme: getCurrentTheme(state)
+ currentTheme: getCurrentTheme(state),
+ defaultDarkTheme: getDefaultDarkTheme(state),
+ defaultRegularTheme: getDefaultRegularTheme(state)
};
}
export default connect(mapStateToProps)(App);
diff --git a/app/locales/en/core.json b/app/locales/en/core.json
index c32441851..1ab196fc1 100644
--- a/app/locales/en/core.json
+++ b/app/locales/en/core.json
@@ -295,7 +295,12 @@
"locationManager": "Location Manager",
"chooseLocation": "Open Location",
"colorPickerDialogTitle": "Choose color",
- "themeSelector": "Theme selector",
+ "themeSelector": "Color scheme",
+ "themeRegularSelector": "Preferred regular theme",
+ "themeDarkSelector": "Preferred dark theme",
+ "darkScheme": "dark",
+ "regularScheme": "regular",
+ "systemScheme": "match OS",
"moveUp": "Move Up",
"moveDown": "Move Down",
"chooseSearchQuery": "Choose a search query",
diff --git a/app/perspectives/common/main-container.tsx b/app/perspectives/common/main-container.tsx
index 955e345ea..0f98f12ca 100644
--- a/app/perspectives/common/main-container.tsx
+++ b/app/perspectives/common/main-container.tsx
@@ -36,7 +36,10 @@ export const renderCell = (
fsEntry: TS.FileSystemEntry,
selectedEntries: Array<TS.FileSystemEntry>,
index: number,
- handleGridContextMenu: (event: React.MouseEvent<HTMLDivElement>, fsEntry: TS.FileSystemEntry) => void,
+ handleGridContextMenu: (
+ event: React.MouseEvent<HTMLDivElement>,
+ fsEntry: TS.FileSystemEntry
+ ) => void,
handleGridCellClick,
handleGridCellDblClick,
isLast?: boolean
diff --git a/app/reducers/settings-default.ts b/app/reducers/settings-default.ts
index 0c6ad5794..edb156af2 100644
--- a/app/reducers/settings-default.ts
+++ b/app/reducers/settings-default.ts
@@ -169,8 +169,8 @@ export default {
tagTextColor: 'white',
tagBackgroundColor: '#61DD61',
currentTheme: 'light',
- currentLightTheme: 'solarized',
- currentDarkTheme: 'dracula',
+ currentLightTheme: 'legacy',
+ currentDarkTheme: 'darklegacy',
geoTaggingFormat: 'pluscodes',
defaultPerspective: PerspectiveIDs.GRID,
enableGlobalKeyboardShortcuts: true,
@@ -180,8 +180,8 @@ export default {
mainVSplitSize: '50%',
supportedGeoTagging: ['pluscodes', 'mgrs'],
supportedThemes: ['light', 'dark', 'system'],
- supportedLightThemes: ['light1', 'solarized'],
- supportedDarkThemes: ['dark1', 'dracula'],
+ supportedRegularThemes: ['legacy', 'newlight'],
+ supportedDarkThemes: ['darklegacy', 'darkblue', 'dracula'],
tsLastOpenedFilesHistory: 10,
tsLastOpenedFoldersHistory: 10,
tsLastEditedFilesHistory: 10,
diff --git a/app/reducers/settings.ts b/app/reducers/settings.ts
index edd4ef145..a46b46558 100644
--- a/app/reducers/settings.ts
+++ b/app/reducers/settings.ts
@@ -61,7 +61,7 @@ export const types = {
SET_TAGCOLOR: 'SETTINGS/SET_TAGCOLOR',
SET_TAGTEXTCOLOR: 'SETTINGS/SET_TAGTEXTCOLOR',
SET_CURRENTTHEME: 'SETTINGS/SET_CURRENTTHEME',
- SET_CURRENT_LIGHT_THEME: 'SETTINGS/SET_CURRENT_LIGHT_THEME',
+ SET_CURRENT_REGULAR_THEME: 'SETTINGS/SET_CURRENT_REGULAR_THEME',
SET_CURRENT_DARK_THEME: 'SETTINGS/SET_CURRENT_DARK_THEME',
SET_GEO_TAGGING_FORMAT: 'SETTINGS/SET_GEO_TAGGING_FORMAT',
SET_HISTORY: 'SETTINGS/SET_HISTORY',
@@ -130,11 +130,12 @@ export default (state: any = defaultSettings, action: any) => {
...defaultSettings,
...state,
currentTheme: window.ExtTheme || state.currentTheme,
- currentLightTheme: window.ExtLightTheme || state.currentLightTheme,
+ currentRegularTheme:
+ window.ExtRegularTheme || state.currentRegularTheme,
currentDarkTheme: window.ExtDarkTheme || state.currentDarkTheme,
// TODO dynamically add supportedThemes functionality
supportedThemes: defaultSettings.supportedThemes, // taking always the themes from default settings
- supportedLightThemes: defaultSettings.supportedLightThemes, // taking always the themes from default settings
+ supportedRegularThemes: defaultSettings.supportedRegularThemes, // taking always the themes from default settings
supportedDarkThemes: defaultSettings.supportedDarkThemes, // taking always the themes from default settings
supportedLanguages: defaultSettings.supportedLanguages, // taking always the languages from default settings
keyBindings: [
@@ -253,8 +254,8 @@ export default (state: any = defaultSettings, action: any) => {
case types.SET_CURRENTTHEME: {
return { ...state, currentTheme: action.currentTheme };
}
- case types.SET_CURRENT_LIGHT_THEME: {
- return { ...state, currentLightTheme: action.currentLightTheme };
+ case types.SET_CURRENT_REGULAR_THEME: {
+ return { ...state, currentRegularTheme: action.currentRegularTheme };
}
case types.SET_CURRENT_DARK_THEME: {
return { ...state, currentDarkTheme: action.currentDarkTheme };
@@ -599,9 +600,9 @@ export const actions = {
type: types.SET_CURRENTTHEME,
currentTheme
}),
- setCurrentLightTheme: (currentLightTheme: string) => ({
- type: types.SET_CURRENT_LIGHT_THEME,
- currentLightTheme
+ setCurrentRegularTheme: (currentRegularTheme: string) => ({
+ type: types.SET_CURRENT_REGULAR_THEME,
+ currentRegularTheme
}),
setCurrentDarkTheme: (currentDarkTheme: string) => ({
type: types.SET_CURRENT_DARK_THEME,
@@ -799,6 +800,10 @@ export const getSupportedFileTypes = (state: any) =>
export const getTagColor = (state: any) => state.settings.tagBackgroundColor;
export const getTagTextColor = (state: any) => state.settings.tagTextColor;
export const getCurrentTheme = (state: any) => state.settings.currentTheme;
+export const getDefaultRegularTheme = (state: any) =>
+ state.settings.currentRegularTheme;
+export const getDefaultDarkTheme = (state: any) =>
+ state.settings.currentDarkTheme;
export const isGlobalKeyBindingEnabled = (state: any) =>
state.settings.enableGlobalKeyboardShortcuts;
export const getMainVerticalSplitSize = (state: any) =>
diff --git a/app/tagspaces.d.ts b/app/tagspaces.d.ts
index 28ac3b8d2..897a3e217 100644
--- a/app/tagspaces.d.ts
+++ b/app/tagspaces.d.ts
@@ -38,7 +38,7 @@ declare interface Window {
ExtLocations?: Array<any>;
ExtSearches?: Array<any>;
ExtTheme?: string;
- ExtLightTheme?: string;
+ ExtRegularTheme?: string;
ExtDarkTheme?: string;
ExtIsFirstRun?: boolean;
ExtIsAmplify?: boolean;