summaryrefslogtreecommitdiffstats
path: root/src/gui/mod.rs
blob: 97751b0c20990166779e56d737468bae2296d36b (plain)
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
use anyhow::Result;
use iced::Application;
use ipfs_api_backend_hyper::TryFromUri;

use crate::client::Client;
use crate::config::Config;
use crate::ipfs_client::IpfsClient;

#[derive(Debug)]
struct DistroxGui;

#[derive(Debug)]
enum Message {
    Loaded(Result<Client>),
}

impl Application for DistroxGui {
    type Executor = iced::executor::Default; // tokio
    type Message = Message;
    type Flags = ();

    fn new(_flags: ()) -> (Self, iced::Command<Self::Message>) {
        (
            DistroxGui,
            iced::Command::perform(async {
                let ipfs  = IpfsClient::from_str("http://localhost:5001")?;
                let config = Config::default();
                let client = Client::new(ipfs, config);
                Ok(client)
            }, Message::Loaded)
        )
    }

    fn title(&self) -> String {
        String::from("distrox")
    }

    fn update(&mut self, _message: Self::Message, _clipboard: &mut iced::Clipboard) -> iced::Command<Self::Message> {
        iced::Command::none()
    }

    fn view(&mut self) -> iced::Element<Self::Message> {
        iced::Text::new("Hello, world!").into()
    }

}

pub fn run() -> Result<()> {
    let settings = iced::Settings {
        window: iced::window::Settings {
            resizable: true,
            decorations: true,
            transparent: false,
            always_on_top: false,
            ..iced::window::Settings::default()
        },
        exit_on_close_request: true,
        ..iced::Settings::default()
    };

    DistroxGui::run(settings).map_err(anyhow::Error::from)
}