improvemets & fixes:
- added 'open with' handling to desktop shortcuts - move logs button to app configuration - fix sync progress disappearing after long hashing - fix sync double file counter - merge wine and proton prefix folders via symlink
This commit is contained in:
parent
8c6db38fab
commit
59ff0b1088
15 changed files with 520 additions and 113 deletions
35
src/argv.js
35
src/argv.js
|
|
@ -1,14 +1,18 @@
|
|||
'use strict'
|
||||
|
||||
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
|
||||
// --open <path> | --open=<path> open an .exe with the wine picker
|
||||
// a bare existing-file path same as --open (plumbing for Exec %f)
|
||||
// --launch <id> | --launch=<id> auto-start that library app
|
||||
// --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)
|
||||
|
||||
function firstNonFlagAfter(args, i) {
|
||||
// Chromium injects its own flags into the second instance's argv and they
|
||||
|
|
@ -34,9 +38,32 @@ function findValue(args, names) {
|
|||
// PLWL's own options must not swallow Chromium's flags (--flag=... style),
|
||||
// so anything after a flag that itself carries a value is skipped here by
|
||||
// looking only at the KNOWN option names above.
|
||||
// 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
|
||||
// existing absolute FILE counts in the fallback, so Chromium's injected flags
|
||||
// and the launcher's own path can never be mistaken for the opened document.
|
||||
const FIELD_CODE_RE = /^%[fFuUdDnNickvm]?$/
|
||||
function launchFileOf(args, launchId) {
|
||||
const explicit = findValue(args, ['--file'])
|
||||
// a desktop environment that does not expand field codes would hand over
|
||||
// the literal token - never treat that as a file path
|
||||
if (explicit && !FIELD_CODE_RE.test(explicit)) return explicit
|
||||
if (!launchId) return null
|
||||
for (let i = args.length - 1; i > 1; i--) {
|
||||
const arg = args[i]
|
||||
if (typeof arg !== 'string' || arg.startsWith('-') || !path.isAbsolute(arg)) continue
|
||||
try {
|
||||
if (fs.statSync(arg).isFile()) return arg
|
||||
} catch {}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function parseArgv(argv) {
|
||||
const args = Array.isArray(argv) ? argv : process.argv
|
||||
const launchId = findValue(args, ['--launch'])
|
||||
const launchFile = launchFileOf(args, launchId)
|
||||
let openPath = findValue(args, ['--open'])
|
||||
if (!openPath && !launchId) {
|
||||
// "Open with" plumbing (Exec %f): the file path arrives as the only
|
||||
|
|
@ -51,7 +78,7 @@ function parseArgv(argv) {
|
|||
)
|
||||
if (bare) openPath = bare
|
||||
}
|
||||
return { launchId, openPath }
|
||||
return { launchId, openPath, launchFile }
|
||||
}
|
||||
|
||||
module.exports = { parseArgv, findValue }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue