Skip to content

Commit

Permalink
add no-cache flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Kl4rry committed Oct 26, 2024
1 parent c47b68a commit e3268c4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,7 @@ impl App {
proxy: EventLoopProxy<UserEvent>,
size: [f32; 2],
zen_mode: bool,
no_cache: bool,
) -> Self {
let dialog_manager = DialogManager::new(proxy.clone());
App {
Expand All @@ -1206,7 +1207,7 @@ impl App {
image_renderer: image_renderer::Renderer::new(wgpu),
crop_renderer: crop_renderer::Renderer::new(wgpu),
image_view: None,
op_queue: OpQueue::new(proxy.clone(), dialog_manager.get_proxy()),
op_queue: OpQueue::new(proxy.clone(), dialog_manager.get_proxy(), no_cache),
dialog_manager,
color_type: ColorType::Rgba8,
size: Vector2::from(size),
Expand Down
8 changes: 6 additions & 2 deletions src/app/op_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,13 @@ pub struct OpQueue {
}

impl OpQueue {
pub fn new(proxy: EventLoopProxy<UserEvent>, dialog_proxy: DialogProxy) -> Self {
pub fn new(
proxy: EventLoopProxy<UserEvent>,
dialog_proxy: DialogProxy,
no_cache: bool,
) -> Self {
const CACHE_SIZE: usize = 1_000_000_000;
let cache = Arc::new(Cache::new(CACHE_SIZE));
let cache = Arc::new(Cache::new(if no_cache { 0 } else { CACHE_SIZE }));
let loading_info = Arc::new(Mutex::new(LoadingInfo::default()));

Self {
Expand Down
6 changes: 6 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@ pub fn get_clap_command() -> clap::Command {
.help("Remove all UI")
.action(clap::ArgAction::SetTrue),
)
.arg(
clap::Arg::new("no-cache")
.long("no-cache")
.help("Do not cache images in memory")
.action(clap::ArgAction::SetTrue),
)
.arg(clap::Arg::new("file").help("Load this file").index(1))
}
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub struct WindowHandler {
}

impl WindowHandler {
pub async fn new(fullscreen: bool, zen_mode: bool) -> Self {
pub async fn new(fullscreen: bool, zen_mode: bool, no_cache: bool) -> Self {
let mut config: Config = confy::load("simp", None).unwrap_or_default();
config.preferences.clamp();

Expand Down Expand Up @@ -204,6 +204,7 @@ impl WindowHandler {
proxy.clone(),
[size.width as f32, size.height as f32],
zen_mode,
no_cache,
);

let ctrl_proxy = proxy.clone();
Expand Down Expand Up @@ -461,8 +462,9 @@ fn main() {
let path: Option<&String> = matches.get_one("file");
let fullscreen: bool = matches.get_flag("fullscreen");
let zen_mode: bool = matches.get_flag("zen-mode");
let no_cache: bool = matches.get_flag("no-cache");

let mut window_handler = pollster::block_on(WindowHandler::new(fullscreen, zen_mode));
let mut window_handler = pollster::block_on(WindowHandler::new(fullscreen, zen_mode, no_cache));

if !io::stdin().is_terminal() {
let proxy = window_handler.proxy.clone();
Expand Down

0 comments on commit e3268c4

Please sign in to comment.