Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
Add a loop handler to subscribe notices and request re-rendering to t…
Browse files Browse the repository at this point in the history
…he front end
  • Loading branch information
satler-git committed Aug 3, 2024
1 parent 8ad2b97 commit ead4351
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod icon;
mod img;

use core::panic;
use std::sync::{Arc, RwLock};

use anyhow::{Context as _, Result};
use komorebi_client::{send_query, Layout, SocketMessage, State};
Expand Down Expand Up @@ -52,27 +51,48 @@ async fn main() -> Result<()> {
_ => {}
})
.setup(|app| {
let main_window = app.get_window("main").unwrap();
let main_window_alt = app.get_window("main").unwrap();
let main_window_notify = app.get_window("main").unwrap();

tokio::task::spawn(async move {
// Altキーの監視
// TODO: 関数へ切り出し
// メモ: asyncブロックはfutureを返す。だからmoveしている変数だけ引数にしてasync関数をつくればいい
let receiver = message_loop::start().unwrap();
let mut state = alt_state(&receiver, &false).unwrap();
main_window.hide().unwrap();
main_window.move_window(Position::TopCenter).unwrap();
main_window_alt.hide().unwrap();
main_window_alt.move_window(Position::TopCenter).unwrap();

loop {
let old_state = state.clone();
state = alt_state(&receiver, &old_state).unwrap();
if old_state != state {
if state {
// Windowを表示して描画。イベントを送る。
main_window.show().unwrap();
main_window_alt.show().unwrap();
} else {
// Windowを隠す
main_window.hide().unwrap();
main_window_alt.hide().unwrap();
}
}
}
});

tokio::task::spawn(async move {
// komorebiの通知の監視
// TODO: 関数へ切り出し
// メモ: asyncブロックはfutureを返す。だからmoveしている変数だけ引数にしてasync関数をつくればいい
let notify_receiver = komorebi_client::subscribe("komorebi.sock")
.context("Unable to subscribe notifyes from komorebi now.")
.unwrap();

for incoming in notify_receiver.incoming() {
match incoming {
Ok(_) => if main_window_notify.is_visible().unwrap() {
// フロントエンド側に再レンダリングを要求
},
Err(_) => {
continue;
}
}
}
Expand Down

0 comments on commit ead4351

Please sign in to comment.