cleanup comments, update translations, bump to 0.4.1
This commit is contained in:
parent
9edcc9841b
commit
7d8ab87eee
28 changed files with 412 additions and 1114 deletions
52
src/argv.js
52
src/argv.js
|
|
@ -3,35 +3,15 @@
|
|||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
// Shared command-line parsing for the launcher process itself. Both boot
|
||||
// (process.argv) and the single-instance handoff (second-instance argv) use
|
||||
// it, so a shortcut, a "Open with PLWL" file-open and Chromium's own injected
|
||||
// flags are handled the same way everywhere.
|
||||
//
|
||||
// Supported forms:
|
||||
// --launch <id> | --launch=<id> auto-start that library app
|
||||
// --file <path> | --file=<path> hand this file to the --launch app
|
||||
// --open <path> | --open=<path> open an .exe with the wine picker
|
||||
// a bare existing-file path same as --open (plumbing for Exec %f)
|
||||
//
|
||||
// Electron hands the second instance's argv over RE-SERIALIZED: every switch
|
||||
// comes first and its value follows as a positional argument, e.g. a shortcut
|
||||
// `--launch <id> --file <path>` arrives as
|
||||
// `--launch --file --allow-file-access-from-files <id> <path>`. Taking the
|
||||
// token next to an option therefore picks the wrong value (it used to take
|
||||
// the launch id as the opened file, so an app started without its image).
|
||||
// Options and positionals are matched IN ORDER here instead.
|
||||
// Command-line parsing shared by boot and the single-instance handoff.
|
||||
// Supported: --launch <id>, --file <path>, --open <path>, or a bare file path.
|
||||
// Electron re-serializes handoff argv, so options/positionals match in order.
|
||||
|
||||
const VALUE_OPTIONS = ['--launch', '--file', '--open']
|
||||
|
||||
// The options that carry a value, the positional arguments that follow the
|
||||
// switches, and the values written inline (`--name=value`, which keeps its
|
||||
// value no matter how the rest is ordered).
|
||||
//
|
||||
// Tokens before the first switch are the executable - never values. In dev
|
||||
// mode (`electron <app> ...`) Electron re-serializes the app path ALONG WITH
|
||||
// the values, so it is matched against the running app's own path and skipped:
|
||||
// it would otherwise be paired with the first option and shift every value.
|
||||
// Value options, the positionals that follow the switches, and inline
|
||||
// `--name=value` pairs. Tokens before the first switch are the executable
|
||||
// (matched against the running app path in dev mode and skipped).
|
||||
function splitArgv(argv) {
|
||||
const options = []
|
||||
const positional = []
|
||||
|
|
@ -56,10 +36,8 @@ function splitArgv(argv) {
|
|||
return { options, positional, inline }
|
||||
}
|
||||
|
||||
// The value of an option: inline when it was written as `--name=value`,
|
||||
// otherwise the positional argument with the SAME position as the option
|
||||
// among our value options (Chromium pushes all switches before all values, so
|
||||
// any other pairing would read another option's value).
|
||||
// An option's value: inline `--name=value`, or the positional at the same
|
||||
// in-order position among the value options.
|
||||
function optionValue(parsed, name) {
|
||||
if (parsed.inline.has(name)) return parsed.inline.get(name)
|
||||
const index = parsed.options.indexOf(name)
|
||||
|
|
@ -68,16 +46,11 @@ function optionValue(parsed, name) {
|
|||
return value === undefined ? null : value
|
||||
}
|
||||
|
||||
// The file an app shortcut was asked to open: `--file <path>` when the
|
||||
// generated shortcut passes it explicitly, or the path a file manager appends
|
||||
// on its own to an Exec line without a file field (KDE does that). Only an
|
||||
// absolute path counts in either place: the launch id, Chromium's injected
|
||||
// flags and the launcher's own path can never be mistaken for the document.
|
||||
// The file an app shortcut was asked to open; only an absolute path counts.
|
||||
const FIELD_CODE_RE = /^%[fFuUdDnNickvm]?$/
|
||||
function launchFileOf(parsed, launchId) {
|
||||
const explicit = optionValue(parsed, '--file')
|
||||
// a desktop environment that does not expand field codes would hand over
|
||||
// the literal token - never treat that as a file path
|
||||
// a literal %f token is never a file path
|
||||
if (explicit && !FIELD_CODE_RE.test(explicit) && path.isAbsolute(explicit)) return explicit
|
||||
if (!launchId) return null
|
||||
for (let i = parsed.positional.length - 1; i >= 0; i--) {
|
||||
|
|
@ -97,10 +70,7 @@ function parseArgv(argv) {
|
|||
const launchFile = launchFileOf(parsed, launchId)
|
||||
let openPath = optionValue(parsed, '--open')
|
||||
if (!openPath && !launchId) {
|
||||
// "Open with" plumbing (Exec %f): the file path arrives as the only
|
||||
// non-flag argument - never pick a bare token when a real flag carries
|
||||
// the intent, and skip this process's own binary (electron dev mode
|
||||
// passes it as the first argument).
|
||||
// Exec %f: the file path arrives as the only non-flag argument
|
||||
const bare = args.find(
|
||||
a =>
|
||||
!a.startsWith('-') &&
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue