enable gtk frontend in windows (#58)

The gtk frontend can now be built in windows!
The github workflow is updated to build GTK and add it to the releases section.
This commit is contained in:
Ferdinand Schober
2023-12-24 18:00:59 +01:00
committed by GitHub
parent cdd3a3b818
commit d3fed1b769
11 changed files with 208 additions and 20 deletions

View File

@@ -109,9 +109,9 @@ impl Config {
};
let frontend = match frontend {
#[cfg(all(unix, feature = "gtk"))]
#[cfg(feature = "gtk")]
None => Frontend::Gtk,
#[cfg(any(not(feature = "gtk"), not(unix)))]
#[cfg(not(feature = "gtk"))]
None => Frontend::Cli,
Some(s) => match s.as_str() {
"cli" => Frontend::Cli,

View File

@@ -31,16 +31,16 @@ use crate::{
pub mod cli;
/// gtk frontend
#[cfg(all(unix, feature = "gtk"))]
#[cfg(feature = "gtk")]
pub mod gtk;
pub fn run_frontend(config: &Config) -> Result<()> {
match config.frontend {
#[cfg(all(unix, feature = "gtk"))]
#[cfg(feature = "gtk")]
Frontend::Gtk => {
gtk::run();
}
#[cfg(any(not(feature = "gtk"), not(unix)))]
#[cfg(not(feature = "gtk"))]
Frontend::Gtk => panic!("gtk frontend requested but feature not enabled!"),
Frontend::Cli => {
cli::run()?;

View File

@@ -27,7 +27,17 @@ use super::FrontendNotify;
pub fn run() -> glib::ExitCode {
log::debug!("running gtk frontend");
#[cfg(windows)]
let ret = std::thread::Builder::new()
.stack_size(8 * 1024 * 1024) // https://gitlab.gnome.org/GNOME/gtk/-/commit/52dbb3f372b2c3ea339e879689c1de535ba2c2c3 -> caused crash on windows
.name("gtk".into())
.spawn(gtk_main)
.unwrap()
.join()
.unwrap();
#[cfg(not(windows))]
let ret = gtk_main();
log::debug!("frontend exited");
ret
}

View File

@@ -1,7 +1,9 @@
use std::{
cell::{Cell, RefCell},
os::unix::net::UnixStream,
};
use std::cell::{Cell, RefCell};
#[cfg(windows)]
use std::net::TcpStream;
#[cfg(unix)]
use std::os::unix::net::UnixStream;
use adw::subclass::prelude::*;
use adw::{
@@ -29,7 +31,10 @@ pub struct Window {
#[template_child]
pub toast_overlay: TemplateChild<ToastOverlay>,
pub clients: RefCell<Option<gio::ListStore>>,
#[cfg(unix)]
pub stream: RefCell<Option<UnixStream>>,
#[cfg(windows)]
pub stream: RefCell<Option<TcpStream>>,
pub port: Cell<u16>,
}

View File

@@ -36,8 +36,10 @@ pub fn run() -> Result<()> {
} else {
// otherwise start the service as a child process and
// run a frontend
start_service()?;
let mut service = start_service()?;
frontend::run_frontend(&config)?;
log::info!("terminating service");
service.kill()?;
}
anyhow::Ok(())