Skip to content

Commit 82a4958

Browse files
committed
feat(wifi-qr-code): Allow to copy wifi connection string. Fixes CorentinTh#1438
1 parent 08d977b commit 82a4958

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/tools/wifi-qr-code-generator/useQRCode.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export function useWifiQRCode({
110110
color: { background, foreground },
111111
options,
112112
}: IWifiQRCodeOptions) {
113+
const text = ref('');
113114
const qrcode = ref('');
114115
const encryption = ref<WifiEncryption>('WPA');
115116

@@ -118,7 +119,7 @@ export function useWifiQRCode({
118119
async () => {
119120
// @see https://github.com/zxing/zxing/wiki/Barcode-Contents#wi-fi-network-config-android-ios-11
120121
// This is the full spec, there's quite a bit of logic to generate the string embeddedin the QR code.
121-
const text = getQrCodeText({
122+
text.value = getQrCodeText({
122123
ssid: get(ssid),
123124
password: get(password),
124125
encryption: get(encryption),
@@ -128,8 +129,8 @@ export function useWifiQRCode({
128129
eapIdentity: get(eapIdentity),
129130
eapPhase2Method: get(eapPhase2Method),
130131
});
131-
if (text) {
132-
qrcode.value = await QRCode.toDataURL(get(text).trim(), {
132+
if (text.value) {
133+
qrcode.value = await QRCode.toDataURL(get(text.value).trim(), {
133134
color: {
134135
dark: get(foreground),
135136
light: get(background),
@@ -142,5 +143,5 @@ export function useWifiQRCode({
142143
},
143144
{ immediate: true },
144145
);
145-
return { qrcode, encryption };
146+
return { qrcode, text, encryption };
146147
}

src/tools/wifi-qr-code-generator/wifi-qr-code-generator.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
useWifiQRCode,
66
} from './useQRCode';
77
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
8+
import { useCopy } from '@/composable/copy';
89
910
const foreground = ref('#000000ff');
1011
const background = ref('#ffffffff');
@@ -17,7 +18,7 @@ const eapAnonymous = ref(false);
1718
const eapIdentity = ref();
1819
const eapPhase2Method = ref();
1920
20-
const { qrcode, encryption } = useWifiQRCode({
21+
const { qrcode, text, encryption } = useWifiQRCode({
2122
ssid,
2223
password,
2324
eapMethod,
@@ -33,6 +34,8 @@ const { qrcode, encryption } = useWifiQRCode({
3334
});
3435
3536
const { download } = useDownloadFileFromBase64({ source: qrcode, filename: 'qr-code.png' });
37+
const { copy } = useCopy({ source: text, text: 'Copied to the clipboard' });
38+
3639
</script>
3740

3841
<template>
@@ -148,6 +151,13 @@ const { download } = useDownloadFileFromBase64({ source: qrcode, filename: 'qr-c
148151
</c-button>
149152
</div>
150153
</div>
154+
<div v-if="qrcode">
155+
<div flex flex-col items-center gap-3>
156+
<c-button @click="copy()">
157+
Copy connection string
158+
</c-button>
159+
</div>
160+
</div>
151161
</div>
152162
</c-card>
153163
</template>

0 commit comments

Comments
 (0)