Commit 6f39fb31 authored by Eisha Chen-yen-su's avatar Eisha Chen-yen-su

Add draft for backend feedbacks

parent 56a2666c
......@@ -13,13 +13,17 @@ pub fn launch() {
gtk::Application::new("org.gnome.Automata", gio::ApplicationFlags::empty())
.expect("Could not create application");
let (sender, receiver) = channel::<String>();
let sender = Arc::new(RwLock::new(sender));
let (cmd_sender, cmd_receiver) = channel::<String>();
let cmd_sender = Arc::new(RwLock::new(cmd_sender));
backend::launch(receiver);
let (update_sender, update_receiver) = channel::<String>();
let update_receiver = Arc::new(RwLock::new(update_receiver));
backend::launch(cmd_receiver, update_sender);
app.connect_startup(move |app| {
let w: gtk::ApplicationWindow = window::new_window(sender.clone());
let w: gtk::ApplicationWindow =
window::new_window(cmd_sender.clone(), update_receiver.clone());
w.set_application(app);
w.show_all();
});
......
use std::sync::mpsc::Receiver;
use std::sync::mpsc::{Receiver, Sender};
use std::thread;
pub fn launch(cmd_chan: Receiver<String>) {
thread::spawn(move || loop {
match cmd_chan.recv() {
Ok(msg) => println!("Received: {}", msg),
Err(_) => {
println!("Error, exiting!");
break;
pub fn launch(cmd_chan: Receiver<String>, update_chan: Sender<String>) {
thread::spawn(move || {
let mut count = 0;
loop {
match cmd_chan.recv() {
Ok(_) => {
count += 1;
update_chan
.send(String::from(format!(
"Action button clicked {} times!",
count
)))
.unwrap();
}
Err(_) => {
println!("Backend error, exiting!");
break;
}
}
}
});
......
......@@ -4,10 +4,13 @@ extern crate gtk;
use gtk::prelude::*;
use std::sync::mpsc::Sender;
use std::sync::{Arc, RwLock};
use std::sync::mpsc::{Receiver, Sender};
pub fn new_window(cmd_chan: Arc<RwLock<Sender<String>>>) -> gtk::ApplicationWindow {
pub fn new_window(
cmd_chan: Arc<RwLock<Sender<String>>>,
update_chan: Arc<RwLock<Receiver<String>>>,
) -> gtk::ApplicationWindow {
let builder: gtk::Builder =
gtk::Builder::new_from_resource("/org/gnome/Automata/gtk/window.ui");
......@@ -24,9 +27,12 @@ pub fn new_window(cmd_chan: Arc<RwLock<Sender<String>>>) -> gtk::ApplicationWind
let btn_action: gtk::Button = builder
.get_object("action_button")
.expect("action_button not found");
btn_action.connect_clicked(clone!(cmd_chan => move |_| {
hello_label.set_text("Action button clicked");
btn_action.connect_clicked(clone!(cmd_chan, update_chan => move |_| {
cmd_chan.read().unwrap().send(String::from("Button clicked!")).unwrap();
let msg = update_chan.read().unwrap().recv().unwrap();
hello_label.set_text(&msg);
}));
let mnu_about: gtk::MenuItem = builder
......
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