pterm 0.0.18 → 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +18 -2
  2. package/index.js +12 -7
  3. package/package.json +1 -1
  4. package/script.js +54 -8
package/README.md CHANGED
@@ -103,15 +103,16 @@ pterm stop start.js
103
103
 
104
104
  ## run
105
105
 
106
- Run a launcher. Equivalent to the user visiting a launcher page. Will run whichever script is the current default script.
106
+ Run a launcher. Equivalent to the user visiting a launcher page. By default it will run whichever script is the current launcher default. If the launcher exposes no explicit default, you can provide repeated `--default` selectors and Pinokio will match the first selector that exists in the launcher's current menu state.
107
107
 
108
108
  ### syntax
109
109
 
110
110
  ```
111
- pterm run <launcher_path_or_uri> [--open]
111
+ pterm run <launcher_path_or_uri> [--default <selector>]... [--open]
112
112
  ```
113
113
 
114
114
  - `--open`: (optional) open URL results in the browser. Default behavior is to print the URL to stdout without opening a browser.
115
+ - `--default`: (optional, repeatable) ordered launcher action selector. Each selector is matched against the current launcher menu. Selectors use launcher `href` syntax such as `run.js`, `install.js`, or `run.js?mode=Default`.
115
116
 
116
117
  ### examples
117
118
 
@@ -133,6 +134,21 @@ Run from a launcher URI and auto-open the resulting URL in browser
133
134
  pterm run https://github.com/example/my-launcher --open
