From ec15039c7c66e8fb95c706a51b6f433e3b745bb2 Mon Sep 17 00:00:00 2001 From: Tricked <72335827+SkyBlockDev@users.noreply.github.com> Date: Fri, 15 Apr 2022 10:17:53 +0200 Subject: [PATCH] fix: not copying to clipboard --- .github/workflows/linux.sh | 10 +- .github/workflows/release-desktop.yml | 19 +--- Cargo.lock | 134 +++++++++++++++++++++++--- desktop/Cargo.toml | 13 ++- desktop/src/lib.rs | 10 +- desktop/src/main.rs | 6 +- desktop/src/util.rs | 22 ++++- 7 files changed, 169 insertions(+), 45 deletions(-) diff --git a/.github/workflows/linux.sh b/.github/workflows/linux.sh index 17de4f8..90da3b9 100755 --- a/.github/workflows/linux.sh +++ b/.github/workflows/linux.sh @@ -11,7 +11,7 @@ sudo mv appimagetool-x86_64.AppImage /bin/appimagetool cd desktop run() { - strip -s target/release/ascella + strip -s target/release/ascella-desktop echo installing cargo $1 cargo install cargo-$1 &>/dev/null echo Running cargo $1 @@ -26,8 +26,8 @@ run generate-rpm mkdir ../dist &>/dev/null mv PKGBUILD ../dist/ -mv ascella-*.AppImage ../dist/ -mv ascella-*.tar.gz ../dist/ -mv target/debian/ascella_*.deb ../dist/ -mv target/generate-rpm/ascella-*.rpm ../dist/ +mv ascella-desktop-*.AppImage ../dist/ +mv ascella-desktop-*.tar.gz ../dist/ +mv target/debian/ascella-desktop*.deb ../dist/ +mv target/generate-rpm/ascella-desktop-*.rpm ../dist/ cp LICENSE ../dist/ diff --git a/.github/workflows/release-desktop.yml b/.github/workflows/release-desktop.yml index c1573c1..01c87a7 100644 --- a/.github/workflows/release-desktop.yml +++ b/.github/workflows/release-desktop.yml @@ -6,7 +6,7 @@ on: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - BIN_NAME: desktop + BIN_NAME: ascella-desktop PROJECT_NAME: ascella REPO_NAME: Tricked-dev/ascella @@ -66,27 +66,18 @@ jobs: with: use-cross: ${{ matrix.cross }} command: build - args: --release --target ${{ matrix.target }} --bin desktop + args: --release --target ${{ matrix.target }} - name: Strip release binary (linux and macos) run: strip "./target/${{ matrix.target }}/release/$BIN_NAME" - # - run: mv ./target . - - name: make dist run: mkdir dist - name: Build archive if: matrix.build == 'x86_64-macos' shell: bash - run: | - - if [ "${{ matrix.os }}" = "windows-2019" ]; then - # cp target/wix/ascella* dist/ - cp "target/${{ matrix.target }}/release/$BIN_NAME.exe" "dist/" - else - cp "target/${{ matrix.target }}/release/$BIN_NAME" "dist/" - fi + run: cp "target/${{ matrix.target }}/release/$BIN_NAME" "dist/" - name: Build stuff if: matrix.build == 'x86_64-linux' run: chmod +x ./.github/workflows/linux.sh && ./.github/workflows/linux.sh @@ -125,8 +116,8 @@ jobs: set -ex mkdir dist - mv ascella-x86_64-linux/* dist/ - tar -czvf dist/ascella-x86_64-macos.tar.xz ascella-x86_64-macos + mv ascella-desktop-x86_64-linux/* dist/ + tar -czvf dist/ascella-desktop-x86_64-macos.tar.xz ascella-desktop-x86_64-macos - name: Upload binaries to release uses: svenstaro/upload-release-action@v2 diff --git a/Cargo.lock b/Cargo.lock index a669f02..fdd23a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -329,12 +329,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" [[package]] -name = "ascella" -version = "0.4.4" +name = "ascella-desktop" +version = "0.4.5" dependencies = [ "chrono", "clap", "clipboard", + "clipboard-ext", "home", "iced", "itertools", @@ -349,6 +350,7 @@ dependencies = [ "toml", "winapi 0.3.9", "winit 0.26.1", + "wl-clipboard-rs", ] [[package]] @@ -588,6 +590,12 @@ dependencies = [ "utf8-width", ] +[[package]] +name = "bytecount" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72feb31ffc86498dacdbd0fcebb56138e7177a8cc5cea4516031d15ae85a742e" + [[package]] name = "bytemuck" version = "1.9.1" @@ -764,6 +772,18 @@ dependencies = [ "x11-clipboard", ] +[[package]] +name = "clipboard-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac0b9a9fdf4e6100bfcdc6587c9c26a6a1d1d8247e74684c18a113d635d3dc78" +dependencies = [ + "clipboard", + "libc", + "which 3.1.1", + "x11-clipboard", +] + [[package]] name = "clipboard-win" version = "2.2.0" @@ -1257,6 +1277,17 @@ dependencies = [ "parking_lot 0.12.0", ] +[[package]] +name = "derive-new" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3418329ca0ad70234b9735dc4ceed10af4df60eff9c8e7b06cb5e520d92c3535" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "derive_more" version = "0.99.17" @@ -1500,6 +1531,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" +[[package]] +name = "fixedbitset" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "279fb028e20b3c4c320317955b77c5e0c9701f05a1d309905d6fc702cdc5053e" + [[package]] name = "flate2" version = "1.0.22" @@ -2646,7 +2683,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" dependencies = [ "scopeguard", - "serde", ] [[package]] @@ -2657,6 +2693,7 @@ checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" dependencies = [ "autocfg 1.1.0", "scopeguard", + "serde", ] [[package]] @@ -2934,7 +2971,7 @@ dependencies = [ "raw-window-handle 0.4.3", "thiserror", "wfd", - "which", + "which 4.2.5", "winapi 0.3.9", ] @@ -3084,6 +3121,19 @@ dependencies = [ "memoffset 0.6.5", ] +[[package]] +name = "nix" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6" +dependencies = [ + "bitflags", + "cc", + "cfg-if 1.0.0", + "libc", + "memoffset 0.6.5", +] + [[package]] name = "no-std-compat" version = "0.4.1" @@ -3314,6 +3364,16 @@ dependencies = [ "hashbrown 0.9.1", ] +[[package]] +name = "os_pipe" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c92f2b54f081d635c77e7120862d48db8e91f7f21cef23ab1b4fe9971c59f55" +dependencies = [ + "libc", + "winapi 0.3.9", +] + [[package]] name = "os_str_bytes" version = "6.0.0" @@ -3352,14 +3412,14 @@ dependencies = [ "paperclip-actix", "paperclip-core", "paperclip-macros", - "parking_lot 0.10.2", - "semver 0.9.0", + "parking_lot 0.12.0", + "semver 0.11.0", "serde", "serde_derive", "serde_json", "serde_yaml", "thiserror", - "url 1.7.2", + "url 2.2.2", ] [[package]] @@ -3373,7 +3433,7 @@ dependencies = [ "once_cell", "paperclip-core", "paperclip-macros", - "parking_lot 0.10.2", + "parking_lot 0.12.0", "serde_json", ] @@ -3387,7 +3447,7 @@ dependencies = [ "mime", "once_cell", "paperclip-macros", - "parking_lot 0.10.2", + "parking_lot 0.12.0", "pin-project", "regex", "serde", @@ -3563,7 +3623,17 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7" dependencies = [ - "fixedbitset", + "fixedbitset 0.2.0", + "indexmap", +] + +[[package]] +name = "petgraph" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a13a2fa9d0b63e5f22328828741e523766fff0ee9e779316902290dff3f824f" +dependencies = [ + "fixedbitset 0.4.1", "indexmap", ] @@ -5209,7 +5279,21 @@ dependencies = [ "lazy_static", "nom 3.2.1", "parking_lot 0.10.2", - "petgraph", + "petgraph 0.5.1", +] + +[[package]] +name = "tree_magic_mini" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91adfd0607cacf6e4babdb870e9bec4037c1c4b151cfd279ccefc5e0c7feaa6d" +dependencies = [ + "bytecount", + "fnv", + "lazy_static", + "nom 7.1.1", + "once_cell", + "petgraph 0.6.0", ] [[package]] @@ -5958,6 +6042,16 @@ dependencies = [ "wgpu", ] +[[package]] +name = "which" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" +dependencies = [ + "failure", + "libc", +] + [[package]] name = "which" version = "4.2.5" @@ -6177,6 +6271,24 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "wl-clipboard-rs" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be5ca3d1bf382a9baf6ef08b635e8f417c83a8a459bc88b4179a663abd8acd8b" +dependencies = [ + "derive-new", + "derive_more", + "libc", + "log", + "nix 0.23.1", + "os_pipe", + "tempfile", + "tree_magic_mini", + "wayland-client 0.29.4", + "wayland-protocols", +] + [[package]] name = "ws2_32-sys" version = "0.2.1" diff --git a/desktop/Cargo.toml b/desktop/Cargo.toml index 3839fb8..da4cf03 100644 --- a/desktop/Cargo.toml +++ b/desktop/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "ascella" -version = "0.4.4" +name = "ascella-desktop" +version = "0.4.5" authors = ["Tricked-dev"] edition = "2021" homepage = "https://docs.ascella.host/ascella-desktop" @@ -8,12 +8,14 @@ license = "AGPL-3.0" readme = "README.md" repository = "https://github.com/Tricked-dev/ascella" description = "Ascella desktop app uploader" + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] chrono = "0.4.19" clap = { version = "3.0.5", features = ["cargo", "color"] } clipboard = "0.5.0" +clipboard-ext = "0.2.0" home = "0.5.3" iced = { git = "https://github.com/iced-rs/iced", rev = "4db0f4a570a1fb3398062c78770c542d9efb8a64", features = ["tokio", "debug", "glow"] } itertools = "0.10.3" @@ -26,6 +28,7 @@ serde_json = "1.0.74" tokio = { version = "1.15.0", features = ["sync"] } toml = "0.5.8" winit = "0.26.1" +wl-clipboard-rs = "0.6.0" [target.'cfg(unix)'.dependencies] openssl = { version = "0.10.38", features = ["vendored"] } @@ -35,12 +38,12 @@ libc = "0.2.112" winapi = "0.3.9" [[bin]] -name = "desktop" +name = "ascella-desktop" path = "src/main.rs" [package.metadata.generate-rpm] assets = [ - { source = "target/release/desktop", dest = "/usr/bin/ascella", mode = "0755" }, + { source = "target/release/ascella-desktop", dest = "/usr/bin/ascella", mode = "0755" }, { source = "LICENSE", dest = "/usr/share/doc/ascella/LICENSE", doc = true, mode = "0644" }, { source = "README.md", dest = "/usr/share/doc/ascella/README.md", doc = true, mode = "0644" }, ] @@ -54,7 +57,7 @@ depends = "$auto" section = "utility" priority = "optional" assets = [ - ["target/release/desktop", "usr/bin/", "755"], + ["target/release/ascella-desktop", "usr/bin/ascella", "755"], ["LICENSE", "usr/share/doc/ascella/LICENSE", "644"], ["README.md", "usr/share/doc/ascella/README.md", "644"], ] diff --git a/desktop/src/lib.rs b/desktop/src/lib.rs index 2fe6a3f..badf784 100644 --- a/desktop/src/lib.rs +++ b/desktop/src/lib.rs @@ -133,14 +133,18 @@ pub fn screenshot_full(file: String) { fn flameshot(option: ScreenshotKind, file: String) { let output = match option { - ScreenshotKind::Area => Command::new("flameshot").args(&["gui", "-p", &file]).stdout(Stdio::piped()).output().expect("flameshot did not launch"), + ScreenshotKind::Area => Command::new("flameshot") + .args(&["gui", "-c", "-p", &file]) + .stdout(Stdio::piped()) + .output() + .expect("flameshot did not launch"), ScreenshotKind::Window => Command::new("flameshot") - .args(&["screen", "-p", &file]) + .args(&["screen", "-c", "-p", &file]) .stdout(Stdio::piped()) .output() .expect("flameshot did not launch"), ScreenshotKind::Full => Command::new("flameshot") - .args(&["full", "-p", &file]) + .args(&["full", "-c", "-p", &file]) .stdout(Stdio::piped()) .output() .expect("flameshot did not launch"), diff --git a/desktop/src/main.rs b/desktop/src/main.rs index 85efa65..63ad2a9 100644 --- a/desktop/src/main.rs +++ b/desktop/src/main.rs @@ -4,9 +4,9 @@ use std::{fs, thread, time}; use clap::{crate_authors, crate_description, crate_name, crate_version, App, Arg, ArgMatches}; use iced::{Application, Settings}; -use ascella::ui::app::AscellaDesktop; -use ascella::util::{screenshot, update_config, upload}; -use ascella::ScreenshotKind; +use ascella_desktop::ui::app::AscellaDesktop; +use ascella_desktop::util::{screenshot, update_config, upload}; +use ascella_desktop::ScreenshotKind; pub fn main() -> iced::Result { let app = App::new(crate_name!()) diff --git a/desktop/src/util.rs b/desktop/src/util.rs index 2e5e379..3c5c81c 100644 --- a/desktop/src/util.rs +++ b/desktop/src/util.rs @@ -4,6 +4,8 @@ use std::process::Command; use crate::{take_ss, ScreenshotKind}; use clipboard::{ClipboardContext, ClipboardProvider}; +use clipboard_ext::prelude::*; +use clipboard_ext::x11_bin::ClipboardContext as LinuxContext; use home::home_dir; use native_dialog::{MessageDialog, MessageType}; use reqwest::header::{HeaderMap, HeaderValue}; @@ -130,22 +132,34 @@ pub fn upload<P: AsRef<Path>>(path: P) -> Result<String, Error> { let r: Value = serde_json::from_str(&text).unwrap(); let url = r["url"].as_str().expect("Invalid image type"); - let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap(); println!("{url}"); - ctx.set_contents(url.to_owned()).unwrap(); copy(url.clone().to_owned()); Ok(url.to_owned()) } fn copy(t: String) { - //I hate rust + let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap(); + + ctx.set_contents(t.to_owned()).unwrap(); + + // Linux workarounds #[cfg(target_os = "linux")] { use std::io::prelude::*; - use std::process::Command; use std::process::Stdio; + use wl_clipboard_rs::paste::{get_contents, ClipboardType, MimeType, Seat}; + + let mut ctx = LinuxContext::new().unwrap(); + ctx.set_contents(t.clone()).unwrap(); + + let result = get_contents(ClipboardType::Regular, Seat::Unspecified, MimeType::Text); + if let Ok((mut pipe, _)) = result { + let mut contents = vec![]; + pipe.read_to_end(&mut contents).expect("Failed to read pipe"); + } + let child = Command::new("xclip").arg("-selection").arg("clipboard").stdin(Stdio::piped()).stdout(Stdio::piped()).spawn(); if let Ok(mut child) = child { {