Skip to content

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

feat: introducing support for system dark mode

Ilian Sapundshiev1875192b9677
diff --git a/app/containers/App.tsx b/app/containers/App.tsx
index 59f8ecde8..1437223b1 100644
--- a/app/containers/App.tsx
+++ b/app/containers/App.tsx
@@ -96,6 +96,8 @@ interface Props {
}
function App(props: Props) {
let theme;
+ const systemDarkMode = window.matchMedia('(prefers-color-scheme: dark)')
+ .matches;
switch (props.currentTheme) {
case 'light': {
theme = lightTheme;
@@ -105,6 +107,10 @@ function App(props: Props) {
theme = darkTheme;
break;
}
+ case 'system': {
+ theme = systemDarkMode ? darkTheme : lightTheme;
+ break;
+ }
default: {
theme = lightTheme;
break;
diff --git a/app/reducers/io-actions.ts b/app/reducers/io-actions.ts
index 07c1cf2b5..10adefde7 100644
--- a/app/reducers/io-actions.ts
+++ b/app/reducers/io-actions.ts
@@ -354,63 +354,65 @@ const actions = {
// for AWS location getFileContentPromise cannot load with io-objectore
return import('fs-extra').then(fs => {
try {
- const fileContent = fs.readFileSync(job[0]);
- return PlatformIO.getPropertiesPromise(filePath)
- .then(entryProps => {
- if (entryProps) {
- dispatch(
- AppActions.showNotification(
- 'File with the same name already exist, importing skipped!',
- 'warning',
- true
+ const fileContent = fs.readFileSync(job[0]);
+ return PlatformIO.getPropertiesPromise(filePath)
+ .then(entryProps => {
+ if (entryProps) {
+ dispatch(
+ AppActions.showNotification(
+ 'File with the same name already exist, importing skipped!',
+ 'warning',
+ true
+ )
+ );
+ dispatch(AppActions.setProgress(filePath, -1, undefined));
+ } else {
+ // dispatch(AppActions.setProgress(filePath, progress));
+ return PlatformIO.saveBinaryFilePromise(
+ filePath,
+ fileContent,
+ true,
+ onUploadProgress
)
- );
- dispatch(AppActions.setProgress(filePath, -1, undefined));
- } else {
- // dispatch(AppActions.setProgress(filePath, progress));
- return PlatformIO.saveBinaryFilePromise(
- filePath,
- fileContent,
- true,
- onUploadProgress
- )
- .then((fsEntry: TS.FileSystemEntry) => {
- // handle meta files
- if (fileType === 'meta') {
- try {
+ .then((fsEntry: TS.FileSystemEntry) => {
+ // handle meta files
+ if (fileType === 'meta') {
+ try {
+ // eslint-disable-next-line no-param-reassign
+ fsEntry.meta = loadJSONString(
+ fileContent.toString()
+ );
+ } catch (e) {
+ console.debug('cannot parse entry meta');
+ }
+ } else if (fileType === 'thumb') {
// eslint-disable-next-line no-param-reassign
- fsEntry.meta = loadJSONString(fileContent.toString());
- } catch (e) {
- console.debug('cannot parse entry meta');
+ fsEntry.thumbPath = fsEntry.path;
}
- } else if (fileType === 'thumb') {
- // eslint-disable-next-line no-param-reassign
- fsEntry.thumbPath = fsEntry.path;
- }
- return fsEntry;
- })
- .catch(err => {
- console.error(
- 'Importing file ' + filePath + ' failed ' + err
- );
- dispatch(
- AppActions.showNotification(
- 'Importing file ' + filePath + ' failed.',
- 'error',
- true
- )
- );
- return undefined;
- });
- }
- return undefined;
- })
- .catch(err => {
- console.log('Error getting properties ' + err);
- });
+ return fsEntry;
+ })
+ .catch(err => {
+ console.error(
+ 'Importing file ' + filePath + ' failed ' + err
+ );
+ dispatch(
+ AppActions.showNotification(
+ 'Importing file ' + filePath + ' failed.',
+ 'error',
+ true
+ )
+ );
+ return undefined;
+ });
+ }
+ return undefined;
+ })
+ .catch(err => {
+ console.log('Error getting properties ' + err);
+ });
} catch (ex) {
- console.warn("Error readFileSync for " + job[0], ex);
+ console.warn('Error readFileSync for ' + job[0], ex);
}
});
}
diff --git a/app/reducers/settings-default.ts b/app/reducers/settings-default.ts
index 156b6572e..220d1d001 100644
--- a/app/reducers/settings-default.ts
+++ b/app/reducers/settings-default.ts
@@ -177,7 +177,7 @@ export default {
entrySplitSize: '45%', // AppConfig.isElectron ? '560px' : '360px',
mainVSplitSize: '50%',
supportedGeoTagging: ['pluscodes', 'mgrs'],
- supportedThemes: ['light', 'dark'],
+ supportedThemes: ['light', 'dark', 'system'],
tsLastOpenedFilesHistory: 10,
tsLastOpenedFoldersHistory: 10,
tsLastEditedFilesHistory: 10,
diff --git a/app/reducers/settings.ts b/app/reducers/settings.ts
index e583d183e..9e7da90e4 100644
--- a/app/reducers/settings.ts
+++ b/app/reducers/settings.ts
@@ -254,7 +254,10 @@ export default (state: any = defaultSettings, action: any) => {
}
case types.SWITCH_THEME: {
let currentTheme = 'dark';
- if (state.currentTheme === 'dark') {
+ const systemDarkMode = window.matchMedia('(prefers-color-scheme: dark)');
+ if (state.currentTheme === 'system') {
+ currentTheme = systemDarkMode ? 'light' : 'dark';
+ } else if (state.currentTheme === 'dark') {
currentTheme = 'light';
}
return { ...state, currentTheme };
diff --git a/tests/e2e/file.properties.helpers.js b/tests/e2e/file.properties.helpers.js
index 8cccb94a9..af98d78b5 100644
--- a/tests/e2e/file.properties.helpers.js
+++ b/tests/e2e/file.properties.helpers.js
@@ -46,11 +46,7 @@ export async function AddRemovePropertiesTags(
const tagName = tagNames[i];
await removeTagFromTagMenu(tagName);
// await global.client.waitForLoadState('networkidle'); //'networkidle'); //'domcontentloaded'); // load
- await isDisplayed(
- '[data-tid=tagContainer_' + tagName + ']',
- false,
- 2000
- );
+ await isDisplayed('[data-tid=tagContainer_' + tagName + ']', false, 2000);
// await global.client.waitForTimeout(1500);
const propsNewTags = await getPropertiesTags();
// console.log(JSON.stringify(propsNewTags));
diff --git a/tests/e2e/general.helpers.js b/tests/e2e/general.helpers.js
index c6900fc4b..9bdfa2258 100644
--- a/tests/e2e/general.helpers.js
+++ b/tests/e2e/general.helpers.js
@@ -592,7 +592,7 @@ export async function extractTags(selectorElement) {
const tagsList = await tags.$$('div[role=presentation]');
for (let i = 0; i < tagsList.length; i++) {
const tid = await tagsList[i].getAttribute('data-tid');
- arrTags.push(tid.replace(/(^tagContainer_)/i, ""));
+ arrTags.push(tid.replace(/(^tagContainer_)/i, ''));
}
}
return arrTags;