Fixed running with console on Windows when compiled as GUI app.

pull/3/head
Revertron 3 years ago
parent 6676c0779f
commit 2bea778e0f

@ -1,9 +1,10 @@
[package]
name = "alfis"
version = "0.1.0"
authors = ["Revertron <rev@revertron.com>"]
authors = ["Revertron <alfis@revertron.com>"]
edition = "2018"
build = "build.rs"
readme = "README.md"
homepage = "https://alfis.name"
repository = "https://github.com/Revertron/Alfis"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -30,6 +31,9 @@ mio = { version = "0.7", features = ["os-poll", "net"] }
# for DNS from hermes
derive_more = "0.99.9"
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.7", features = ["impl-default", "wincon"]}
[build-dependencies]
winres = "0.1"

@ -1,3 +1,6 @@
// With the default subsystem, 'console', windows creates an additional console window for the program.
// This is silently ignored on non-windows systems.
// See https://msdn.microsoft.com/en-us/library/4cc7ya5b.aspx for more details.
#![windows_subsystem = "windows"]
extern crate web_view;
extern crate tinyfiledialogs as tfd;
@ -8,6 +11,9 @@ use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::thread;
use std::time::Duration;
#[cfg(windows)]
use winapi::um::wincon::{AttachConsole, FreeConsole, ATTACH_PARENT_PROCESS};
use rand::RngCore;
use serde::Deserialize;
use web_view::*;
@ -34,6 +40,13 @@ const KEYSTORE_DIFFICULTY: usize = 24;
const SETTINGS_FILENAME: &str = "alfis.cfg";
fn main() {
// When linked with the windows subsystem windows won't automatically attach
// to the console of the parent process, so we do it explicitly. This fails silently if the parent has no console.
#[cfg(windows)]
unsafe {
AttachConsole(ATTACH_PARENT_PROCESS);
}
println!("ALFIS 0.1.0");
let args: Vec<String> = env::args().collect();
let program = args[0].clone();
@ -89,6 +102,12 @@ fn main() {
} else {
run_interface(context.clone(), miner.clone());
}
// Without explicitly detaching the console cmd won't redraw it's prompt.
#[cfg(windows)]
unsafe {
FreeConsole();
}
}
fn start_dns_server(context: &Arc<Mutex<Context>>, settings: &Settings) {

Loading…
Cancel
Save