Skip to content

Commit aba5b14

Browse files
authoredSep 26, 2024
Fix opening files from command line (tagspaces#2184)
1 parent 19096ee commit aba5b14

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed
 

‎run-with-args.patch

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
Index: app/main.dev.ts
1+
Index: src/main/main.ts
22
IDEA additional info:
33
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
44
<+>UTF-8
55
===================================================================
6-
diff --git a/app/main.dev.ts b/app/main.dev.ts
7-
--- a/app/main.dev.ts (revision d0f660fb4378c8eb8c59c516ecd10ff161c63d67)
8-
+++ b/app/main.dev.ts (date 1697032441057)
9-
@@ -90,6 +90,8 @@
10-
const devMode =
6+
diff --git a/src/main/main.ts b/src/main/main.ts
7+
--- a/src/main/main.ts (revision ae4ef7d57b496aed78413260f455195aded3f37b)
8+
+++ b/src/main/main.ts (date 1727359541758)
9+
@@ -61,6 +61,8 @@
10+
const isDebug =
1111
process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true';
12-
13-
+process.argv = [...process.argv, 'C:\\Users\\Stanimir\\search_history.png'];
12+
13+
+process.argv = [...process.argv, '/Users/sytolk/Public/sample.md.jpg'];
1414
+
15-
process.argv.forEach((arg, count) => {
16-
console.log('Opening file: ' + arg);
17-
if (
18-
@@ -102,10 +104,10 @@
15+
if (isDebug) {
16+
require('electron-debug')({ showDevTools: false });
17+
if (isMacLike) {
18+
@@ -86,10 +88,10 @@
1919
} else if (arg.toLowerCase() === '-p' || arg.toLowerCase() === '--portable') {
2020
app.setPath('userData', process.cwd() + '/tsprofile'); // making the app portable
2121
portableMode = true;
22-
- } else if (testMode || devMode) {
23-
+ } /* else if (testMode || devMode) {
22+
- } else if (testMode || isDebug) {
23+
+ } /* else if (testMode || isDebug) {
2424
// ignoring the spectron testing
2525
arg = '';
2626
- } else if (
27-
+ } */ else if (
27+
+ }*/ else if (
2828
arg.endsWith('main.prod.js') ||
2929
arg === './app/main.dev.babel.js' ||
3030
arg === '.' ||

‎src/main/main.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,19 @@ process.argv.forEach((arg, count) => {
9191
arg = '';
9292
} else if (
9393
arg.endsWith('main.prod.js') ||
94-
arg === './app/main.dev.babel.js' ||
94+
arg.indexOf('node_modules/electron/dist/') > -1 ||
95+
arg.endsWith('electronmon/src/hook.js') ||
96+
//arg === './app/main.dev.babel.js' ||
9597
arg === '.' ||
98+
arg === '--require' ||
9699
count === 0
97100
) {
98101
// ignoring the first argument
99102
} else if (arg.length > 2) {
100103
// console.warn('Opening file: ' + arg);
101-
if (arg !== './app/main.dev.js' && arg !== './app/') {
102-
startupFilePath = arg;
103-
}
104+
//if (arg !== './app/main.dev.js' && arg !== './app/' && arg !== '') {
105+
startupFilePath = arg;
106+
//}
104107
}
105108

106109
if (portableMode) {
@@ -495,6 +498,7 @@ function startWS() {
495498
const createWindow = async (i18n) => {
496499
let startupParameter = '';
497500
if (startupFilePath) {
501+
console.log('Startup file path: ' + startupFilePath);
498502
if (startupFilePath.startsWith('./') || startupFilePath.startsWith('.\\')) {
499503
startupParameter =
500504
'?cmdopen=' + encodeURIComponent(path.join(__dirname, startupFilePath));

‎src/renderer/hooks/OpenedEntryContextProvider.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,13 @@ export const OpenedEntryContextProvider = ({
145145
const dispatch: AppDispatch = useDispatch();
146146
const { t } = useTranslation();
147147

148-
const { currentLocation, findLocation, openLocation, getLocationPath } =
149-
useCurrentLocationContext();
148+
const {
149+
currentLocation,
150+
findLocation,
151+
openLocation,
152+
getLocationPath,
153+
getFirstRWLocation,
154+
} = useCurrentLocationContext();
150155
const { getMetadata } = useIOActionsContext();
151156
const {
152157
currentDirectoryPath,
@@ -686,7 +691,8 @@ export const OpenedEntryContextProvider = ({
686691
const id = getURLParameter('tseid', url);
687692
if (cmdOpen && cmdOpen.length > 0) {
688693
const entryPath = decodeURIComponent(cmdOpen);
689-
getAllPropertiesPromise(entryPath, lid)
694+
const locationId = lid ? lid : getFirstRWLocation()?.uuid;
695+
getAllPropertiesPromise(entryPath, locationId)
690696
.then((fsEntry: TS.FileSystemEntry) => {
691697
if (fsEntry.isFile) {
692698
openFsEntry(fsEntry);

0 commit comments

Comments
 (0)
Please sign in to comment.