Skip to content

Commit 38ab3fb

Browse files
author
linyuan.yang
committed
build:pwa
1 parent d5ad20c commit 38ab3fb

8 files changed

Lines changed: 40 additions & 16 deletions

File tree

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

docs/pwa/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<link rel="icon" href="/sbot/pwa/logo.svg" type="image/svg+xml">
1010
<link rel="apple-touch-icon" href="/sbot/pwa/pwa-192x192.png">
1111
<title>sbot</title>
12-
<script type="module" crossorigin src="/sbot/pwa/assets/index-ClA1GbxV.js"></script>
13-
<link rel="stylesheet" crossorigin href="/sbot/pwa/assets/index-CRJa2Ob5.css">
12+
<script type="module" crossorigin src="/sbot/pwa/assets/index-00WzkvsF.js"></script>
13+
<link rel="stylesheet" crossorigin href="/sbot/pwa/assets/index-BbonGCOR.css">
1414
<link rel="manifest" href="/sbot/pwa/manifest.webmanifest"><script id="vite-plugin-pwa:register-sw" src="/sbot/pwa/registerSW.js"></script></head>
1515
<body>
1616
<div id="app"></div>

docs/pwa/sw.js

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

packages/chat-ui/src/WebSocketTransport.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ export class WebSocketTransport implements IChatTransport {
3838

3939
connect(): void {
4040
if (this.ws?.readyState === WebSocket.CONNECTING || this.ws?.readyState === WebSocket.OPEN) return
41-
const proto = location.protocol === 'https:' ? 'wss:' : 'ws:'
42-
const host = this._baseUrl ? new URL(this._baseUrl).host : location.host
41+
const url = this._baseUrl ? new URL(this._baseUrl) : location
42+
const proto = url.protocol === 'https:' ? 'wss:' : 'ws:'
43+
const host = url.host
4344
const ws = new WebSocket(`${proto}//${host}/ws/chat`)
4445
this.ws = ws
4546
ws.onopen = () => {

packages/chat-ui/src/components/ServerPicker.vue

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<input v-model="editHost" placeholder="Host" />
1616
<label>Port</label>
1717
<input v-model.number="editPort" type="number" placeholder="Port" />
18+
<label class="checkbox-label"><input v-model="editSecure" type="checkbox" /> HTTPS</label>
1819
<label>{{ L.namePlaceholder }}</label>
1920
<input v-model="editName" :placeholder="L.namePlaceholder" />
2021
<div class="edit-actions">
@@ -45,6 +46,8 @@
4546
<label>Port</label>
4647
<input v-model.number="port" type="number" placeholder="5500" />
4748

49+
<label class="checkbox-label"><input v-model="secure" type="checkbox" /> HTTPS</label>
50+
4851
<label>{{ L.namePlaceholder }}</label>
4952
<input v-model="name" :placeholder="host ? `${host}:${port}` : ''" />
5053

@@ -64,39 +67,45 @@ const L = computed(() => resolveLabels(props.labels));
6467
const emit = defineEmits<{
6568
selectLocal: [];
6669
selectRemote: [index: number];
67-
addRemote: [name: string, host: string, port: number];
68-
updateRemote: [index: number, patch: { name?: string; host?: string; port?: number }];
70+
addRemote: [name: string, host: string, port: number, secure: boolean];
71+
updateRemote: [index: number, patch: { name?: string; host?: string; port?: number; secure?: boolean }];
6972
removeRemote: [index: number];
7073
}>();
7174
7275
const DEFAULT_PORT = 5500;
7376
77+
const defaultSecure = typeof location !== 'undefined' && location.protocol === 'https:';
78+
7479
const host = ref('');
7580
const port = ref(DEFAULT_PORT);
7681
const name = ref('');
82+
const secure = ref(defaultSecure);
7783
7884
const editingIndex = ref(-1);
7985
const editName = ref('');
8086
const editHost = ref('');
8187
const editPort = ref(DEFAULT_PORT);
88+
const editSecure = ref(defaultSecure);
8289
8390
function onAdd() {
8491
if (!host.value) return;
85-
emit('addRemote', name.value || `${host.value}:${port.value}`, host.value, port.value);
92+
emit('addRemote', name.value || `${host.value}:${port.value}`, host.value, port.value, secure.value);
8693
host.value = '';
8794
port.value = DEFAULT_PORT;
8895
name.value = '';
96+
secure.value = defaultSecure;
8997
}
9098
9199
function startEdit(i: number, r: RemoteEntry) {
92100
editingIndex.value = i;
93101
editName.value = r.name;
94102
editHost.value = r.host;
95103
editPort.value = r.port;
104+
editSecure.value = r.secure ?? defaultSecure;
96105
}
97106
98107
function onSaveEdit(i: number) {
99-
emit('updateRemote', i, { name: editName.value, host: editHost.value, port: editPort.value });
108+
emit('updateRemote', i, { name: editName.value, host: editHost.value, port: editPort.value, secure: editSecure.value });
100109
editingIndex.value = -1;
101110
}
102111
</script>
@@ -248,4 +257,13 @@ h3 {
248257
}
249258
.btn-add:hover { background: var(--chatui-btn-hover); }
250259
.btn-add:disabled { opacity: 0.5; cursor: default; }
260+
.checkbox-label {
261+
display: flex;
262+
align-items: center;
263+
gap: 4px;
264+
font-size: var(--chatui-font-size-sm);
265+
color: var(--chatui-fg-secondary);
266+
cursor: pointer;
267+
}
268+
.checkbox-label input[type="checkbox"] { margin: 0; }
251269
</style>

packages/chat-ui/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export interface RemoteEntry {
22
name: string;
33
host: string;
44
port: number;
5+
secure?: boolean;
56
}
67

78
export interface SessionItem {

packages/pwa/src/App.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,20 @@ function selectLocal() {
4141
4242
function selectRemote(index: number) {
4343
const r = remotes.value[index]
44-
if (r) selectServer(`http://${r.host}:${r.port}`)
44+
if (r) {
45+
const proto = r.secure ? 'https' : 'http'
46+
selectServer(`${proto}://${r.host}:${r.port}`)
47+
}
4548
}
4649
47-
function addRemote(name: string, host: string, port: number) {
48-
remotes.value.push({ name, host, port })
50+
function addRemote(name: string, host: string, port: number, secure: boolean) {
51+
remotes.value.push({ name, host, port, secure })
4952
saveRemotes(remotes.value)
50-
selectServer(`http://${host}:${port}`)
53+
const proto = secure ? 'https' : 'http'
54+
selectServer(`${proto}://${host}:${port}`)
5155
}
5256
53-
function updateRemote(index: number, patch: { name?: string; host?: string; port?: number }) {
57+
function updateRemote(index: number, patch: { name?: string; host?: string; port?: number; secure?: boolean }) {
5458
const r = remotes.value[index]
5559
if (r) {
5660
Object.assign(r, patch)

0 commit comments

Comments
 (0)