Clipboard

This commit is contained in:
koalasat
2025-07-16 13:04:47 +02:00
parent 8bf57a5b7e
commit bdd1a9b624
4 changed files with 25 additions and 4 deletions

View File

@ -36,7 +36,7 @@ interface SettingsFormProps {
}
const SettingsForm = ({ dense = false }: SettingsFormProps): React.JSX.Element => {
const { settings, setSettings, client } = useContext<UseAppStoreType>(AppContext);
const { settings, setSettings } = useContext<UseAppStoreType>(AppContext);
const theme = useTheme();
const { t } = useTranslation();
const fontSizes = [
@ -241,7 +241,7 @@ const SettingsForm = ({ dense = false }: SettingsFormProps): React.JSX.Element =
</ToggleButtonGroup>
</ListItem>
{client === 'mobile' && (
{window.navigator.userAgent.includes('robosats') && (
<ListItem>
<ListItemIcon>
<TorIcon />

View File

@ -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 {

View File

@ -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) => {

View File

@ -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()
}
}
}