platform: fix build on Linux and update web-view

This commit is contained in:
liushuyu 2019-03-28 11:08:13 -06:00
parent f2af419b95
commit d236eeec0c
No known key found for this signature in database
GPG Key ID: 23D1CE4534419437
9 changed files with 853 additions and 576 deletions

1311
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@ description = "An adaptable installer for your application."
build = "build.rs" build = "build.rs"
[dependencies] [dependencies]
web-view = {git = "https://github.com/Boscop/web-view.git", rev = "555f422d09cbb94e82a728d47e9e07ca91963f6e"} web-view = "0.4.0"
hyper = "0.11.27" hyper = "0.11.27"
futures = "*" futures = "*"

View File

@ -328,7 +328,8 @@ impl InstallerFramework {
x.to_str() x.to_str()
.log_expect("Unable to convert argument to String") .log_expect("Unable to convert argument to String")
.to_string() .to_string()
}).collect(); })
.collect();
{ {
let new_app_file = match File::create(&args_file) { let new_app_file = match File::create(&args_file) {

View File

@ -17,7 +17,8 @@ pub fn setup_logger(file_name: String) -> Result<(), fern::InitError> {
record.level(), record.level(),
message message
)) ))
}).level(log::LevelFilter::Info) })
.level(log::LevelFilter::Info)
.chain(io::stdout()) .chain(io::stdout())
.chain(fern::log_file(file_name)?) .chain(fern::log_file(file_name)?)
.apply()?; .apply()?;

View File

@ -40,7 +40,7 @@ extern crate log;
extern crate chrono; extern crate chrono;
extern crate clap; extern crate clap;
#[cfg(windows)]
extern crate winapi; extern crate winapi;
mod archives; mod archives;
@ -112,7 +112,8 @@ fn main() {
.value_name("TARGET") .value_name("TARGET")
.help("Launches the specified executable after checking for updates") .help("Launches the specified executable after checking for updates")
.takes_value(true), .takes_value(true),
).arg( )
.arg(
Arg::with_name("swap") Arg::with_name("swap")
.long("swap") .long("swap")
.value_name("TARGET") .value_name("TARGET")
@ -280,14 +281,15 @@ fn main() {
let resizable = false; let resizable = false;
let debug = true; let debug = true;
run( web_view::builder()
&format!("{} Installer", app_name), .title(&format!("{} Installer", app_name))
Content::Url(http_address), .content(Content::Url(http_address))
Some(size), .size(size.0, size.1)
resizable, .resizable(resizable)
debug, .debug(debug)
|_| {}, .user_data(())
|wv, msg, _| { .invoke_handler(|wv, msg| {
let mut cb_result = Ok(());
let command: CallbackType = let command: CallbackType =
serde_json::from_str(msg).log_expect(&format!("Unable to parse string: {:?}", msg)); serde_json::from_str(msg).log_expect(&format!("Unable to parse string: {:?}", msg));
@ -304,15 +306,16 @@ fn main() {
}; };
#[cfg(not(windows))] #[cfg(not(windows))]
let result = let result = wv
wv.dialog(Dialog::ChooseDirectory, "Select a install directory...", ""); .dialog()
.choose_directory("Select a install directory...", "");
if !result.is_empty() { if result.is_ok() {
let result = serde_json::to_string(&result) let result = serde_json::to_string(&result.ok())
.log_expect("Unable to serialize response"); .log_expect("Unable to serialize response");
let command = format!("{}({});", callback_name, result); let command = format!("{}({});", callback_name, result);
debug!("Injecting response: {}", command); debug!("Injecting response: {}", command);
wv.eval(&command); cb_result = wv.eval(&command);
} }
} }
CallbackType::Log { msg, kind } => { CallbackType::Log { msg, kind } => {
@ -326,7 +329,8 @@ fn main() {
log!(target: "liftinstall::frontend-js", kind, "{}", msg); log!(target: "liftinstall::frontend-js", kind, "{}", msg);
} }
} }
}, cb_result
(), })
); .run()
.expect("Unable to launch Web UI!");
} }

View File

