Skip to content

Commit

Permalink
use world's scuffed workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
couleurm committed Apr 30, 2024
1 parent 5828540 commit 8e6ec21
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 52 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ indexmap = { version = "2.2.6", features = ["serde"] }
# gui-related
eframe = "0.27.2" # egui 'frame'work
env_logger = "0.11.3"
winit = "0.29.15" # load icon
winit = "0.30.0" # load icon
image = "0.25.1" # load icon
copypasta = "0.10.1" # copy to clipboard

winapi = "0.3.9"
windows = { version = "0.56.0", features = ["Win32", "Win32_UI", "Win32_UI_WindowsAndMessaging"]}

[build-dependencies]
winres = "0.1" # give the exe an icon
cc = "1.0.79" # for /src/windows.c
Expand Down
58 changes: 38 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
extern crate serde_derive;

use recipe::Recipe;
use winapi::um::{wincon::GetConsoleWindow, winuser::ShowWindow};
use render::vspipe_render;

#[cfg(windows)]
use winapi::um::{
wincon::GetConsoleWindow,
winuser::ShowWindow,
};

mod cli;
mod cmd;
Expand Down Expand Up @@ -56,10 +62,12 @@ fn main() {
recipe.get_bool("miscellaneous", "always verbose"),
);

#[cfg(windows)]
let is_conhost: bool = (env::var("WT_SESSION").is_err() && env::var("ALACRITY_LOG").is_err())
|| env::var("NO_SMOOTHIE_WIN32").is_ok();
// user is neither running Windows Terminal and alacritty, OR has NO_SMOOTHIE_WIN32 defined