134
135
  ```
135
136
 
137
+ Run a launcher with ordered fallback selectors when the launcher has no explicit default item
138
+
139
+ ```
140
+ pterm run ~/pinokio/api/facefusion-pinokio.git \
141
+ --default 'run.js?mode=Default' \
142
+ --default run.js \
143
+ --default install.js
144
+ ```
145
+
146
+ Launch a script directly with query parameters. Query parameters are passed through as script input automatically.
147
+
148
+ ```
149
+ pterm start 'run.js?mode=Default'
150
+ ```
151
+
136
152
  ## search
137
153
 
138
154
  Search installed or available apps.
package/index.js CHANGED
@@ -2,7 +2,12 @@
2
2
  const path = require('path')
3
3
  const yargs = require('yargs/yargs')
4
4
  const { hideBin } = require('yargs/helpers')
5
- const argv = yargs(hideBin(process.argv)).parse();
5
+ const argv = yargs(hideBin(process.argv))
6
+ .option('default', {
7
+ type: 'string',
8
+ array: true
9
+ })
10
+ .parse();
6
11
  const Script = require('./script')
7
12
  const Util = require('./util')
8
13
  const script = new Script();
@@ -89,11 +94,11 @@ const isHttpUri = (value) => typeof value === "string" && /^https?:\/\//i.test(v
89
94
  })
90
95
  }
91
96
  while(true) {
92
- let default_uri = await script.default_script(uri)
93
- if (default_uri) {
94
- if (path.isAbsolute(default_uri)) {
97
+ let default_target = await script.default_script(uri, argv.default)
98
+ if (default_target) {
99
+ if (path.isAbsolute(default_target.uri)) {
95
100
  await new Promise((resolve, reject) => {
96
- script.start(default_uri, false, (packet) => {
101
+ script.start(default_target, false, (packet) => {
97
102
  if (packet.type === "result") {
98
103
  resolve()
99
104
  }
@@ -105,10 +110,10 @@ const isHttpUri = (value) => typeof value === "string" && /^https?:\/\//i.test(v
105
110
  } else {
106
111
  // default behavior is no browser side effect.
107
112
  if (argv.open) {
108
- let response = await util.open_url(default_uri)
113
+ let response = await util.open_url(default_target.uri)
109
114
  console.log({ response })
110
115
  } else {
111
- console.log(default_uri)
116
+ console.log(default_target.uri)
112
117
  }
113
118
  break
114
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pterm",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
package/script.js CHANGED
@@ -30,7 +30,44 @@ class Script {
30
30
 
31
31
  return cleanup; // call this to stop listening
32
32
  }
33
- async default_script (uri) {
33
+ normalizeTarget(target) {
34
+ const appendInputValue = (input, key, value) => {
35
+ if (Object.prototype.hasOwnProperty.call(input, key)) {
36
+ if (Array.isArray(input[key])) {
37
+ input[key].push(value)
38
+ } else {
39
+ input[key] = [input[key], value]
40
+ }
41
+ } else {
42
+ input[key] = value
43
+ }
44
+ }
45
+ if (target && typeof target === "object" && typeof target.uri === "string") {
46
+ return {
47
+ uri: target.uri,
48
+ input: target.input && typeof target.input === "object" ? target.input : undefined
49
+ }
50
+ }
51
+ let uri = target
52
+ let input
53
+ if (!/^https?:\/\//i.test(uri)) {
54
+ let queryIndex = uri.indexOf("?")
55
+ if (queryIndex >= 0) {
56
+ input = {}
57
+ let params = new URLSearchParams(uri.slice(queryIndex + 1))
58
+ for (let [key, value] of params.entries()) {
59
+ appendInputValue(input, key, value)
60
+ }
61
+ uri = uri.slice(0, queryIndex)
62
+ }
63
+ uri = path.resolve(process.cwd(), uri)
64
+ }
65
+ return {
66
+ uri,
67
+ input
68
+ }
69
+ }
70
+ async default_script (uri, defaultSelectors) {
34
71
  const rpc = new RPC("ws://localhost:42000")
35
72
  const stop = () => {
36
73
  rpc.run({
@@ -51,10 +88,11 @@ class Script {
51
88
  process.on("exit", (code) => {
52
89
  stop()
53
90
  });
54
- let default_uri = await new Promise((resolve, reject) => {
91
+ let default_target = await new Promise((resolve, reject) => {
55
92
  rpc.run({
56
93
  uri,
57
94
  mode: "open",
95
+ default: Array.isArray(defaultSelectors) ? defaultSelectors : undefined,
58
96
  source: "pterm",
59
97
  client: {
60
98
  source: "pterm"
@@ -64,16 +102,19 @@ class Script {
64
102
  // start
65
103
  //rpc.stop({ uri })
66
104
  stop()
67
- resolve(packet.data.uri)
105
+ resolve({
106
+ uri: packet.data.uri,
107
+ input: packet.data.input
108
+ })
68
109
  }
69
110
  })
70
111
  })
71
- return default_uri
112
+ return default_target
72
113
  }
73
114
  async stop(argv) {
74
115
  if (argv._.length > 1) {
75
116
  let _uri = argv._[1]
76
- const uri = path.resolve(process.cwd(), _uri)
117
+ const { uri } = this.normalizeTarget(_uri)
77
118
  const rpc = new RPC("ws://localhost:42000")
78
119
  rpc.run({
79
120
  method: "kernel.api.stop",
@@ -90,7 +131,8 @@ class Script {
90
131
  const rows = process.stdout.rows;
91
132
  const rpc = new RPC("ws://localhost:42000")
92
133
 
93
- const uri = path.resolve(process.cwd(), _uri)
134
+ const target = this.normalizeTarget(_uri)
135
+ const uri = target.uri
94
136
 
95
137
  const stop = () => {
96
138
  this.killed = true
@@ -139,7 +181,7 @@ class Script {
139
181
  }, (packet) => {
140
182
  })
141
183
  });
142
- await rpc.run({
184
+ let payload = {
143
185
  uri,
144
186
  source: "pterm",
145
187
  client: {
@@ -147,7 +189,11 @@ class Script {
147
189
  rows,
148
190
  source: "pterm"
149
191
  }
150
- }, (packet) => {
192
+ }
193
+ if (target.input && Object.keys(target.input).length > 0) {
194
+ payload.input = target.input
195
+ }
196
+ await rpc.run(payload, (packet) => {
151
197
  if (packet.type === "stop") {
152
198
  rpc.stop({ uri })
153
199
  if (kill) {