Commit 52b60d19 authored by Daniel García Moreno's avatar Daniel García Moreno

Move the backend code to fractal-api

parent 1ccffaac
Pipeline #1288 passed with stage
in 26 minutes and 23 seconds
[package]
authors = ["Daniel Garcia <danigm@wadobo.com>"]
name = "fractal-api"
version = "0.1.0"
authors = ["Daniel Garcia <danigm@wadobo.com>"]
workspace = "../"
[dependencies]
gdk = "0.7.0"
gdk-pixbuf = "0.3.0"
#gdk-pixbuf-sys = "0.5.0"
glib = "0.4.0"
mime = "0.3.5"
regex = "0.2.3"
reqwest = "0.8.1"
serde = "1.0.23"
serde_derive = "1.0.23"
serde_json = "1.0.6"
time = "0.1.38"
tree_magic = "0.2.0"
url = "1.6.0"
[dependencies.cairo-rs]
features = ["png"]
version = "0.3.0"
[dependencies.chrono]
features = ["serde"]
version = "0.4.0"
use std::collections::HashMap;
use std::time::Instant;
pub struct CacheMap<T> {
map: HashMap<String, (Instant, T)>,
timeout: u64,
}
impl<T> CacheMap<T> {
pub fn new() -> CacheMap<T> {
CacheMap { map: HashMap::new(), timeout: 10 }
}
pub fn timeout(mut self, timeout: u64) -> CacheMap<T> {
self.timeout = timeout;
self
}
pub fn get(&self, k: &String) -> Option<&T> {
match self.map.get(k) {
Some(t) => {
if t.0.elapsed().as_secs() >= self.timeout {
return None;
}
Some(&t.1)
}
None => None
}
}
pub fn insert(&mut self, k: String, v: T) {
let now = Instant::now();
self.map.insert(k, (now, v));
}
}
......@@ -30,7 +30,6 @@ derror!(io::Error, Error::BackendError);
derror!(regex::Error, Error::BackendError);
derror!(cairo::Status, Error::BackendError);
derror!(cairo::IoError, Error::BackendError);
derror!(cairo::BorrowError, Error::BackendError);
derror!(glib::Error, Error::BackendError);
derror!(SystemTimeError, Error::BackendError);
......
#![deny(unused_extern_crates)]
#[macro_use]
extern crate serde_json;
#[macro_use]
extern crate serde_derive;
#[macro_use]
pub mod util;
pub mod error;
pub mod globals;
mod model;
pub mod types;
pub mod cache;
pub mod backend;
#[cfg(test)]
mod tests {
#[test]
......
......@@ -6,27 +6,18 @@ version = "0.1.3"
workspace = "../"
[dependencies]
fractal-api = { path = "../fractal-api" }
gdk = "0.7.0"
gdk-pixbuf = "0.3.0"
gdk-pixbuf-sys = "0.5.0"
gio = "0.3.0"
glib = "0.4.0"
mime = "0.3.5"
notify-rust = "3.4.2"
pango = "0.3.0"
regex = "0.2.3"
reqwest = "0.8.1"
secret-service = "0.4.0"
serde = "1.0.23"
serde_derive = "1.0.23"
serde_json = "1.0.6"
time = "0.1.38"
tree_magic = "0.2.0"
url = "1.6.0"
[dependencies.cairo-rs]
features = ["png"]
version = "0.3.0"
[dependencies.chrono]
features = ["serde"]
......
......@@ -5,7 +5,6 @@ extern crate secret_service;
extern crate chrono;
extern crate gdk;
extern crate notify_rust;
extern crate pango;
use self::notify_rust::Notification;
......
extern crate serde;
extern crate serde_json;
use std::fs::File;
......@@ -7,46 +6,9 @@ use std::io::prelude::*;
use types::RoomList;
use error::Error;
use std::collections::HashMap;
use std::time::Instant;
use util::cache_path;
use globals;
pub struct CacheMap<T> {
map: HashMap<String, (Instant, T)>,
timeout: u64,
}
impl<T> CacheMap<T> {
pub fn new() -> CacheMap<T> {
CacheMap { map: HashMap::new(), timeout: 10 }
}
pub fn timeout(mut self, timeout: u64) -> CacheMap<T> {
self.timeout = timeout;
self
}
pub fn get(&self, k: &String) -> Option<&T> {
match self.map.get(k) {
Some(t) => {
if t.0.elapsed().as_secs() >= self.timeout {
return None;
}
Some(&t.1)
}
None => None
}
}
pub fn insert(&mut self, k: String, v: T) {
let now = Instant::now();
self.map.insert(k, (now, v));
}
}
#[derive(Serialize, Deserialize)]
pub struct CacheData {
pub since: String,
......
#![deny(unused_extern_crates)]
extern crate glib;
extern crate gio;
#[macro_use]
extern crate serde_json;
#[macro_use]
extern crate serde_derive;
#[macro_use]
mod util;
mod globals;
extern crate fractal_api;
use fractal_api::backend;
use fractal_api::util;
use fractal_api::types;
use fractal_api::error;
use fractal_api::globals;
mod widgets;
mod error;
mod types;
mod cache;
mod backend;
mod model;
mod app;
mod static_resources;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment