Skip to content

Commit 5f86ff3

Browse files
committed
store backups at to root of the first location
1 parent 53e4b14 commit 5f86ff3

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

src/backend/backup-scheduler.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ export default class BackupScheduler implements DataBackup {
6565
console.log('BackupScheduler: Updated backup directory to', newDir);
6666
}
6767

68+
/**
69+
* Returns the current backup directory.
70+
*/
71+
getBackupDirectory(): string {
72+
return this.#backupDirectory;
73+
}
74+
6875
/**
6976
* Called whenever there's a data change that might merit an auto-backup.
7077
*/

src/frontend/containers/Settings/ImportExport.tsx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getFilenameFriendlyFormattedDateTime } from 'common/fmt';
22
import { shell } from 'electron';
33
import { observer } from 'mobx-react-lite';
44
import SysPath from 'path';
5-
import React, { useEffect, useState } from 'react';
5+
import React, { useState } from 'react';
66
import { AppToaster } from 'src/frontend/components/Toaster';
77
import { RendererMessenger } from 'src/ipc/renderer';
88
import { Button, ButtonGroup, IconSet } from 'widgets';
@@ -14,23 +14,20 @@ import FileInput from 'src/frontend/components/FileInput';
1414

1515
export const ImportExport = observer(() => {
1616
const rootStore = useStore();
17-
const { fileStore, tagStore, exifTool } = rootStore;
17+
const backupDir = rootStore.backupDirectory;
18+
1819
const [isConfirmingMetadataExport, setConfirmingMetadataExport] = useState(false);
1920
const [isConfirmingFileImport, setConfirmingFileImport] = useState<{
2021
path: string;
2122
info: string;
2223
}>();
23-
const [backupDir, setBackupDir] = useState('');
24-
useEffect(() => {
25-
RendererMessenger.getDefaultBackupDirectory().then(setBackupDir);
26-
}, []);
2724

2825
const handleChooseImportDir = async ([path]: [string, ...string[]]) => {
2926
try {
3027
const [numTags, numFiles] = await rootStore.peekDatabaseFile(path);
3128
setConfirmingFileImport({
3229
path,
33-
info: `Backup contains ${numTags} tags (currently ${tagStore.count}) and ${numFiles} images (currently ${fileStore.numTotalFiles}).`,
30+
info: `Backup contains ${numTags} tags (currently ${rootStore.tagStore.count}) and ${numFiles} images (currently ${rootStore.fileStore.numTotalFiles}).`,
3431
});
3532
} catch (e) {
3633
console.log(e);
@@ -72,31 +69,28 @@ export const ImportExport = observer(() => {
7269
The separator is used to format the tags metadata. For example a file with the assigned tags
7370
Food, Fruit and Apple will be formatted with the currently selected separator as{' '}
7471
<pre style={{ display: 'inline' }}>
75-
{['Food', 'Fruit', 'Apple'].join(exifTool.hierarchicalSeparator)}
72+
{['Food', 'Fruit', 'Apple'].join(rootStore.exifTool.hierarchicalSeparator)}
7673
</pre>
7774
.
7875
</Callout>
7976
<div className="vstack">
8077
<label>
8178
Hierarchical separator
8279
<select
83-
value={exifTool.hierarchicalSeparator}
84-
onChange={(e) => exifTool.setHierarchicalSeparator(e.target.value)}
80+
value={rootStore.exifTool.hierarchicalSeparator}
81+
onChange={(e) => rootStore.exifTool.setHierarchicalSeparator(e.target.value)}
8582
>
8683
<option value="|">|</option>
8784
<option value="/">/</option>
8885
<option value="\">\</option>
8986
<option value=":">:</option>
9087
</select>
9188
</label>
92-
{/* TODO: adobe bridge has option to read with multiple separators */}
93-
9489
<ButtonGroup>
9590
<Button
9691
text="Import tags from file metadata"
9792
onClick={() => {
98-
fileStore.readTagsFromFiles();
99-
// fileStore.readFacesAnnotationsFromFiles();
93+
rootStore.fileStore.readTagsFromFiles();
10094
}}
10195
styling="outlined"
10296
/>
@@ -111,7 +105,7 @@ export const ImportExport = observer(() => {
111105
primaryButtonText="Export"
112106
onClick={(button) => {
113107
if (button === DialogButton.PrimaryButton) {
114-
fileStore.writeTagsToFiles();
108+
rootStore.fileStore.writeTagsToFiles();
115109
}
116110
setConfirmingMetadataExport(false);
117111
}}

src/frontend/stores/RootStore.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import ImageLoader from '../image/ImageLoader';
1212

1313
import { RendererMessenger } from 'src/ipc/renderer';
1414
import SearchStore from './SearchStore';
15+
// Import BackupScheduler to access extended methods (e.g., getBackupDirectory)
16+
import BackupScheduler from 'src/backend/backup-scheduler';
1517

1618
// This will throw exceptions whenever we try to modify the state directly without an action
1719
// Actions will batch state modifications -> better for performance
@@ -44,7 +46,7 @@ class RootStore {
4446
private constructor(
4547
backend: DataStorage,
4648
backup: DataBackup,
47-
formatWindowTitle: (FileStore: FileStore, uiStore: UiStore) => string,
49+
formatWindowTitle: (fileStore: FileStore, uiStore: UiStore) => string,
4850
) {
4951
this.tagStore = new TagStore(backend, this);
5052
this.fileStore = new FileStore(backend, this);
@@ -182,6 +184,10 @@ class RootStore {
182184
// TODO: should be able to be done more reliably by running exiftool as a child process
183185
return this.exifTool.close();
184186
}
187+
188+
get backupDirectory(): string {
189+
return (this.#backup as BackupScheduler).getBackupDirectory();
190+
}
185191
}
186192

187193
export default RootStore;

0 commit comments

Comments
 (0)