From 3aba5eaf3973ca823470b89f3204a0f562656179 Mon Sep 17 00:00:00 2001 From: Salem Yaslem Date: Mon, 8 Mar 2021 14:02:32 +0300 Subject: [PATCH] open video in snap --- snap/snapcraft.yaml | 1 - src/ffmpeg_interface.rs | 66 ++++++++++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 7f3bb02..1144d9d 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -21,7 +21,6 @@ parts: stage-packages: - libappindicator3-1 - x11-utils - - xdg-utils build-packages: - libappindicator3-dev - clang diff --git a/src/ffmpeg_interface.rs b/src/ffmpeg_interface.rs index d094625..a956e96 100644 --- a/src/ffmpeg_interface.rs +++ b/src/ffmpeg_interface.rs @@ -1,11 +1,7 @@ extern crate subprocess; use chrono::prelude::*; use gtk::prelude::*; -use gtk::{ - CheckButton, ComboBoxText, Entry, FileChooser, - SpinButton, Dialog, ProgressBar, - Window -}; +use gtk::{CheckButton, ComboBoxText, Dialog, Entry, FileChooser, ProgressBar, SpinButton, Window}; use std::collections::HashMap; use std::path::PathBuf; use std::process::Command; @@ -27,8 +23,9 @@ impl ProgressWidget { pub fn new(window: &Window) -> ProgressWidget { ProgressWidget { dialog: Dialog::new(), - progress: ProgressBar::new() - }.init(&window) + progress: ProgressBar::new(), + } + .init(&window) } pub fn init(&self, window: &Window) -> ProgressWidget { @@ -97,7 +94,7 @@ pub struct Ffmpeg { pub process_id: Option, pub saved_filename: Option, pub unbound: Option>, - pub progress_widget: ProgressWidget + pub progress_widget: ProgressWidget, } impl Ffmpeg { @@ -224,7 +221,9 @@ impl Ffmpeg { &self.progress_widget.show(); // kill the process to stop recording if self.process_id.is_some() { - &self.progress_widget.set_progress("Stop Recording".to_string(), 1, 5); + &self + .progress_widget + .set_progress("Stop Recording".to_string(), 1, 5); Command::new("kill") .arg(format!("{}", self.process_id.unwrap())) .output() @@ -246,7 +245,11 @@ impl Ffmpeg { ) .exists(); if self.unbound.is_some() { - &self.progress_widget.set_progress("Stop Wayland Video Recording".to_string(), 2, 5); + &self.progress_widget.set_progress( + "Stop Wayland Video Recording".to_string(), + 2, + 5, + ); self.unbound .as_ref() .unwrap() @@ -279,7 +282,11 @@ impl Ffmpeg { .unwrap(); if is_audio_record { - &self.progress_widget.set_progress("Stop Wayland Audio Recording".to_string(), 3, 5); + &self.progress_widget.set_progress( + "Stop Wayland Audio Recording".to_string(), + 3, + 5, + ); // merge audio with video let mut ffmpeg_audio_merge_command = Command::new("ffmpeg"); @@ -315,7 +322,11 @@ impl Ffmpeg { } } } else if is_audio_record { - &self.progress_widget.set_progress("Convert Audio to choosen format".to_string(), 3, 5); + &self.progress_widget.set_progress( + "Convert Audio to choosen format".to_string(), + 3, + 5, + ); println!("convert audio"); Command::new("ffmpeg") .arg("-f") @@ -338,11 +349,17 @@ impl Ffmpeg { // execute command after finish recording if !(self.command.get_text().trim() == "") { - &self.progress_widget.set_progress("execute custom command after finish".to_string(), 4, 5); + &self.progress_widget.set_progress( + "execute custom command after finish".to_string(), + 4, + 5, + ); Exec::shell(self.command.get_text().trim()).popen().unwrap(); } - &self.progress_widget.set_progress("Finish".to_string(), 5, 5); + &self + .progress_widget + .set_progress("Finish".to_string(), 5, 5); &self.progress_widget.hide(); } @@ -385,10 +402,19 @@ impl Ffmpeg { pub fn play_record(self) { if self.saved_filename.is_some() { - Command::new("xdg-open") - .arg(self.saved_filename.unwrap()) - .spawn() - .unwrap(); + if is_snap() { + // open the video using snapctrl for snap package + Command::new("snapctl") + .arg("user-open") + .arg(self.saved_filename.unwrap()) + .spawn() + .unwrap(); + } else { + Command::new("xdg-open") + .arg(self.saved_filename.unwrap()) + .spawn() + .unwrap(); + } } } } @@ -398,3 +424,7 @@ fn is_wayland() -> bool { .unwrap() .eq_ignore_ascii_case("wayland") } + +fn is_snap() -> bool { + std::env::var("SNAP").unwrap_or(String::new()).len() > 0 +}