Skip to content

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

fixes

sytolk17b25328637b
diff --git a/.gitignore b/.gitignore
index 9149bf769..59da1b5e8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -84,7 +84,7 @@ web/EULA.txt
.env
src/.env
-src/renderer/config
+src/main/config
src/renderer/extconfig*
web/extconfig*
!web/extconfig.tmpl.js
diff --git a/.prettierignore b/.prettierignore
index d16cb6065..474541278 100755
--- a/.prettierignore
+++ b/.prettierignore
@@ -45,6 +45,6 @@ tests/file-structure
tests/bin
.ycache
src/renderer/aws-exports.js
-src/renderer/config/config.json
+src/main/config/config.json
src/renderer/extension-config.ts
app/version.json
diff --git a/scripts/jwt_generate.js b/scripts/jwt_generate.js
index 1ed0bee64..7ed054da5 100644
--- a/scripts/jwt_generate.js
+++ b/scripts/jwt_generate.js
@@ -17,7 +17,7 @@ const token = jwt.sign(payload, properties.get('KEY'));
const content = '{"jwt":"' + token + '"}';
fs.outputFileSync(
- pathLib.join(__dirname, '../src/renderer/config/config.json'),
+ pathLib.join(__dirname, '../src/main/config/config.json'),
content,
);
/* fs.writeFile(
diff --git a/src/main/main.ts b/src/main/main.ts
index 3138938bd..ce10ca44b 100644
--- a/src/main/main.ts
+++ b/src/main/main.ts
@@ -9,23 +9,15 @@
* `./src/main.js` using webpack. This gives us some performance wins.
*/
import path from 'path';
-import {
- app,
- BrowserWindow,
- shell,
- ipcMain,
- globalShortcut,
- dialog,
-} from 'electron';
+import { app, BrowserWindow, shell, ipcMain, globalShortcut } from 'electron';
import { autoUpdater } from 'electron-updater';
import log from 'electron-log';
import pm2 from '@elife/pm2';
import propertiesReader from 'properties-reader';
-import fs from 'fs-extra';
import { resolveHtmlPath } from './util';
import windowStateKeeper from 'electron-window-state';
import findFreePorts from 'find-free-ports';
-import settings from '../renderer/settings';
+import settings from './settings';
import { getExtensions } from './extension-utils';
import i18nInit from '../renderer/services/i18nInit';
import buildTrayIconMenu from './electron-tray-menu';
@@ -41,11 +33,11 @@ class AppUpdater {
}
let mainWindow: BrowserWindow | null = null;
-let usedWsPort = undefined;
+/*let usedWsPort = undefined;
function getUsedWsPort() {
return usedWsPort;
-}
+}*/
if (process.env.NODE_ENV === 'production') {
const sourceMapSupport = require('source-map-support');
@@ -400,7 +392,8 @@ function startWS() {
} else if (err) {
reject(err);
} else {
- usedWsPort = freePort;
+ settings.setUsedWsPort(freePort);
+ // usedWsPort = freePort;
if (mainWindow) {
mainWindow.webContents.send('start_ws', {
port: freePort,
@@ -471,16 +464,15 @@ const createWindow = async (i18n) => {
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36';
const testWinOnUnix = false; // set to true to simulate windows os, useful for testing s3 handling
- mainWindow
- .loadURL(
- resolveHtmlPath('index.html') + startupParameter,
- testWinOnUnix ? { userAgent: winUserAgent } : {},
- )
- .then(() => {
+ mainWindow.loadURL(
+ resolveHtmlPath('index.html') + startupParameter,
+ testWinOnUnix ? { userAgent: winUserAgent } : {},
+ );
+ /*.then(() => {
mainWindow.webContents.send('start_ws', {
port: getUsedWsPort(),
});
- });
+ });*/
mainWindow.webContents.on('before-input-event', (_, input) => {
if (input.type === 'keyDown' && input.key === 'F12') {
diff --git a/src/main/mainEvents.ts b/src/main/mainEvents.ts
index b7d615d80..ebc671897 100644
--- a/src/main/mainEvents.ts
+++ b/src/main/mainEvents.ts
@@ -23,11 +23,15 @@ import {
import fs from 'fs-extra';
import path from 'path';
import chokidar, { FSWatcher } from 'chokidar';
-import { postRequest, readMacOSTags } from './util';
+import { isWorkerAvailable, postRequest, readMacOSTags } from './util';
let watcher: FSWatcher = undefined;
export default function loadMainEvents() {
+ ipcMain.handle('isWorkerAvailable', async () => {
+ const results = await isWorkerAvailable();
+ return results;
+ });
ipcMain.handle('resolveRelativePaths', (event, relativePath) => {
return path.resolve(relativePath);
});
@@ -69,13 +73,10 @@ export default function loadMainEvents() {
//const chokidar = require('chokidar');
watcher = chokidar.watch(locationPath, options);
});
- ipcMain.handle(
- 'postRequest',
- async (event, payload, endpoint, token, wsPort) => {
- const result = await postRequest(payload, endpoint, token, wsPort);
- return result;
- },
- );
+ ipcMain.handle('postRequest', async (event, payload, endpoint) => {
+ const result = await postRequest(payload, endpoint);
+ return result;
+ });
ipcMain.handle(
'listDirectoryPromise',
async (event, path, mode, ignorePatterns, resultsLimit) => {
diff --git a/src/main/preload.ts b/src/main/preload.ts
index 169959109..24cd1f244 100644
--- a/src/main/preload.ts
+++ b/src/main/preload.ts
@@ -3,6 +3,7 @@
import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron';
export type Channels =
+ | 'isWorkerAvailable'
| 'resolveRelativePaths'
| 'set-language'
| 'setZoomFactor'
diff --git a/src/renderer/settings.ts b/src/main/settings.ts
similarity index 87%
rename from src/renderer/settings.ts
rename to src/main/settings.ts
index fbf4a9792..d390894e6 100644
--- a/src/renderer/settings.ts
+++ b/src/main/settings.ts
@@ -17,6 +17,7 @@
*/
class SettingsSingleton {
private usedWsPort?: number;
+ private token?: string;
getInitWsPort(): number {
return 49352;
@@ -29,6 +30,14 @@ class SettingsSingleton {
setUsedWsPort(port: number): void {
this.usedWsPort = port;
}
+
+ getToken(): string | undefined {
+ return this.token;
+ }
+
+ setToken(token: string): void {
+ this.token = token;
+ }
}
const settings = new SettingsSingleton();
diff --git a/src/main/util.ts b/src/main/util.ts
index 5d1b5324e..dc94aad5b 100644
--- a/src/main/util.ts
+++ b/src/main/util.ts
@@ -6,6 +6,8 @@ import fs from 'fs';
import chalk from 'chalk';
import { execSync } from 'child_process';
import http from 'http';
+import settings from './settings';
+import config from './config/config.json';
export function resolveHtmlPath(htmlFileName: string) {
if (process.env.NODE_ENV === 'development') {
@@ -66,51 +68,54 @@ export function generateJWT() {
/**
* @param payload: string
* @param endpoint: string
- * @param token: string
- * @param wsPort: number
*/
-export function postRequest(payload, endpoint, token, wsPort) {
- return new Promise((resolve, reject) => {
- const option = {
- hostname: '127.0.0.1',
- port: wsPort,
- method: 'POST',
- path: endpoint,
- headers: {
- Authorization: 'Bearer ' + token,
- 'Content-Type': 'application/json',
- 'Content-Length': Buffer.byteLength(payload, 'utf8'),
- },
- };
- const reqPost = http
- .request(option, (resp) => {
- // .get('http://127.0.0.1:8888/thumb-gen?' + search.toString(), resp => {
- let data = '';
+export function postRequest(payload, endpoint) {
+ return isWorkerAvailable().then((workerAvailable) => {
+ if (!workerAvailable) {
+ return Promise.reject(new Error('no Worker Available!'));
+ }
+ return new Promise((resolve, reject) => {
+ const option = {
+ hostname: '127.0.0.1',
+ port: settings.getUsedWsPort(),
+ method: 'POST',
+ path: endpoint,
+ headers: {
+ Authorization: 'Bearer ' + settings.getToken(),
+ 'Content-Type': 'application/json',
+ 'Content-Length': Buffer.byteLength(payload, 'utf8'),
+ },
+ };
+ const reqPost = http
+ .request(option, (resp) => {
+ // .get('http://127.0.0.1:8888/thumb-gen?' + search.toString(), resp => {
+ let data = '';
- // A chunk of data has been received.
- resp.on('data', (chunk) => {
- data += chunk;
- });
+ // A chunk of data has been received.
+ resp.on('data', (chunk) => {
+ data += chunk;
+ });
- // The whole response has been received. Print out the result.
- resp.on('end', () => {
- if (data) {
- try {
- resolve(JSON.parse(data));
- } catch (ex) {
- reject(ex);
+ // The whole response has been received. Print out the result.
+ resp.on('end', () => {
+ if (data) {
+ try {
+ resolve(JSON.parse(data));
+ } catch (ex) {
+ reject(ex);
+ }
+ } else {
+ reject(new Error('Error: no data'));
}
- } else {
- reject(new Error('Error: no data'));
- }
+ });
+ })
+ .on('error', (err) => {
+ console.log('Error: ' + err.message);
+ reject(err);
});
- })
- .on('error', (err) => {
- console.log('Error: ' + err.message);
- reject(err);
- });
- reqPost.write(payload);
- reqPost.end();
+ reqPost.write(payload);
+ reqPost.end();
+ });
});
}
@@ -162,3 +167,34 @@ export function readMacOSTags(filename) {
});
});
}
+
+/**
+ * needs to run in init this function always return false first time
+ */
+export function isWorkerAvailable(): Promise<boolean> {
+ if (settings.getToken() !== undefined) {
+ return Promise.resolve(settings.getToken() !== 'not');
+ }
+ try {
+ fetch('http://127.0.0.1:' + settings.getUsedWsPort(), {
+ method: 'HEAD',
+ }).then((res) => {
+ if (res.status === 200) {
+ if (config && config.jwt) {
+ settings.setToken(config.jwt);
+ return true;
+ } else {
+ console.error('jwt token not generated');
+ settings.setToken('not');
+ }
+ }
+ });
+ } catch (e) {
+ if (e && e.code && e.code === 'MODULE_NOT_FOUND') {
+ console.error('WS error MODULE_NOT_FOUND');
+ settings.setToken('not');
+ }
+ console.debug('isWorkerAvailable:', e);
+ }
+ return Promise.resolve(false);
+}
diff --git a/src/renderer/components/DirectoryTreeView.tsx b/src/renderer/components/DirectoryTreeView.tsx
index f154e4aae..cb85ff7c4 100644
--- a/src/renderer/components/DirectoryTreeView.tsx
+++ b/src/renderer/components/DirectoryTreeView.tsx
@@ -46,8 +46,8 @@ export interface DirectoryTreeViewRef {
const DirectoryTreeView = forwardRef(
(props: Props, ref: Ref<DirectoryTreeViewRef>) => {
const { classes, location, handleFileMoveDrop } = props;
- const { openDirectory } = useDirectoryContentContext();
- const { changeLocation, currentLocationPath } = useCurrentLocationContext();
+ const { openDirectory, currentLocationPath } = useDirectoryContentContext();
+ const { changeLocation } = useCurrentLocationContext();
const [data, setData] = useState(undefined);
const [isExpanded, setExpanded] = useState(false);
diff --git a/src/renderer/components/LocationView.tsx b/src/renderer/components/LocationView.tsx
index 4e544f43b..be0584298 100644
--- a/src/renderer/components/LocationView.tsx
+++ b/src/renderer/components/LocationView.tsx
@@ -60,14 +60,17 @@ function LocationView(props: Props) {
const {
openLocation,
currentLocation,
- currentLocationPath,
readOnlyMode,
setSelectedLocation,
setLocationDirectoryContextMenuAnchorEl,
} = useCurrentLocationContext();
const { setSelectedEntries } = useSelectedEntriesContext();
- const { currentDirectoryPath, addDirectoryEntries, openDirectory } =
- useDirectoryContentContext();
+ const {
+ currentDirectoryPath,
+ currentLocationPath,
+ addDirectoryEntries,
+ openDirectory,
+ } = useDirectoryContentContext();
const { showNotification } = useNotificationContext();
const directoryTreeRef = useRef<DirectoryTreeViewRef>(null);
diff --git a/src/renderer/components/menus/FileMenu.tsx b/src/renderer/components/menus/FileMenu.tsx
index ad0392dd7..f96d59c11 100644
--- a/src/renderer/components/menus/FileMenu.tsx
+++ b/src/renderer/components/menus/FileMenu.tsx
@@ -110,12 +110,11 @@ function FileMenu(props: Props) {
const dispatch: AppDispatch = useDispatch();
const { selectedEntries } = useSelectedEntriesContext();
const { openEntry } = useOpenedEntryContext();
- const { openDirectory } = useDirectoryContentContext();
+ const { openDirectory, currentLocationPath } = useDirectoryContentContext();
const { showNotification } = useNotificationContext();
const { copyFilePromise, setFolderThumbnailPromise } =
usePlatformFacadeContext();
- const { currentLocation, readOnlyMode, currentLocationPath } =
- useCurrentLocationContext();
+ const { currentLocation, readOnlyMode } = useCurrentLocationContext();
//const locations: Array<TS.Location> = useSelector(getLocations);
const prefixTagContainer = useSelector(getPrefixTagContainer);
const warningOpeningFilesExternally = useSelector(
diff --git a/src/renderer/hooks/CurrentLocationContextProvider.tsx b/src/renderer/hooks/CurrentLocationContextProvider.tsx
index 812b499c1..f996899f3 100644
--- a/src/renderer/hooks/CurrentLocationContextProvider.tsx
+++ b/src/renderer/hooks/CurrentLocationContextProvider.tsx
@@ -42,7 +42,6 @@ import { getPersistTagsInSidecarFile } from '-/reducers/settings';
type CurrentLocationContextData = {
currentLocation: TS.Location;
- currentLocationPath: string;
readOnlyMode: boolean;
skipInitialDirList: boolean;
persistTagsInSidecarFile: boolean;
@@ -72,7 +71,6 @@ type CurrentLocationContextData = {
export const CurrentLocationContext = createContext<CurrentLocationContextData>(
{
currentLocation: undefined,
- currentLocationPath: undefined,
readOnlyMode: false,
skipInitialDirList: false,
persistTagsInSidecarFile: true,
@@ -108,7 +106,6 @@ export const CurrentLocationContextProvider = ({
const { showNotification } = useNotificationContext();
const [currentLocation, setCurrentLocation] =
useState<TS.Location>(undefined);
- const currentLocationPath = useRef<string>('');
const selectedLocation = useRef<TS.Location>(undefined);
const skipInitialDirList = useRef<boolean>(false);
const [
@@ -135,14 +132,6 @@ export const CurrentLocationContextProvider = ({
}
}, []);
- useEffect(() => {
- if (currentLocation) {
- getLocationPath(currentLocation).then(
- (path) => (currentLocationPath.current = path),
- );
- }
- }, [currentLocation]);
-
useEffect(() => {
if (locations.length < 1) {
// init locations
@@ -403,7 +392,6 @@ export const CurrentLocationContextProvider = ({
const context = useMemo(() => {
return {
currentLocation,
- currentLocationPath: currentLocationPath.current,
readOnlyMode,
skipInitialDirList: skipInitialDirList.current,
persistTagsInSidecarFile,
@@ -427,7 +415,6 @@ export const CurrentLocationContextProvider = ({
};
}, [
currentLocation,
- currentLocationPath.current,
persistTagsInSidecarFile,
skipInitialDirList.current,
locationDirectoryContextMenuAnchorEl,
diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsx
index 5e832e2f5..15be69c58 100644
--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx
+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx
@@ -40,7 +40,6 @@ import {
extractTagsAsObjects,
extractParentDirectoryPath,
getMetaFileLocationForDir,
- normalizePath,
getMetaDirectoryPath,
} from '@tagspaces/tagspaces-common/paths';
import PlatformIO from '-/services/platform-facade';
@@ -60,7 +59,6 @@ import {
} from '-/reducers/settings';
import { enhanceEntry, getUuid } from '@tagspaces/tagspaces-common/utils-io';
import { useCurrentLocationContext } from '-/hooks/useCurrentLocationContext';
-import useFirstRender from '-/utils/useFirstRender';
import { useNotificationContext } from '-/hooks/useNotificationContext';
import { loadCurrentDirMeta } from '-/services/meta-loader';
import { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';
@@ -70,6 +68,7 @@ import { defaultTitle } from '-/services/search';
import { Pro } from '-/pro';
type DirectoryContentContextData = {
+ currentLocationPath: string;
currentDirectoryEntries: TS.FileSystemEntry[];
directoryMeta: TS.FileSystemEntryMeta;
currentDirectoryPerspective: string;
@@ -127,6 +126,7 @@ type DirectoryContentContextData = {
export const DirectoryContentContext =
createContext<DirectoryContentContextData>({
+ currentLocationPath: undefined,
currentDirectoryEntries: [],
directoryMeta: undefined,
currentDirectoryPerspective: undefined,
@@ -175,8 +175,11 @@ export const DirectoryContentContextProvider = ({
closeAllLocations,
currentLocation,
skipInitialDirList,
- currentLocationPath,
+ getLocationPath,
} = useCurrentLocationContext();
+
+ const currentLocationPath = useRef<string>('');
+
const { showNotification, hideNotifications } = useNotificationContext();
const { selectedEntries, setSelectedEntries } = useSelectedEntriesContext();
@@ -213,15 +216,19 @@ export const DirectoryContentContextProvider = ({
const currentPerspective = useRef<string>(PerspectiveIDs.UNSPECIFIED);
const currentDirectoryFiles = useRef<TS.OrderVisibilitySettings[]>([]);
const currentDirectoryDirs = useRef<TS.OrderVisibilitySettings[]>([]);
- const firstRender = useFirstRender();
+ // const firstRender = useFirstRender();
const [ignored, forceUpdate] = useReducer((x) => x + 1, 0, undefined);
useEffect(() => {
if (currentLocation) {
- if (!skipInitialDirList) {
- openDirectory(currentLocationPath);
- }
+ getLocationPath(currentLocation).then((locationPath) => {
+ currentLocationPath.current = locationPath;
+ if (!skipInitialDirList) {
+ return openDirectory(locationPath);
+ }
+ });
} else {
+ currentLocationPath.current = '';
clearDirectoryContent();
exitSearchMode();
}
@@ -369,9 +376,6 @@ export const DirectoryContentContextProvider = ({
if (isSearchMode.current) {
exitSearchMode();
}
- /*const currentLocationPath = normalizePath(
- PlatformIO.getLocationPath(currentLocation),
- );*/
// dispatch(actions.setIsLoading(true));
@@ -384,9 +388,9 @@ export const DirectoryContentContextProvider = ({
'parentDirectory: ' +
parentDirectory +
' - currentLocationPath: ' +
- currentLocationPath,
+ currentLocationPath.current,
);
- if (parentDirectory.includes(currentLocationPath)) {
+ if (parentDirectory.includes(currentLocationPath.current)) {
openDirectory(parentDirectory);
} else {
showNotification(t('core:parentDirNotInLocation'), 'warning', true);
@@ -554,7 +558,7 @@ export const DirectoryContentContextProvider = ({
dispatch(AppActions.toggleTruncatedConfirmDialog());
}
updateHistory(
- { ...currentLocation, path: currentLocationPath },
+ { ...currentLocation, path: currentLocationPath.current },
directoryPath,
);
if (results !== undefined) {
@@ -856,6 +860,7 @@ export const DirectoryContentContextProvider = ({
const context = useMemo(() => {
return {
+ currentLocationPath: currentLocationPath.current,
currentDirectoryEntries: currentDirectoryEntries,
directoryMeta: directoryMeta.current,
currentDirectoryPerspective: currentPerspective.current,
@@ -892,6 +897,7 @@ export const DirectoryContentContextProvider = ({
};
}, [
currentLocation,
+ currentLocationPath.current,
currentDirectoryEntries,
currentDirectoryPath.current,
directoryMeta.current,
diff --git a/src/renderer/hooks/FSWatcherContextProvider.tsx b/src/renderer/hooks/FSWatcherContextProvider.tsx
index 6673bca0a..e993a8fbd 100644
--- a/src/renderer/hooks/FSWatcherContextProvider.tsx
+++ b/src/renderer/hooks/FSWatcherContextProvider.tsx
@@ -67,10 +67,11 @@ export type FSWatcherContextProviderProps = {
export const FSWatcherContextProvider = ({
children,
}: FSWatcherContextProviderProps) => {
- const { currentLocation, currentLocationPath } = useCurrentLocationContext();
+ const { currentLocation } = useCurrentLocationContext();
const {
loadDirectoryContent,
currentDirectoryPath,
+ currentLocationPath,
currentDirectoryPerspective,
addDirectoryEntries,
removeDirectoryEntries,
diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsx
index 489d67541..47b25c8ca 100644
--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx
+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx
@@ -149,15 +149,12 @@ export const OpenedEntryContextProvider = ({
const dispatch: AppDispatch = useDispatch();
const { t } = useTranslation();
- const {
- openLocation,
- currentLocation,
- getLocationPath,
- currentLocationPath,
- } = useCurrentLocationContext();
+ const { openLocation, currentLocation, getLocationPath } =
+ useCurrentLocationContext();
const {
currentDirectoryEntries,
currentDirectoryPath,
+ currentLocationPath,
openDirectory,
addDirectoryEntries,
} = useDirectoryContentContext();
diff --git a/src/renderer/hooks/RendererListenerContextProvider.tsx b/src/renderer/hooks/RendererListenerContextProvider.tsx
index f0b699070..9c27e9f64 100644
--- a/src/renderer/hooks/RendererListenerContextProvider.tsx
+++ b/src/renderer/hooks/RendererListenerContextProvider.tsx
@@ -22,7 +22,6 @@ import { actions as AppActions, AppDispatch } from '-/reducers/app';
import { useOpenedEntryContext } from '-/hooks/useOpenedEntryContext';
import { useDirectoryContentContext } from '-/hooks/useDirectoryContentContext';
import AppConfig from '-/AppConfig';
-import settings from '-/settings';
import { actions as SettingsActions } from '-/reducers/settings';
type RendererListenerContextData = {};
@@ -169,11 +168,11 @@ export const RendererListenerContextProvider = ({
//console.debug('supportedFileTypes', supportedFileTypes);
});
- ipcRenderer.on('start_ws', (event, arg) => {
+ /*ipcRenderer.on('start_ws', (event, arg) => {
const { port } = arg;
console.debug('RendererListener start_ws port:' + port);
settings.setUsedWsPort(port);
- });
+ });*/
}
return () => {
destroy(ipcRenderer);
diff --git a/src/renderer/hooks/ThumbGenerationContextProvider.tsx b/src/renderer/hooks/ThumbGenerationContextProvider.tsx
index b04e245d8..3abd0f74b 100644
--- a/src/renderer/hooks/ThumbGenerationContextProvider.tsx
+++ b/src/renderer/hooks/ThumbGenerationContextProvider.tsx
@@ -149,7 +149,19 @@ export const ThumbGenerationContextProvider = ({
return Promise.resolve(false);
}
- const isWorkerAvailable = enableWS && PlatformIO.isWorkerAvailable();
+ if (AppConfig.isElectron) {
+ return PlatformIO.isWorkerAvailable().then((isWorkerAvailable) =>
+ generateThumbnails2(dirEntries, isWorkerAvailable),
+ );
+ }
+ return generateThumbnails2(dirEntries, false);
+ }
+
+ function generateThumbnails2(
+ dirEntries: TS.FileSystemEntry[],
+ isWorkerAvailable,
+ ): Promise<boolean> {
+ // const isWorkerAvailable = enableWS && PlatformIO.isWorkerAvailable();
const workerEntries: string[] = [];
const mainEntries: string[] = [];
dirEntries.map((entry) => {
@@ -159,7 +171,11 @@ export const ThumbGenerationContextProvider = ({
if (!showUnixHiddenEntries && entry.name.startsWith('.')) {
return true;
}
- if (isWorkerAvailable && supportedImgsWS.includes(entry.extension)) {
+ if (
+ isWorkerAvailable &&
+ enableWS &&
+ supportedImgsWS.includes(entry.extension)
+ ) {
workerEntries.push(entry.path);
} else if (
supportedImgs.includes(entry.extension) ||
@@ -202,6 +218,7 @@ export const ThumbGenerationContextProvider = ({
return true;
});
}
+
setGenThumbs(false);
return Promise.resolve(false);
}
diff --git a/src/renderer/reducers/app.ts b/src/renderer/reducers/app.ts
index 342c703d0..1a7139243 100644
--- a/src/renderer/reducers/app.ts
+++ b/src/renderer/reducers/app.ts
@@ -819,6 +819,11 @@ export const actions = {
return true;
});
}
+ PlatformIO.isWorkerAvailable().then((workerAvailable) =>
+ workerAvailable
+ ? console.log('Worker is available in renderer thread')
+ : console.log('Worker is not available in renderer thread'),
+ );
// let openDefaultLocation = true;
/*const lid = getURLParameter('tslid');
diff --git a/src/renderer/services/platform-facade.ts b/src/renderer/services/platform-facade.ts
index 638ee7dfc..e36b8e8ce 100644
--- a/src/renderer/services/platform-facade.ts
+++ b/src/renderer/services/platform-facade.ts
@@ -48,15 +48,11 @@ import {
platformSelectDirectoryDialog,
platformShareFiles,
platformCreateIndex,
- platformCreateNewInstance,
platformCheckFileExist,
platformCheckDirExist,
} from '@tagspaces/tagspaces-platforms/platform-io';
import AppConfig from '-/AppConfig';
import { TS } from '-/tagspaces.namespace';
-import settings from '-/settings';
-
-let token: string;
export default class PlatformFacade {
static enableObjectStoreSupport = (objectStoreConfig: any): Promise<any> =>
@@ -160,30 +156,11 @@ export default class PlatformFacade {
/**
* needs to run in init this function always return false first time
*/
- static isWorkerAvailable = (): boolean => {
- if (token !== undefined) {
- return token !== 'not';
- }
- if (AppConfig.isElectron) {
- try {
- fetch('http://127.0.0.1:' + settings.getUsedWsPort(), {
- method: 'HEAD',
- }).then((res) => {
- if (res.status === 200) {
- const config = require('-/config/config.json');
- token = config.jwt;
- return true;
- }
- });
- } catch (e) {
- if (e && e.code && e.code === 'MODULE_NOT_FOUND') {
- console.debug('jwt token not available');
- token = 'not';
- }
- console.debug('isWorkerAvailable:', e);
- }
+ static isWorkerAvailable = (): Promise<boolean> => {
+ if (AppConfig.isElectron) {
+ return window.electronIO.ipcRenderer.invoke('isWorkerAvailable');
}
- return false;
+ return Promise.resolve(false);
};
static readMacOSTags = (filename: string): Promise<TS.Tag[]> => {
@@ -222,9 +199,6 @@ export default class PlatformFacade {
ignorePatterns: Array<string>,
): Promise<any> => {
if (AppConfig.isElectron) {
- if (!PlatformFacade.isWorkerAvailable()) {
- return Promise.reject(new Error('no Worker Available!'));
- }
const payload = JSON.stringify({
directoryPath,
extractText,
@@ -234,8 +208,6 @@ export default class PlatformFacade {
'postRequest',
payload,
'/thumb-gen',
- token,
- settings.getUsedWsPort(),
);
}
return Promise.reject(
@@ -247,16 +219,11 @@ export default class PlatformFacade {
tmbGenerationList: Array<string>,
): Promise<any> => {
if (AppConfig.isElectron) {
- if (!PlatformFacade.isWorkerAvailable()) {
- return Promise.reject(new Error('no Worker Available!'));
- }
const payload = JSON.stringify(tmbGenerationList);
return window.electronIO.ipcRenderer.invoke(
'postRequest',
payload,
'/thumb-gen',
- token,
- settings.getUsedWsPort(),
);
}
return Promise.reject(new Error('createThumbnailsInWorker not Electron!'));
diff --git a/src/renderer/services/utils-io.ts b/src/renderer/services/utils-io.ts
index ff5cfd55a..ce97b0cd1 100644
--- a/src/renderer/services/utils-io.ts
+++ b/src/renderer/services/utils-io.ts
@@ -488,7 +488,8 @@ export function createDirectoryIndex(
ignorePatterns: Array<string> = [],
enableWS = true,
// disableIndexing = true,
-): Promise<Array<TS.FileSystemEntry>> {
+) {
+ //: Promise<TS.FileSystemEntry[]> {
if (Pro && Pro.Watcher) {
Pro.Watcher.stopWatching();
}
@@ -504,8 +505,8 @@ export function createDirectoryIndex(
if (
enableWS &&
!PlatformIO.haveObjectStoreSupport() &&
- !PlatformIO.haveWebDavSupport() &&
- PlatformIO.isWorkerAvailable()
+ !PlatformIO.haveWebDavSupport()
+ // PlatformIO.isWorkerAvailable()
) {
// Start indexing in worker if not in the object store mode
return PlatformIO.createDirectoryIndexInWorker(
@@ -516,7 +517,7 @@ export function createDirectoryIndex(
if (succeeded) {
return loadIndex({ path: dirPath, locationID });
}
- return undefined;
+ return undefined; // todo create index not in worker
});
}