Various installer and tray apps fixes (#4970)
* Mac tray app fixes * Windows restarting fixed
This commit is contained in:
parent
bb1bbebfd6
commit
f5ea47a7b2
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -52,6 +52,7 @@ dependencies = [
|
|||||||
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"toml 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"toml 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -24,6 +24,7 @@ serde = "0.9"
|
|||||||
serde_json = "0.9"
|
serde_json = "0.9"
|
||||||
app_dirs = "1.1.1"
|
app_dirs = "1.1.1"
|
||||||
fdlimit = "0.1"
|
fdlimit = "0.1"
|
||||||
|
ws2_32-sys = "0.2"
|
||||||
hyper = { default-features = false, git = "https://github.com/paritytech/hyper" }
|
hyper = { default-features = false, git = "https://github.com/paritytech/hyper" }
|
||||||
ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" }
|
ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" }
|
||||||
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.7" }
|
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc.git", branch = "parity-1.7" }
|
||||||
|
@ -26,7 +26,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
let statusItem = NSStatusBar.system().statusItem(withLength: NSVariableStatusItemLength)
|
let statusItem = NSStatusBar.system().statusItem(withLength: NSVariableStatusItemLength)
|
||||||
var parityPid: Int32? = nil
|
var parityPid: Int32? = nil
|
||||||
var commandLine: [String] = []
|
var commandLine: [String] = []
|
||||||
let defaultConfig = "[network]\nwarp = true"
|
|
||||||
let defaultDefaults = "{\"fat_db\":false,\"mode\":\"passive\",\"mode.alarm\":3600,\"mode.timeout\":300,\"pruning\":\"fast\",\"tracing\":false}"
|
let defaultDefaults = "{\"fat_db\":false,\"mode\":\"passive\",\"mode.alarm\":3600,\"mode.timeout\":300,\"pruning\":\"fast\",\"tracing\":false}"
|
||||||
|
|
||||||
func menuAppPath() -> String {
|
func menuAppPath() -> String {
|
||||||
@ -51,7 +50,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
|
|
||||||
func killParity() {
|
func killParity() {
|
||||||
if let pid = self.parityPid {
|
if let pid = self.parityPid {
|
||||||
kill(pid, SIGINT)
|
kill(pid, SIGKILL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,9 +80,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let configFile = basePath?.appendingPathComponent("config.toml")
|
let configFile = basePath?.appendingPathComponent("config.toml")
|
||||||
if !FileManager.default.fileExists(atPath: configFile!.path) {
|
|
||||||
try defaultConfig.write(to: configFile!, atomically: false, encoding: String.Encoding.utf8)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch {}
|
catch {}
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,9 @@ extern crate ethcore_secretstore;
|
|||||||
#[cfg(feature = "dapps")]
|
#[cfg(feature = "dapps")]
|
||||||
extern crate ethcore_dapps;
|
extern crate ethcore_dapps;
|
||||||
|
|
||||||
|
#[cfg(windows)] extern crate ws2_32;
|
||||||
|
#[cfg(windows)] extern crate winapi;
|
||||||
|
|
||||||
macro_rules! dependency {
|
macro_rules! dependency {
|
||||||
($dep_ty:ident, $url:expr) => {
|
($dep_ty:ident, $url:expr) => {
|
||||||
{
|
{
|
||||||
@ -123,7 +126,7 @@ mod stratum;
|
|||||||
use std::{process, env};
|
use std::{process, env};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::{self as stdio, BufReader, Read, Write};
|
use std::io::{self as stdio, BufReader, Read, Write};
|
||||||
use std::fs::{remove_file, metadata, File};
|
use std::fs::{remove_file, metadata, File, create_dir_all};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use util::sha3::sha3;
|
use util::sha3::sha3;
|
||||||
use cli::Args;
|
use cli::Args;
|
||||||
@ -210,10 +213,11 @@ fn latest_exe_path() -> Option<PathBuf> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn set_spec_name_override(spec_name: String) {
|
fn set_spec_name_override(spec_name: String) {
|
||||||
if let Err(e) = File::create(updates_path("spec_name_overide"))
|
if let Err(e) = create_dir_all(default_hypervisor_path())
|
||||||
.and_then(|mut f| f.write_all(spec_name.as_bytes()))
|
.and_then(|_| File::create(updates_path("spec_name_overide"))
|
||||||
|
.and_then(|mut f| f.write_all(spec_name.as_bytes())))
|
||||||
{
|
{
|
||||||
warn!("Couldn't override chain spec: {}", e);
|
warn!("Couldn't override chain spec: {} at {:?}", e, updates_path("spec_name_overide"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,12 +231,24 @@ fn take_spec_name_override() -> Option<String> {
|
|||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn global_cleanup() {
|
fn global_cleanup() {
|
||||||
extern "system" { pub fn WSACleanup() -> i32; }
|
|
||||||
// We need to cleanup all sockets before spawning another Parity process. This makes shure everything is cleaned up.
|
// We need to cleanup all sockets before spawning another Parity process. This makes shure everything is cleaned up.
|
||||||
// The loop is required because of internal refernce counter for winsock dll. We don't know how many crates we use do
|
// The loop is required because of internal refernce counter for winsock dll. We don't know how many crates we use do
|
||||||
// initialize it. There's at least 2 now.
|
// initialize it. There's at least 2 now.
|
||||||
for _ in 0.. 10 {
|
for _ in 0.. 10 {
|
||||||
unsafe { WSACleanup(); }
|
unsafe { ::ws2_32::WSACleanup(); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
fn global_init() {}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn global_init() {
|
||||||
|
// When restarting in the same process this reinits windows sockets.
|
||||||
|
unsafe {
|
||||||
|
const WS_VERSION: u16 = 0x202;
|
||||||
|
let mut wsdata: ::winapi::winsock2::WSADATA = ::std::mem::zeroed();
|
||||||
|
::ws2_32::WSAStartup(WS_VERSION, &mut wsdata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,15 +257,17 @@ fn global_cleanup() {}
|
|||||||
|
|
||||||
// Starts ~/.parity-updates/parity and returns the code it exits with.
|
// Starts ~/.parity-updates/parity and returns the code it exits with.
|
||||||
fn run_parity() -> Option<i32> {
|
fn run_parity() -> Option<i32> {
|
||||||
global_cleanup();
|
global_init();
|
||||||
use ::std::ffi::OsString;
|
use ::std::ffi::OsString;
|
||||||
let prefix = vec![OsString::from("--can-restart"), OsString::from("--force-direct")];
|
let prefix = vec![OsString::from("--can-restart"), OsString::from("--force-direct")];
|
||||||
latest_exe_path().and_then(|exe| process::Command::new(exe)
|
let res = latest_exe_path().and_then(|exe| process::Command::new(exe)
|
||||||
.args(&(env::args_os().skip(1).chain(prefix.into_iter()).collect::<Vec<_>>()))
|
.args(&(env::args_os().skip(1).chain(prefix.into_iter()).collect::<Vec<_>>()))
|
||||||
.status()
|
.status()
|
||||||
.map(|es| es.code().unwrap_or(128))
|
.map(|es| es.code().unwrap_or(128))
|
||||||
.ok()
|
.ok()
|
||||||
)
|
);
|
||||||
|
global_cleanup();
|
||||||
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
const PLEASE_RESTART_EXIT_CODE: i32 = 69;
|
const PLEASE_RESTART_EXIT_CODE: i32 = 69;
|
||||||
@ -257,10 +275,11 @@ const PLEASE_RESTART_EXIT_CODE: i32 = 69;
|
|||||||
// Run our version of parity.
|
// Run our version of parity.
|
||||||
// Returns the exit error code.
|
// Returns the exit error code.
|
||||||
fn main_direct(can_restart: bool) -> i32 {
|
fn main_direct(can_restart: bool) -> i32 {
|
||||||
|
global_init();
|
||||||
let mut alt_mains = HashMap::new();
|
let mut alt_mains = HashMap::new();
|
||||||
sync_main(&mut alt_mains);
|
sync_main(&mut alt_mains);
|
||||||
stratum_main(&mut alt_mains);
|
stratum_main(&mut alt_mains);
|
||||||
if let Some(f) = std::env::args().nth(1).and_then(|arg| alt_mains.get(&arg.to_string())) {
|
let res = if let Some(f) = std::env::args().nth(1).and_then(|arg| alt_mains.get(&arg.to_string())) {
|
||||||
f();
|
f();
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
@ -280,7 +299,9 @@ fn main_direct(can_restart: bool) -> i32 {
|
|||||||
1
|
1
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
global_cleanup();
|
||||||
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
fn println_trace_main(s: String) {
|
fn println_trace_main(s: String) {
|
||||||
|
Loading…
Reference in New Issue
Block a user