Skip to content

Commit a59ce52

Browse files
committed
miso-widgets js sources
1 parent 128836a commit a59ce52

File tree

8 files changed

+6721
-9
lines changed

8 files changed

+6721
-9
lines changed

ghcjs/miso-widgets/js/main.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { defineCustomElements } from "@ionic/pwa-elements/loader";
2+
import { WebviewPrint } from "capacitor-webview-print";
3+
import { Preferences } from "@capacitor/preferences";
4+
import { Clipboard } from "@capacitor/clipboard";
5+
import { Browser } from "@capacitor/browser";
6+
import { Share } from "@capacitor/share";
7+
import { Toast } from "@capacitor/toast";
8+
import { Capacitor } from "@capacitor/core";
9+
import { Html5Qrcode } from "html5-qrcode";
10+
import {
11+
CapacitorBarcodeScanner,
12+
CapacitorBarcodeScannerTypeHint,
13+
} from "@capacitor/barcode-scanner";
14+
15+
export async function printCurrentPage(name) {
16+
return await WebviewPrint.print({ name: name });
17+
}
18+
19+
export async function selectStorage(key) {
20+
const { value } = await Preferences.get({ key: key });
21+
return value;
22+
}
23+
24+
export async function insertStorage(key, value) {
25+
return await Preferences.set({ key: key, value: value });
26+
}
27+
28+
export async function selectClipboard() {
29+
const { value } = await Clipboard.read();
30+
return value;
31+
}
32+
33+
export async function openBrowserPage(url) {
34+
try {
35+
return await Browser.open({ url: url, windowName: "_blank" });
36+
} catch (e) {
37+
return window.open(url, "_blank").focus();
38+
}
39+
}
40+
41+
export async function shareText(text) {
42+
const { value } = await Share.canShare();
43+
if (value) {
44+
return await Share.share({ text: text });
45+
} else {
46+
return await navigator.clipboard.writeText(text);
47+
}
48+
}
49+
50+
export async function popupText(text) {
51+
return await Toast.show({ text: text });
52+
}
53+
54+
export async function selectBarcode() {
55+
if (!Capacitor.isNativePlatform()) {
56+
const devices = await Html5Qrcode.getCameras();
57+
if (!(devices && devices.length)) {
58+
throw new Error("Camera not found!");
59+
}
60+
}
61+
const { ScanResult } = await CapacitorBarcodeScanner.scanBarcode({
62+
hint: CapacitorBarcodeScannerTypeHint.ALL,
63+
});
64+
return ScanResult;
65+
}
66+
67+
defineCustomElements(window);

ghcjs/miso-widgets/js/main.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/*! Capacitor: https://capacitorjs.com/ - MIT License */

ghcjs/miso-widgets/miso-widgets.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ common pkg
9393

9494
if ((impl(ghcjs) || arch(javascript)) || os(wasi))
9595
build-depends: ghcjs-base
96+
js-sources: js/main.min.js
9697

9798
library
9899
import: pkg

0 commit comments

Comments
 (0)