Skip to content

Commit

Permalink
fixed!
Browse files Browse the repository at this point in the history
  • Loading branch information
jantar1154 committed May 3, 2024
1 parent 2bc60ec commit c03e4f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/cg_fetch.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{sync::Mutex, collections::HashMap, env, fs::File, hash::Hash, io::Write};
use std::{collections::HashMap, env, fs::File, io::Write};

use crate::MainWindow;
use reqwest::blocking::{self, Client};
use serde_json::Value;
use slint::{SharedPixelBuffer, SharedString, Weak};
use slint::{SharedPixelBuffer, Weak};

fn file_to_slint_img(img_path: &str) -> slint::Image {
// Convert the file into rgb8 array and then the array into into slint::Image
Expand Down Expand Up @@ -56,8 +56,9 @@ fn get_temp_path() -> String {
}
// Handles getting image from https://nekos.moe
// and setting the Image in uiw to the image
pub(crate) fn fetch_new() {
let json = get_random_id();
pub(crate) fn fetch_new(uiw: &Weak<MainWindow>) {
let ui = uiw.upgrade().unwrap();
let json = get_random_id(ui.get_nsfw());

// Use the ID to create a new link, which contains only a catgirl image
let url = format!("https://nekos.moe/image/{}", json.0);
Expand Down Expand Up @@ -98,4 +99,9 @@ pub(crate) fn fetch_new() {
.copy_to(&mut image_file)
.unwrap();

let slint_img = file_to_slint_img(&tmp_path);

// Set the slint image as a source in .slint file
ui.set_img(slint_img);

}
5 changes: 1 addition & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ fn main() -> Result<(), slint::PlatformError> {

let uiw = ui.as_weak();
ui.on_fetch(move || {
thread::spawn(move || {
cg_fetch::fetch_new();
});
cg_fetch::update_ui(&uiw);
cg_fetch::fetch_new(&uiw);
});

ui.on_download(move || {
Expand Down

0 comments on commit c03e4f5

Please sign in to comment.