Просмотр исходного кода

wallet: add missing file for clipboard

darkfi 1 год назад
Родитель
Сommit
ce080840f4
1 измененных файлов с 47 добавлено и 0 удалено
  1. 47 0
      bin/darkwallet/src/util/clip.rs

+ 47 - 0
bin/darkwallet/src/util/clip.rs

@@ -0,0 +1,47 @@
+/* This file is part of DarkFi (https://dark.fi)
+ *
+ * Copyright (C) 2020-2024 Dyne.org foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+pub struct Clipboard {
+    #[cfg(not(target_os = "android"))]
+    clip: arboard::Clipboard,
+}
+
+impl Clipboard {
+    pub fn new() -> Self {
+        Self {
+            #[cfg(not(target_os = "android"))]
+            clip: arboard::Clipboard::new().unwrap(),
+        }
+    }
+
+    pub fn get(&mut self) -> Option<String> {
+        #[cfg(target_os = "android")]
+        return miniquad::window::clipboard_get();
+
+        #[cfg(not(target_os = "android"))]
+        return self.clip.get_text().ok();
+    }
+
+    pub fn set(&mut self, data: &str) {
+        #[cfg(target_os = "android")]
+        return miniquad::window::clipboard_set(data);
+
+        #[cfg(not(target_os = "android"))]
+        return self.clip.set_text(data).unwrap();
+    }
+}