diff --git a/frontend/src/components/SettingsForm/index.tsx b/frontend/src/components/SettingsForm/index.tsx index 9c4fbb07..52341609 100644 --- a/frontend/src/components/SettingsForm/index.tsx +++ b/frontend/src/components/SettingsForm/index.tsx @@ -36,7 +36,7 @@ interface SettingsFormProps { } const SettingsForm = ({ dense = false }: SettingsFormProps): React.JSX.Element => { - const { settings, setSettings, client } = useContext(AppContext); + const { settings, setSettings } = useContext(AppContext); const theme = useTheme(); const { t } = useTranslation(); const fontSizes = [ @@ -241,7 +241,7 @@ const SettingsForm = ({ dense = false }: SettingsFormProps): React.JSX.Element = - {client === 'mobile' && ( + {window.navigator.userAgent.includes('robosats') && ( diff --git a/frontend/src/services/Android/index.ts b/frontend/src/services/Android/index.ts index a8abb1af..2cc2cdd1 100644 --- a/frontend/src/services/Android/index.ts +++ b/frontend/src/services/Android/index.ts @@ -9,6 +9,7 @@ declare global { interface AndroidAppRobosats { generateRoboname: (uuid: string, initialString: string) => void; generateRobohash: (uuid: string, initialString: string) => void; + copyToClipboard: (value: string) => void; } class AndroidRobosats { diff --git a/frontend/src/services/System/SystemAndroidClient/index.ts b/frontend/src/services/System/SystemAndroidClient/index.ts index b0d7410b..c1ca3303 100644 --- a/frontend/src/services/System/SystemAndroidClient/index.ts +++ b/frontend/src/services/System/SystemAndroidClient/index.ts @@ -8,8 +8,10 @@ class SystemAndroidClient implements SystemClient { public loading = false; - // TODO - public copyToClipboard: (value: string) => void = () => {}; + // Clipboard + public copyToClipboard: (value: string) => void = (value) => { + window.AndroidAppRobosats?.copyToClipboard(value ?? ''); + }; // Cookies public getCookie: (key: string) => string = (key) => { diff --git a/mobile_new/app/src/main/java/com/robosats/WebAppInterface.kt b/mobile_new/app/src/main/java/com/robosats/WebAppInterface.kt index ee913863..9e6c6f1a 100644 --- a/mobile_new/app/src/main/java/com/robosats/WebAppInterface.kt +++ b/mobile_new/app/src/main/java/com/robosats/WebAppInterface.kt @@ -61,4 +61,22 @@ class WebAppInterface(private val context: Context, private val webView: WebView } } } + + @JavascriptInterface + fun copyToClipboard(message: String) { + try { + val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as android.content.ClipboardManager + val clip = android.content.ClipData.newPlainText("RoboSats Data", message) + clipboard.setPrimaryClip(clip) + + // Show a toast notification + Toast.makeText(context, "Copied to clipboard", Toast.LENGTH_SHORT).show() + + // Log the action + Log.d(TAG, "Text copied to clipboard") + } catch (e: Exception) { + Log.e(TAG, "Error copying to clipboard", e) + Toast.makeText(context, "Failed to copy to clipboard", Toast.LENGTH_SHORT).show() + } + } }