Skip to content

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

Add author in settings (#2374)

Stanimir93d4531c22d1
diff --git a/src/main/mainEvents.ts b/src/main/mainEvents.ts
index 08be1100f..2257f7cf2 100644
--- a/src/main/mainEvents.ts
+++ b/src/main/mainEvents.ts
@@ -43,7 +43,7 @@ import {
postRequest,
readMacOSTags,
} from './util';
-import { ApiResponse } from './types';
+import os from 'os';
//let watcher: FSWatcher;
const progress = {};
@@ -598,4 +598,12 @@ export default function loadMainEvents() {
};
}
});
+
+ ipcMain.on('getAuthor', (event) => {
+ try {
+ event.returnValue = os.userInfo().username ?? '';
+ } catch {
+ event.returnValue = process.env.USER ?? process.env.USERNAME ?? '';
+ }
+ });
}
diff --git a/src/main/preload.ts b/src/main/preload.ts
index 4b52ca03d..d474699b3 100644
--- a/src/main/preload.ts
+++ b/src/main/preload.ts
@@ -80,6 +80,7 @@ export type Channels =
| 'pullOllamaModel'
| 'deleteOllamaModel'
| 'startup-finished'
+ | 'getAuthor'
| 'cancelRequest';
const electronHandler = {
@@ -102,6 +103,9 @@ const electronHandler = {
invoke(command: Channels, ...args: unknown[]) {
return ipcRenderer.invoke(command, ...args);
},
+ getSync(command: Channels, ...args: unknown[]) {
+ return ipcRenderer.sendSync(command, ...args);
+ },
removeAllListeners(channel: string) {
ipcRenderer.removeAllListeners(channel);
},
diff --git a/src/renderer/AppConfig.ts b/src/renderer/AppConfig.ts
index 1e9932e6c..ab6d5de9f 100644
--- a/src/renderer/AppConfig.ts
+++ b/src/renderer/AppConfig.ts
@@ -196,7 +196,7 @@ AppConfig.defaultTemplate =
: {
id: 'default',
name: 'Default',
- content: '{createdInApp} ({date})',
+ content: '{createdInApp} ({date}) {author}',
fileNameTmpl: 'note[{timestamp}]',
};
diff --git a/src/renderer/components/dialogs/NewFileDialog.tsx b/src/renderer/components/dialogs/NewFileDialog.tsx
index bf90c5c4e..89481afc8 100644
--- a/src/renderer/components/dialogs/NewFileDialog.tsx
+++ b/src/renderer/components/dialogs/NewFileDialog.tsx
@@ -45,6 +45,8 @@ import { useContext, useEffect, useReducer, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import versionMeta from '-/version.json';
import useFirstRender from '-/utils/useFirstRender';
+import { useSelector } from 'react-redux';
+import { getAuthor } from '-/reducers/settings';
interface Props {
open: boolean;
@@ -63,6 +65,8 @@ function NewFileDialog(props: Props) {
const { targetDirectoryPath } = useTargetPathContext();
const haveError = useRef<boolean>(false);
const urlInputError = useRef<string>(undefined);
+
+ const author = useSelector(getAuthor);
const firstRWLocation = getFirstRWLocation();
const fileTemplatesContext = Pro?.contextProviders?.FileTemplatesContext
? useContext<TS.FileTemplatesContextData>(
@@ -128,6 +132,7 @@ function NewFileDialog(props: Props) {
`${t('core:createdIn')} ${versionMeta.name}`,
)
.replace('{date}', dateTimeArray[0])
+ .replace('{author}', author)
.replace('{time}', dateTimeArray[1].split('.')[0])
);
}
diff --git a/src/renderer/components/dialogs/components/SettingsAdvanced.tsx b/src/renderer/components/dialogs/components/SettingsAdvanced.tsx
index 7ab4e1b53..0d28485fc 100644
--- a/src/renderer/components/dialogs/components/SettingsAdvanced.tsx
+++ b/src/renderer/components/dialogs/components/SettingsAdvanced.tsx
@@ -17,7 +17,7 @@
*/
import AppConfig from '-/AppConfig';
-import { DeleteIcon } from '-/components/CommonIcons';
+import { DeleteIcon, ReloadIcon } from '-/components/CommonIcons';
import { ProLabel } from '-/components/HelperComponents';
import InfoIcon from '-/components/InfoIcon';
import TooltipTS from '-/components/Tooltip';
@@ -44,7 +44,7 @@ import { clearAllURLParams } from '-/utils/dom';
import CheckIcon from '@mui/icons-material/Check';
import EditIcon from '@mui/icons-material/Edit';
import FiberManualRecordIcon from '@mui/icons-material/FiberManualRecord';
-import { CircularProgress, ListItemIcon } from '@mui/material';
+import { CircularProgress, InputAdornment, ListItemIcon } from '@mui/material';
import List from '@mui/material/List';
import ListItem from '@mui/material/ListItem';
import ListItemText from '@mui/material/ListItemText';
@@ -133,6 +133,8 @@ function SettingsAdvanced(props: Props) {
const setPrefixTagContainer = (prefix) =>
dispatch(SettingsActions.setPrefixTagContainer(prefix));
+ const setAuthor = (user: string) => dispatch(SettingsActions.setAuthor(user));
+
return (
<List style={{ overflowX: 'hidden', overflowY: 'auto', height: '100%' }}>
<ListItem>
@@ -534,6 +536,46 @@ function SettingsAdvanced(props: Props) {
isDefault={tileServerDialog.isDefault}
/>
)}
+ <ListItem>
+ <ListItemText
+ primary={
+ <>
+ {t('core:author')}
+ <InfoIcon
+ tooltip={
+ 'The value of this text field can be used for example in the templates as {author} variable. If you do not want this, just delete it from here.'
+ }
+ />
+ </>
+ }
+ />
+ <TsTextField
+ disabled={window.ExtAuthor !== undefined}
+ title={window.ExtAuthor ? t('core:settingExternallyConfigured') : ''}
+ data-tid="authorTID"
+ value={window.ExtAuthor ? window.ExtAuthor : settings.author}
+ onChange={(event) => setAuthor(event.target.value)}
+ slotProps={{
+ input: {
+ endAdornment: (
+ <InputAdornment position="end">
+ <TooltipTS title={t('loadDefaultAuthor')}>
+ <TsIconButton
+ data-tid="loadDefaultAuthorTID"
+ disabled={window.ExtAuthor !== undefined}
+ onClick={() =>
+ dispatch(SettingsActions.setAuthor(undefined))
+ }
+ >
+ <ReloadIcon />
+ </TsIconButton>
+ </TooltipTS>
+ </InputAdornment>
+ ),
+ },
+ }}
+ />
+ </ListItem>
<ListItem>
<ListItemText
primary={
diff --git a/src/renderer/components/dialogs/components/SettingsTemplates.tsx b/src/renderer/components/dialogs/components/SettingsTemplates.tsx
index 6bc3755c3..269613135 100644
--- a/src/renderer/components/dialogs/components/SettingsTemplates.tsx
+++ b/src/renderer/components/dialogs/components/SettingsTemplates.tsx
@@ -164,6 +164,10 @@ function SettingsTemplates(props: Props) {
,{' '}
<b>
{'{'}time{'}'}
+ </b>
+ ,{' '}
+ <b>
+ {'{'}author{'}'}
</b>{' '}
and{' '}
<b>
diff --git a/src/renderer/locales/en/core.json b/src/renderer/locales/en/core.json
index 990970ecd..55226f9ad 100644
--- a/src/renderer/locales/en/core.json
+++ b/src/renderer/locales/en/core.json
@@ -998,5 +998,6 @@
"fileNameTmpl": "File Name Template",
"templateNameEmptyError": "Template name can't be empty",
"fileNameEmptyError": "Filename template can't be empty",
+ "loadDefaultAuthor": "Load username from OS",
"-": "-"
}
diff --git a/src/renderer/reducers/settings-default.ts b/src/renderer/reducers/settings-default.ts
index 9c07e16a0..fd75c91b7 100644
--- a/src/renderer/reducers/settings-default.ts
+++ b/src/renderer/reducers/settings-default.ts
@@ -41,6 +41,17 @@ if (window.ExtUseOnlyTagsFromTagLibrary !== undefined) {
useOnlyTagsFromTagLibrary = window.ExtUseOnlyTagsFromTagLibrary;
}
+let author = '';
+if (window.ExtAuthor !== undefined) {
+ author = window.ExtAuthor;
+} else if (AppConfig.isElectron) {
+ try {
+ author = window.electronIO.ipcRenderer.getSync('getAuthor');
+ } catch (err) {
+ console.error('Error retrieving author:', err);
+ }
+}
+
export default {
//isLoading: false,
error: null,
@@ -119,6 +130,7 @@ export default {
? true
: window.ExtRevisionsEnabled,
prefixTagContainer: AppConfig.prefixTagContainer,
+ author: author,
aiProviders: [],
isAutoSaveEnabled:
typeof window.ExtAutoSaveEnabled === 'undefined'
diff --git a/src/renderer/reducers/settings.ts b/src/renderer/reducers/settings.ts
index f5012ed1c..509c3ff96 100644
--- a/src/renderer/reducers/settings.ts
+++ b/src/renderer/reducers/settings.ts
@@ -75,6 +75,7 @@ export const types = {
REMOVE_AI_PROVIDER: 'SETTINGS/REMOVE_AI_PROVIDER',
SET_AI_PROVIDERS: 'SETTINGS/SET_AI_PROVIDERS',
SET_PREFIX_TAG_CONTAINER: 'SETTINGS/SET_PREFIX_TAG_CONTAINER',
+ SET_AUTHOR: 'SETTINGS/SET_AUTHOR',
SET_USEGENERATETHUMBNAILS: 'SETTINGS/SET_USEGENERATETHUMBNAILS',
SET_TAGCOLOR: 'SETTINGS/SET_TAGCOLOR',
SET_TAGTEXTCOLOR: 'SETTINGS/SET_TAGTEXTCOLOR',
@@ -321,6 +322,11 @@ export default (state: any = defaultSettings, action: any) => {
case types.SET_PREFIX_TAG_CONTAINER: {
return { ...state, prefixTagContainer: action.prefixTagContainer };
}
+ case types.SET_AUTHOR: {
+ const author =
+ action.author === undefined ? defaultSettings.author : action.author;
+ return { ...state, author: author };
+ }
case types.SET_USEGENERATETHUMBNAILS: {
return { ...state, useGenerateThumbnails: action.useGenerateThumbnails };
}
@@ -753,6 +759,10 @@ export const actions = {
type: types.SET_PREFIX_TAG_CONTAINER,
prefixTagContainer,
}),
+ setAuthor: (author: string) => ({
+ type: types.SET_AUTHOR,
+ author,
+ }),
setUseGenerateThumbnails: (useGenerateThumbnails: boolean) => ({
type: types.SET_USEGENERATETHUMBNAILS,
useGenerateThumbnails,
@@ -999,6 +1009,8 @@ export const getAIProviders = (state: any) => {
};
export const getPrefixTagContainer = (state: any) =>
state.settings.prefixTagContainer;
+export const getAuthor = (state: any) =>
+ window.ExtAuthor ?? state.settings.author;
export const getGeoTaggingFormat = (state: any) =>
state.settings.geoTaggingFormat;
export const getAddTagsToLibrary = (state: any) =>
diff --git a/src/renderer/tagspaces.d.ts b/src/renderer/tagspaces.d.ts
index bbd10dc75..0e30fb1bf 100644
--- a/src/renderer/tagspaces.d.ts
+++ b/src/renderer/tagspaces.d.ts
@@ -88,6 +88,7 @@ declare interface Window {
ExtTagsFromImagePrompt?: string;
ExtFileTemplates?: Array<any>;
ExtDefaultFileTemplate?: any;
+ ExtAuthor?: string;
}
declare interface NodeModule {