Skip to content

Commit 1c3da11

Browse files
fix: prevent parsing electron and argument options as files
Improve command-line argument options parse with minimist. Refs: #954
1 parent 2dd5882 commit 1c3da11

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
"node_modules/@sabaki/i18n/**/*",
7575
"node_modules/dolm/**/*",
7676
"node_modules/{iconv-lite,safer-buffer}/**/*",
77-
"node_modules/pikaday/css/*"
77+
"node_modules/pikaday/css/*",
78+
"node_modules/minimist"
7879
]
7980
},
8081
"prettier": {
@@ -102,6 +103,7 @@
102103
"fix-path": "<4.0.0",
103104
"iconv-lite": "^0.5.1",
104105
"jschardet": "^3.0.0",
106+
"minimist": "^1.2.6",
105107
"natsort": "^2.0.2",
106108
"pikaday": "^1.8.0",
107109
"preact": "^10.4.0",

src/main.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const {resolve} = require('path')
1111
const i18n = require('./i18n')
1212
const setting = require('./setting')
1313
const updater = require('./updater')
14+
const parseArgs = require('minimist')
15+
const argv = parseArgs(process.argv, {boolean: true})
1416
require('@electron/remote/main').initialize()
1517

1618
let windows = []
@@ -235,11 +237,11 @@ async function main() {
235237

236238
await app.whenReady()
237239

238-
if (!openfile && process.argv.length >= 2) {
239-
if (!['electron.exe', 'electron'].some(x => process.argv[0].endsWith(x))) {
240-
openfile = process.argv[1]
241-
} else if (process.argv.length >= 3) {
242-
openfile = process.argv[2]
240+
if (!openfile) {
241+
if (argv._[0].endsWith('sabaki')) {
242+
openfile = argv._[1]
243+
} else {
244+
openfile = argv._[2]
243245
}
244246
}
245247

0 commit comments

Comments
 (0)