@ -4,7 +4,7 @@
#[derive(Debug)] #[derive(Debug)]
pub struct Process { pub struct Process {
pub pid: usize, pub pid: usize,
pub name : String pub name: String,
} }
#[cfg(windows)] #[cfg(windows)]
@ -23,14 +23,13 @@ mod natives {
use std::process::Command; use std::process::Command;
use winapi::shared::minwindef::{DWORD, FALSE, MAX_PATH}; use winapi::shared::minwindef::{DWORD, FALSE, MAX_PATH};
use winapi::um::processthreadsapi::OpenProcess;
use winapi::um::psapi::{
EnumProcessModulesEx, GetModuleFileNameExW, K32EnumProcesses, LIST_MODULES_ALL,
};
use winapi::um::winnt::{ use winapi::um::winnt::{
HANDLE, PROCESS_QUERY_INFORMATION, PROCESS_TERMINATE, PROCESS_VM_READ, HANDLE, PROCESS_QUERY_INFORMATION, PROCESS_TERMINATE, PROCESS_VM_READ,
}; };
use winapi::um::processthreadsapi::{OpenProcess};
use winapi::um::psapi::{
K32EnumProcesses,
EnumProcessModulesEx, GetModuleFileNameExW, LIST_MODULES_ALL,
};
extern "C" { extern "C" {
pub fn saveShortcut( pub fn saveShortcut(
@ -149,9 +148,7 @@ mod natives {
let size = ::std::mem::size_of::<DWORD>() * process_ids.len(); let size = ::std::mem::size_of::<DWORD>() * process_ids.len();
unsafe { unsafe {
if K32EnumProcesses(process_ids.as_mut_ptr(), if K32EnumProcesses(process_ids.as_mut_ptr(), size as DWORD, &mut cb_needed) == 0 {
size as DWORD,
&mut cb_needed) == 0 {
return vec![]; return vec![];
} }
} }
@ -169,20 +166,25 @@ mod natives {
let mut process_name = [0u16; MAX_PATH + 1]; let mut process_name = [0u16; MAX_PATH + 1];
let mut cb_needed = 0; let mut cb_needed = 0;
if EnumProcessModulesEx(process_handler, if EnumProcessModulesEx(
process_handler,
&mut h_mod, &mut h_mod,
::std::mem::size_of::<DWORD>() as DWORD, ::std::mem::size_of::<DWORD>() as DWORD,
&mut cb_needed, &mut cb_needed,
LIST_MODULES_ALL) != 0 { LIST_MODULES_ALL,
GetModuleFileNameExW(process_handler, ) != 0
{
GetModuleFileNameExW(
process_handler,
h_mod, h_mod,
process_name.as_mut_ptr(), process_name.as_mut_ptr(),
MAX_PATH as DWORD + 1); MAX_PATH as DWORD + 1,
);
let mut pos = 0; let mut pos = 0;
for x in process_name.iter() { for x in process_name.iter() {
if *x == 0 { if *x == 0 {
break break;
} }
pos += 1; pos += 1;
} }
@ -210,11 +212,11 @@ mod natives {
use logging::LoggingErrors; use logging::LoggingErrors;
pub fn create_shortcut( pub fn create_shortcut(
name: &str, _name: &str,
description: &str, _description: &str,
target: &str, _target: &str,
args: &str, _args: &str,
working_dir: &str, _working_dir: &str,
) -> Result<String, String> { ) -> Result<String, String> {
// TODO: no-op // TODO: no-op
warn!("create_shortcut is stubbed!"); warn!("create_shortcut is stubbed!");

View File

@ -62,7 +62,8 @@ impl WebServer {
Ok(WebService { Ok(WebService {
framework: framework.clone(), framework: framework.clone(),
}) })
}).log_expect("Failed to bind to port"); })
.log_expect("Failed to bind to port");
server.run().log_expect("Failed to run HTTP server"); server.run().log_expect("Failed to run HTTP server");
}); });

View File

@ -41,7 +41,8 @@ impl ReleaseSource for GithubReleases {
.get(&format!( .get(&format!(
"https://api.github.com/repos/{}/releases", "https://api.github.com/repos/{}/releases",
config.repo config.repo
)).header(USER_AGENT, "liftinstall (j-selby)") ))
.header(USER_AGENT, "liftinstall (j-selby)")
.send() .send()
.map_err(|x| format!("Error while sending HTTP request: {:?}", x))?; .map_err(|x| format!("Error while sending HTTP request: {:?}", x))?;
@ -87,14 +88,16 @@ impl ReleaseSource for GithubReleases {
let string = match asset["name"].as_str() { let string = match asset["name"].as_str() {
Some(v) => v, Some(v) => v,
None => { None => {
return Err("JSON payload missing information about release name".to_string()) return Err(
"JSON payload missing information about release name".to_string()
);
} }
}; };
let url = match asset["browser_download_url"].as_str() { let url = match asset["browser_download_url"].as_str() {
Some(v) => v, Some(v) => v,
None => { None => {
return Err("JSON payload missing information about release URL".to_string()) return Err("JSON payload missing information about release URL".to_string());
} }
}; };

View File

@ -7,8 +7,8 @@ use tasks::TaskDependency;
use tasks::TaskMessage; use tasks::TaskMessage;
use tasks::TaskParamType; use tasks::TaskParamType;
use native::Process;
use native::get_process_names; use native::get_process_names;
use native::Process;
use std::process; use std::process;