-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.rs
143 lines (119 loc) · 4.03 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// #![windows_subsystem = "windows"]
#[macro_use] // to parse --json in video.rs
extern crate serde_derive;
use recipe::Recipe;
use render::vspipe_render;
#[cfg(windows)]
use winapi::um::{
wincon::GetConsoleWindow,
winuser::ShowWindow,
};
mod cli;
mod cmd;
mod smgui;
// mod ffpb;
// mod ffpb2;
mod parse;
mod recipe;
mod render;
mod utils;
//mod vapoursynth;
mod video;
use crate::{cli::Arguments, cmd::SmCommand, video::Payload};
use std::{env, sync::mpsc::channel};
use utils::verbosity_init;
const VIDEO_EXTENSIONS: &[&str] = &[
"mp4", "mkv", "webm", "mov", "avi", "wmv", "flv", "ts", "m3u8", "qt", "m4v",
];
const YES: &[&str] = &[
"on", "True", "true", "yes", "y", "1", "yeah", "yea", "yep", "sure", "positive",
];
const NO: &[&str] = &[
"off", "False", "false", "no", "n", "nah", "nope", "negative", "negatory", "0", "0.0", "null",
"", " ", " ", "\t", "none",
];
fn main() {
if enable_ansi_support::enable_ansi_support().is_err() {
println!("Failed enabling ANSI color support, expect broken colors!")
}
// unused for now as it spams the API each time you launch it :/...
// parse::parse_update();
let mut args: Arguments = cli::setup_args();
// args.input is the only one being mutated in video.rs
// Recipe and WidgetMetadata
let (recipe, _metadata) = recipe::get_recipe(&mut args);
// mutable because args.verbose sets `[miscellaneous] always verbose:` to true
// loads defaults.ini, then overrides recipe.ini over it
verbosity_init(
args.verbose,
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")
&& !recipe.get_bool("miscellaneous", "always verbose")
&& !args.verbose
{
utils::set_window_position(&recipe);
}
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();
if !hwnd.is_null() {
Some(hwnd)
} else {
None
}
}
} else {
None
};
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, Option<windows::Win32::Foundation::HWND>)>();
let _ret = smgui::sm_gui(recipe.clone(), _metadata, args.recipe.clone(), args, sender);
#[cfg(windows)]
if interact {
if let Some(hwnd) = hwnd {
unsafe {
ShowWindow(hwnd, winapi::um::winuser::SW_RESTORE);
}
}
}
if let Ok((args, recipe, hwnd)) = receiver.recv() {
#[cfg(windows)]
unsafe {
let _ret = windows::Win32::UI::WindowsAndMessaging::DestroyWindow(hwnd.unwrap());
// dbg!(&_ret);
}
(args, recipe)
} else {
std::process::exit(0);
// panic!("Failed retrieving data from GUI");
// this also
}
} else {
// data was already retrieved from CLI, just pass them back
(recipe, args)
};
payloads = video::resolve_input(&mut args, &recipe);
let commands: Vec<SmCommand> = cmd::build_commands(args, payloads, recipe);
vspipe_render(commands);
}