Skip to content

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

Fix opening files from command line (#2184)

Stanimiraba5b1436c4c
diff --git a/run-with-args.patch b/run-with-args.patch
index a00b8d9e8..c790fb279 100644
--- a/run-with-args.patch
+++ b/run-with-args.patch
@@ -1,30 +1,30 @@
-Index: app/main.dev.ts
+Index: src/main/main.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
-diff --git a/app/main.dev.ts b/app/main.dev.ts
---- a/app/main.dev.ts (revision d0f660fb4378c8eb8c59c516ecd10ff161c63d67)
-+++ b/app/main.dev.ts (date 1697032441057)
-@@ -90,6 +90,8 @@
- const devMode =
+diff --git a/src/main/main.ts b/src/main/main.ts
+--- a/src/main/main.ts (revision ae4ef7d57b496aed78413260f455195aded3f37b)
++++ b/src/main/main.ts (date 1727359541758)
+@@ -61,6 +61,8 @@
+ const isDebug =
process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true';
-
-+process.argv = [...process.argv, 'C:\\Users\\Stanimir\\search_history.png'];
+
++process.argv = [...process.argv, '/Users/sytolk/Public/sample.md.jpg'];
+
- process.argv.forEach((arg, count) => {
- console.log('Opening file: ' + arg);
- if (
-@@ -102,10 +104,10 @@
+ if (isDebug) {
+ require('electron-debug')({ showDevTools: false });
+ if (isMacLike) {
+@@ -86,10 +88,10 @@
} else if (arg.toLowerCase() === '-p' || arg.toLowerCase() === '--portable') {
app.setPath('userData', process.cwd() + '/tsprofile'); // making the app portable
portableMode = true;
-- } else if (testMode || devMode) {
-+ } /* else if (testMode || devMode) {
+- } else if (testMode || isDebug) {
++ } /* else if (testMode || isDebug) {
// ignoring the spectron testing
arg = '';
- } else if (
-+ } */ else if (
++ }*/ else if (
arg.endsWith('main.prod.js') ||
arg === './app/main.dev.babel.js' ||
arg === '.' ||
diff --git a/src/main/main.ts b/src/main/main.ts
index 72a47c4e1..8ba9f1bf2 100644
--- a/src/main/main.ts
+++ b/src/main/main.ts
@@ -91,16 +91,19 @@ process.argv.forEach((arg, count) => {
arg = '';
} else if (
arg.endsWith('main.prod.js') ||
- arg === './app/main.dev.babel.js' ||
+ arg.indexOf('node_modules/electron/dist/') > -1 ||
+ arg.endsWith('electronmon/src/hook.js') ||
+ //arg === './app/main.dev.babel.js' ||
arg === '.' ||
+ arg === '--require' ||
count === 0
) {
// ignoring the first argument
} else if (arg.length > 2) {
// console.warn('Opening file: ' + arg);
- if (arg !== './app/main.dev.js' && arg !== './app/') {
- startupFilePath = arg;
- }
+ //if (arg !== './app/main.dev.js' && arg !== './app/' && arg !== '') {
+ startupFilePath = arg;
+ //}
}
if (portableMode) {
@@ -495,6 +498,7 @@ function startWS() {
const createWindow = async (i18n) => {
let startupParameter = '';
if (startupFilePath) {
+ console.log('Startup file path: ' + startupFilePath);
if (startupFilePath.startsWith('./') || startupFilePath.startsWith('.\\')) {
startupParameter =
'?cmdopen=' + encodeURIComponent(path.join(__dirname, startupFilePath));
diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsx
index 758e90981..6b8163863 100644
--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx
+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx
@@ -145,8 +145,13 @@ export const OpenedEntryContextProvider = ({
const dispatch: AppDispatch = useDispatch();
const { t } = useTranslation();
- const { currentLocation, findLocation, openLocation, getLocationPath } =
- useCurrentLocationContext();
+ const {
+ currentLocation,
+ findLocation,
+ openLocation,
+ getLocationPath,
+ getFirstRWLocation,
+ } = useCurrentLocationContext();
const { getMetadata } = useIOActionsContext();
const {
currentDirectoryPath,
@@ -686,7 +691,8 @@ export const OpenedEntryContextProvider = ({
const id = getURLParameter('tseid', url);
if (cmdOpen && cmdOpen.length > 0) {
const entryPath = decodeURIComponent(cmdOpen);
- getAllPropertiesPromise(entryPath, lid)
+ const locationId = lid ? lid : getFirstRWLocation()?.uuid;
+ getAllPropertiesPromise(entryPath, locationId)
.then((fsEntry: TS.FileSystemEntry) => {
if (fsEntry.isFile) {
openFsEntry(fsEntry);