Skip to content

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

Moving files from one instance to another not updated in the source instance (#2227)

Stanimirc58f13e5799f
diff --git a/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx b/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx
index a3855dc57..c94c57e84 100644
--- a/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx
+++ b/src/renderer/components/dialogs/MoveOrCopyFilesDialog.tsx
@@ -64,7 +64,7 @@ function MoveOrCopyFilesDialog(props: Props) {
const { setReflectMetaActions } = useEditedEntryMetaContext();
const { findLocation } = useCurrentLocationContext();
const { moveFiles, copyFiles } = useIOActionsContext();
- const { currentDirectoryPath } = useDirectoryContentContext();
+ const { currentDirectoryPath, sendDirMessage } = useDirectoryContentContext();
const smallScreen = useMediaQuery(theme.breakpoints.down('md'));
const targetDir = props.targetDir ? props.targetDir : currentDirectoryPath;
const targetLocation = findLocation(targetLocationId);
@@ -84,6 +84,7 @@ function MoveOrCopyFilesDialog(props: Props) {
function handleMove(filePaths: string[]) {
moveFiles(filePaths, targetDir, targetLocation.uuid).then((success) => {
if (success) {
+ sendDirMessage('moveFiles', filePaths);
generateThumbs(
filePaths.map((targetPath) =>
joinPaths(
diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsx
index 9f137ed0e..f6e513a46 100644
--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx
+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx
@@ -33,7 +33,11 @@ import {
getDefaultPerspective,
getShowUnixHiddenEntries,
} from '-/reducers/settings';
-import { executePromisesInBatches, updateFsEntries } from '-/services/utils-io';
+import {
+ executePromisesInBatches,
+ instanceId,
+ updateFsEntries,
+} from '-/services/utils-io';
import { TS } from '-/tagspaces.namespace';
import { CommonLocation } from '-/utils/CommonLocation';
import { arrayBufferToDataURL, updateHistory } from '-/utils/dom';
@@ -78,6 +82,7 @@ type DirectoryContentContextData = {
//isMetaFolderExist: boolean;
searchQuery: TS.SearchQuery;
isSearchMode: boolean;
+ sendDirMessage: (type: string, payload?: any) => void;
addDirectoryEntries: (entries: TS.FileSystemEntry[]) => void;
//removeDirectoryEntries: (entryPaths: string[]) => void;
//reflectRenameEntries: (paths: Array<string[]>) => Promise<boolean>;
@@ -153,6 +158,7 @@ export const DirectoryContentContext =
//isMetaFolderExist: false,
searchQuery: {},
isSearchMode: false,
+ sendDirMessage: undefined,
addDirectoryEntries: undefined,
//removeDirectoryEntries: undefined,
//reflectRenameEntries: undefined,
@@ -240,11 +246,32 @@ export const DirectoryContentContextProvider = ({
const currentDirectoryDirs = useRef<TS.OrderVisibilitySettings[]>([]);
const firstRender = useFirstRender();
const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
+ const broadcast = new BroadcastChannel('ts-directory-channel');
const currentLocation = findLocation(currentLocationId);
useEffect(() => {
if (AppConfig.isElectron) {
+ try {
+ // Listen for messages from other instance
+ broadcast.onmessage = (event: MessageEvent) => {
+ const action = event.data as TS.BroadcastMessage;
+ if (instanceId !== action.uuid) {
+ if (action.type === 'moveFiles') {
+ const filePaths = action.payload as string[];
+ setCurrentDirectoryEntries(
+ currentDirectoryEntries.current.filter(
+ (entry) => !filePaths.includes(entry.path),
+ ),
+ );
+ //openDirectory(currentDirectoryPath.current);
+ }
+ }
+ };
+ } catch (e) {
+ console.error('broadcast.onmessage error:', e);
+ }
+
window.electronIO.ipcRenderer.on('cmd', (arg) => {
if (arg === 'open-search') {
setSearchQuery({ textQuery: '' });
@@ -340,6 +367,15 @@ export const DirectoryContentContextProvider = ({
}
}, [actions]);
+ function sendDirMessage(type: string, payload?: any) {
+ try {
+ const message: TS.BroadcastMessage = { uuid: instanceId, type, payload };
+ broadcast.postMessage(message);
+ } catch (e) {
+ console.error('broadcast.postMessage error:', e);
+ }
+ }
+
const reflectActions = async (actions) => {
if (actions && actions.length > 0) {
for (const action of actions) {
@@ -1084,7 +1120,7 @@ export const DirectoryContentContextProvider = ({
}
function setSearchQuery(sQuery: TS.SearchQuery) {
- if (Object.keys(searchQuery).length === 0) {
+ if (Object.keys(sQuery).length === 0) {
exitSearchMode();
} else {
isSearchMode.current = true;
@@ -1444,6 +1480,7 @@ export const DirectoryContentContextProvider = ({
//isMetaFolderExist: isMetaFolderExist.current,
searchQuery: searchQuery.current,
isSearchMode: isSearchMode.current,
+ sendDirMessage,
getPerspective,
setCurrentDirectoryEntries,
updateCurrentDirEntry,