Skip to content

Commit 1088f91

Browse files
committed
feat: support default port & input port
1 parent 240c3b0 commit 1088f91

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

.DS_Store

6 KB
Binary file not shown.

src/core.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import '@jxa/global-type'
2+
import type { Selection } from './types'
3+
4+
const app = Application.currentApplication()
5+
app.includeStandardAdditions = true
6+
7+
const getIntranetIP = () => (app.systemInfo() as any).ipv4Address
8+
9+
export const parsePort = (port: string): Selection => {
10+
return {
11+
title: `Port:${port}`,
12+
subtitle: `http://localhost:${port}`,
13+
arg: `localhost:${port}`,
14+
mods: {
15+
cmd: {
16+
subtitle: `http://127.0.0.1:${port}`,
17+
arg: `127.0.0.1:${port}`,
18+
},
19+
ctrl: {
20+
subtitle: `http://${getIntranetIP()}:${port}`,
21+
arg: `${getIntranetIP()}:${port}`,
22+
},
23+
},
24+
}
25+
}

src/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
import { parsePort } from './core'
12
import type { Selection } from './types'
23

3-
export default function run(argv: Array<string | boolean >) {
4+
export default function run(argv: [string, boolean]) {
45
const query = argv[0]
6+
const items = []
7+
items.push(parsePort('8080'))
8+
const currPort = parsePort(query)
9+
query && items.push(currPort)
10+
511
const result: {
612
items: Selection[]
713
} = {
8-
items: [{
9-
title: `This is a selection example, and you are inputing ${query}`,
10-
}],
14+
items,
1115
}
1216

1317
// for testing

src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ export interface Selection {
2323

2424
}
2525

26-
export type Mod = Record<ModComb, ModItem>
26+
export type Mod = Partial<Record<ModComb, ModItem>>
2727

2828
export type ModNames = 'cmd' | 'alt' | 'ctrl' | 'shift' | 'fn'
2929

3030
export type t = {
3131
[k in ModNames]: {
32-
[v in ModNames]: k extends v ? v extends k ? never : `${k} + ${v}` : `${k} + ${v}`
32+
[v in ModNames]: k extends v ? v extends k ? v : `${k} + ${v}` : `${k} + ${v}`
3333
}
3434
}
3535

3636
// the same key combinations is not allowed, 'fn + fn' e.g.
3737
export type ModComb = `${t[ModNames][ModNames]}`
3838

3939
export interface ModItem {
40-
valid: string
40+
valid?: string
4141
arg: string
4242
subtitle: string
4343
}

0 commit comments

Comments
 (0)