#[cfg(windows)]
if args.tui
&& is_conhost
&& cfg!(target_os = "windows")
Expand All @@ -71,6 +79,7 @@ fn main() {

let payloads: Vec<Payload>;
let (recipe, mut args) = if args.input.is_empty() && !args.tui {
#[cfg(windows)]
let hwnd: Option<*mut winapi::shared::windef::HWND__> = if cfg!(windows) {
unsafe {
let hwnd = GetConsoleWindow();
Expand All @@ -84,34 +93,43 @@ fn main() {
None
};

if let Some(hwnd) = hwnd {
unsafe {
ShowWindow(hwnd, winapi::um::winuser::SW_MINIMIZE);
let env_var = std::env::var("SM_NOWINDOWINTERACT");
let interact: bool = env_var.is_ok() && env_var.unwrap() == "1".to_owned();

#[cfg(windows)]
if interact {
if let Some(hwnd) = hwnd {
unsafe {
ShowWindow(hwnd, winapi::um::winuser::SW_MINIMIZE);
}
}
}

let (sender, receiver) = channel::<(Recipe, Arguments)>();

if let Err(e) = smgui::sm_gui(recipe.clone(), _metadata, args.recipe.clone(), args, sender)
{
println!("smoothie egui failed:\n\n{}", e);
};
let (sender, receiver) =
channel::<(Recipe, Arguments, Option<windows::Win32::Foundation::HWND>)>();

let _ret = smgui::sm_gui(recipe.clone(), _metadata, args.recipe.clone(), args, sender);

// for video in receiver.recv().ok().unwrap() {
// dbg!(&video.payload.basename);
// }
#[cfg(windows)]
if interact {
if let Some(hwnd) = hwnd {
unsafe {
ShowWindow(hwnd, winapi::um::winuser::SW_RESTORE);
}
}
}

if let Some(hwnd) = hwnd {
if let Ok((args, recipe, hwnd)) = receiver.recv() {
unsafe {
ShowWindow(hwnd, winapi::um::winuser::SW_RESTORE);
let _ret = windows::Win32::UI::WindowsAndMessaging::DestroyWindow(hwnd.unwrap());
// dbg!(&_ret);
}
}

if let Ok((args, recipe)) = receiver.recv() {
(args, recipe)
} else {
panic!("Failed retrieving data from GUI");
// this also
std::process::exit(0);
// panic!("Failed retrieving data from GUI");
// this also
}
} else {
// data was already retrieved from CLI, just pass them back
Expand All @@ -120,5 +138,5 @@ fn main() {

payloads = video::resolve_input(&mut args, &recipe);
let commands: Vec<SmCommand> = cmd::build_commands(args, payloads, recipe);
render::vspipe_render(commands);
vspipe_render(commands);
}
9 changes: 1 addition & 8 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,7 @@ pub fn vspipe_render(commands: Vec<SmCommand>) {
vs.wait_with_output().unwrap();
let status = ffmpeg.wait_with_output().unwrap().status;
if !status.success() {
let ffmpeg_code = status.code();
eprintln!("ffmpeg returned with error: {:?}", ffmpeg_code);
let return_code = if let Some(code) = ffmpeg_code {
code
} else {
0
};
std::process::exit(return_code);
panic!("ffmpeg / vapoursynth did not return sucessfully\n\nIF YOU ARE TAKING A SCREENSHOT WHEN ASKING FOR SUPPORT MAKE SURE TO INCLUDE THE TERMINAL's WHICH IS WHERE THE ERROR IS EXPLAINED");
}
}
}
Expand Down
71 changes: 48 additions & 23 deletions src/smgui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
};
use copypasta::{ClipboardContext, ClipboardProvider};
use eframe::egui;
use winit::raw_window_handle::HasWindowHandle;

struct SmApp {
recipe: Recipe,
Expand All @@ -22,7 +23,7 @@ struct SmApp {
start_rendering: bool,
// yeah that's the damn typename
recipe_saved: String,
sender: Sender<(Recipe, Arguments)>
sender: Sender<(Recipe, Arguments, Option<windows::Win32::Foundation::HWND>)>
}

pub const WINDOW_NAME: &str = "smoothie-app";
Expand Down Expand Up @@ -75,22 +76,9 @@ pub fn sm_gui<'gui>(
metadata: WidgetMetadata,
recipe_filepath: String,
args: Arguments,
sender: Sender<(Recipe, Arguments)>,
sender: Sender<(Recipe, Arguments, Option<windows::Win32::Foundation::HWND>)>,
) -> Result<(), eframe::Error> {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let state: SmApp = SmApp {
recipe_saved: format!("{:?}", recipe),
recipe,
metadata,
selected_files: vec![], // file select dialog with render button
show_confirmation_dialog: false,
allowed_to_close: false,
show_about: false,
recipe_filepath,
args,
start_rendering: false,
sender: sender,
};

let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
Expand All @@ -105,31 +93,69 @@ pub fn sm_gui<'gui>(
eframe::run_native(
WINDOW_NAME,
options,
Box::new(|_|{Box::new(state)}),
Box::new(|_cc|{

Box::new(
SmApp {
recipe_saved: format!("{:?}", recipe),
recipe,
metadata,
selected_files: vec![], // file select dialog with render button
show_confirmation_dialog: false,
allowed_to_close: false,
show_about: false,
recipe_filepath,
args,
start_rendering: false,
sender: sender
}
)
}),
)
}


impl eframe::App for SmApp {

fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
if self.start_rendering {

let mut scoped_args = self.args.clone();
scoped_args.input = self.selected_files.clone();

let send_result = self.sender.send((self.recipe.clone(), scoped_args));

let hwnd: Option<windows::Win32::Foundation::HWND> = if cfg!(windows) {
let winit::raw_window_handle::RawWindowHandle::Win32(handle) = _frame.window_handle().unwrap().as_raw() else {
panic!("Unsupported platform");
};
Some(windows::Win32::Foundation::HWND(handle.hwnd.into()))

} else {
None
};

let send_result = self.sender.send((self.recipe.clone(), scoped_args, hwnd));

if let Err(e) = send_result {
eprintln!("Retrieving filepaths from GUI panicked: {:?}", e);
}

self.selected_files.clear();
self.start_rendering = false;

// self.show_confirmation_dialog = true;
// self.allowed_to_close = true;
// let ctx = ctx.clone();
// std::thread::spawn(move || {
// ctx.send_viewport_cmd(egui::ViewportCommand::Minimized(true));
// });
self.selected_files.clear();
self.start_rendering = false;

ctx.send_viewport_cmd(egui::ViewportCommand::Close);
ctx.request_repaint();
// self.show_confirmation_dialog = false;
// self.allowed_to_close = true;
ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
}

egui::menu::bar(ui, |ui| {
egui::widgets::global_dark_light_mode_switch(ui);
if ui.button("README").clicked() {
Expand Down Expand Up @@ -173,7 +199,6 @@ impl eframe::App for SmApp {
if !input_vids.is_empty() {
self.selected_files = input_vids;
self.start_rendering = true;
// ui.ctx().send_viewport_cmd(egui::ViewportCommand::Close);
}
}
}
Expand Down Expand Up @@ -479,7 +504,7 @@ impl eframe::App for SmApp {
}
});
}

if ctx.input(|i| i.viewport().close_requested()) && !self.allowed_to_close {
{
ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose);
Expand Down
4 changes: 4 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ extern "C" {

#[cfg(windows)]
pub fn set_window_position(recipe: &Recipe) {

if cfg!(windows) {
return
}
#[rustfmt::skip]
let pos = {
let pos = recipe.get("console", "position");
Expand Down

0 comments on commit 8e6ec21

Please sign in to comment.