mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2026-01-31 12:04:23 +01:00
Fix clipboard for android
This commit is contained in:
committed by
Tony Giorgio
parent
d951fceaca
commit
de6cfa185c
@@ -10,6 +10,7 @@ android {
|
||||
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
|
||||
dependencies {
|
||||
implementation project(':capacitor-camera')
|
||||
implementation project(':capacitor-clipboard')
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -43,4 +43,6 @@
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-feature android:name="android.hardware.camera" />
|
||||
<uses-permission android:name="android.permission.READ_CLIPBOARD" />
|
||||
<uses-permission android:name="android.permission.WRITE_CLIPBOARD" />
|
||||
</manifest>
|
||||
|
||||
@@ -4,3 +4,6 @@ project(':capacitor-android').projectDir = new File('../node_modules/.pnpm/@capa
|
||||
|
||||
include ':capacitor-camera'
|
||||
project(':capacitor-camera').projectDir = new File('../node_modules/.pnpm/@capacitor+camera@5.0.6_@capacitor+core@5.2.1/node_modules/@capacitor/camera/android')
|
||||
|
||||
include ':capacitor-clipboard'
|
||||
project(':capacitor-clipboard').projectDir = new File('../node_modules/.pnpm/@capacitor+clipboard@5.0.6_@capacitor+core@5.2.1/node_modules/@capacitor/clipboard/android')
|
||||
|
||||
17
insertHead.js
Normal file
17
insertHead.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { readFile, writeFile } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
|
||||
const insertHeadTag = async () => {
|
||||
const filePath = join(process.cwd(), 'dist', 'public', 'index.html');
|
||||
try {
|
||||
let data = await readFile(filePath, 'utf8');
|
||||
const lines = data.split('\n');
|
||||
lines.splice(2, 0, '<head></head>');
|
||||
data = lines.join('\n');
|
||||
await writeFile(filePath, data);
|
||||
} catch (err) {
|
||||
console.error(`Error: ${err}`);
|
||||
}
|
||||
};
|
||||
|
||||
insertHeadTag();
|
||||
@@ -6,7 +6,7 @@
|
||||
"scripts": {
|
||||
"dev": "solid-start dev",
|
||||
"host": "solid-start dev --host",
|
||||
"build": "solid-start build",
|
||||
"build": "solid-start build && node insertHead.js",
|
||||
"start": "solid-start start",
|
||||
"lint": "eslint src --ext .ts,.tsx,.js",
|
||||
"format": "npx prettier --write \"src/**/*.{ts,tsx,js,jsx,json,css,scss,md}\""
|
||||
@@ -39,6 +39,7 @@
|
||||
"dependencies": {
|
||||
"@capacitor/android": "^5.2.1",
|
||||
"@capacitor/camera": "^5.0.6",
|
||||
"@capacitor/clipboard": "^5.0.6",
|
||||
"@capacitor/core": "^5.2.1",
|
||||
"@kobalte/core": "^0.9.8",
|
||||
"@kobalte/tailwindcss": "^0.5.0",
|
||||
|
||||
11
pnpm-lock.yaml
generated
11
pnpm-lock.yaml
generated
@@ -7,6 +7,9 @@ dependencies:
|
||||
'@capacitor/camera':
|
||||
specifier: ^5.0.6
|
||||
version: 5.0.6(@capacitor/core@5.2.1)
|
||||
'@capacitor/clipboard':
|
||||
specifier: ^5.0.6
|
||||
version: 5.0.6(@capacitor/core@5.2.1)
|
||||
'@capacitor/core':
|
||||
specifier: ^5.2.1
|
||||
version: 5.2.1
|
||||
@@ -1407,6 +1410,14 @@ packages:
|
||||
- supports-color
|
||||
dev: true
|
||||
|
||||
/@capacitor/clipboard@5.0.6(@capacitor/core@5.2.1):
|
||||
resolution: {integrity: sha512-VsokRAn+0HVWj6riSRdspczEfqFoHbrhS/XRhGoEPsj0uvYPSufy0Kb2dpnSqkeeElhh2Jvn8jmVAzII2XeR9w==}
|
||||
peerDependencies:
|
||||
'@capacitor/core': ^5.0.0
|
||||
dependencies:
|
||||
'@capacitor/core': 5.2.1
|
||||
dev: false
|
||||
|
||||
/@capacitor/core@5.2.1:
|
||||
resolution: {integrity: sha512-v7nzTQZj9l99Sp0v8C7Zq8QX6Cg5ljq7ASneWk/Hc5nBR5LOj/k3a+yEx/RoclWtkxJfs89Y5k+KJTFFQ6cLoA==}
|
||||
dependencies:
|
||||
|
||||
@@ -5,6 +5,8 @@ import { Button } from "~/components/layout";
|
||||
import { showToast } from "~/components/Toaster";
|
||||
import { useMegaStore } from "~/state/megaStore";
|
||||
import { toParsedParams } from "~/logic/waila";
|
||||
import { Clipboard } from "@capacitor/clipboard";
|
||||
import { Capacitor } from "@capacitor/core";
|
||||
|
||||
export default function Scanner() {
|
||||
const [state, actions] = useMegaStore();
|
||||
@@ -22,7 +24,17 @@ export default function Scanner() {
|
||||
|
||||
async function handlePaste() {
|
||||
try {
|
||||
const text = await navigator.clipboard.readText();
|
||||
let text;
|
||||
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
const { value } = await Clipboard.read({
|
||||
type: "string"
|
||||
});
|
||||
text = value;
|
||||
} else {
|
||||
text = await navigator.clipboard.readText();
|
||||
}
|
||||
|
||||
const trimText = text.trim();
|
||||
setScanResult(trimText);
|
||||
} catch (e) {
|
||||
|
||||
@@ -45,6 +45,8 @@ import { InfoBox } from "~/components/InfoBox";
|
||||
import { useI18n } from "~/i18n/context";
|
||||
import { ParsedParams, toParsedParams } from "~/logic/waila";
|
||||
import { FeesModal } from "~/components/MoreInfoModal";
|
||||
import { Clipboard } from "@capacitor/clipboard";
|
||||
import { Capacitor } from "@capacitor/core";
|
||||
|
||||
export type SendSource = "lightning" | "onchain";
|
||||
|
||||
@@ -384,11 +386,21 @@ export default function Send() {
|
||||
}
|
||||
|
||||
async function handlePaste() {
|
||||
if (!navigator.clipboard.readText)
|
||||
return showToast(new Error("Clipboard not supported"));
|
||||
|
||||
try {
|
||||
const text = await navigator.clipboard.readText();
|
||||
let text;
|
||||
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
const { value } = await Clipboard.read({
|
||||
type: "string"
|
||||
});
|
||||
text = value;
|
||||
} else {
|
||||
if (!navigator.clipboard.readText) {
|
||||
return showToast(new Error("Clipboard not supported"));
|
||||
}
|
||||
text = await navigator.clipboard.readText();
|
||||
}
|
||||
|
||||
const trimText = text.trim();
|
||||
setFieldDestination(trimText);
|
||||
parsePaste(trimText);
|
||||
|
||||
@@ -27,6 +27,8 @@ import { ConfirmDialog } from "~/components/Dialog";
|
||||
import { MutinyWallet } from "@mutinywallet/mutiny-wasm";
|
||||
import { WORDS_EN } from "~/utils/words";
|
||||
import { InfoBox } from "~/components/InfoBox";
|
||||
import { Clipboard } from "@capacitor/clipboard";
|
||||
import { Capacitor } from "@capacitor/core";
|
||||
|
||||
type SeedWordsForm = {
|
||||
words: string[];
|
||||
@@ -91,17 +93,27 @@ function TwelveWordsEntry() {
|
||||
});
|
||||
|
||||
async function handlePaste() {
|
||||
if (!navigator.clipboard.readText)
|
||||
return showToast(new Error("Clipboard not supported"));
|
||||
|
||||
try {
|
||||
const text = await navigator.clipboard.readText();
|
||||
let text;
|
||||
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
const { value } = await Clipboard.read({
|
||||
type: "string"
|
||||
});
|
||||
text = value;
|
||||
} else {
|
||||
if (!navigator.clipboard.readText) {
|
||||
return showToast(new Error("Clipboard not supported"));
|
||||
}
|
||||
text = await navigator.clipboard.readText();
|
||||
}
|
||||
|
||||
// split words on space or newline
|
||||
const words = text.split(/[\s\n]+/);
|
||||
|
||||
if (words.length !== 12)
|
||||
if (words.length !== 12) {
|
||||
return showToast(new Error("Wrong number of words"));
|
||||
}
|
||||
|
||||
setValues(seedWordsForm, "words", words);
|
||||
validate(seedWordsForm);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Thanks you https://soorria.com/snippets/use-copy-solidjs
|
||||
import type { Accessor } from "solid-js";
|
||||
import { createSignal } from "solid-js";
|
||||
import { Clipboard } from "@capacitor/clipboard";
|
||||
import { Capacitor } from "@capacitor/core";
|
||||
export type UseCopyProps = {
|
||||
copiedTimeout?: number;
|
||||
};
|
||||
@@ -12,7 +14,13 @@ export const useCopy = ({ copiedTimeout = 2000 }: UseCopyProps = {}): [
|
||||
const [copied, setCopied] = createSignal(false);
|
||||
let timeout: number;
|
||||
const copy: CopyFn = async (text) => {
|
||||
await navigator.clipboard.writeText(text);
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
await Clipboard.write({
|
||||
string: text
|
||||
});
|
||||
} else {
|
||||
await navigator.clipboard.writeText(text);
|
||||
}
|
||||
setCopied(true);
|
||||
if (timeout) clearTimeout(timeout);
|
||||
timeout = setTimeout(() => setCopied(false), copiedTimeout);
|
||||
|
||||
Reference in New Issue
Block a user