fix(tasks): fix shortcut manipulation logic

This commit is contained in:
liushuyu 2022-04-02 21:52:28 -06:00
parent 42e092f54d
commit 89be1c0d84
No known key found for this signature in database
GPG key ID: 23D1CE4534419437
6 changed files with 24 additions and 5 deletions

View file

@ -190,7 +190,9 @@ pub fn handle(service: &WebService, _req: Request) -> InternalFuture {
let req = serde_json::from_slice::<AuthRequest>(&body);
if req.is_err() {
warn!("Failed to parse auth request from the frontend");
return default_future(Response::new().with_status(hyper::StatusCode::BadRequest));
return default_future(
Response::new().with_status(hyper::StatusCode::BadRequest),
);
}
let req = req.unwrap();

View file

@ -52,6 +52,19 @@ pub fn handle(service: &WebService, req: Request) -> Future {
}
}
if !install_desktop_shortcut {
let framework_ref = framework
.read()
.log_expect("InstallerFramework has been dirtied");
install_desktop_shortcut = framework_ref.preexisting_install
&& framework_ref
.database
.packages
.first()
.and_then(|x| Some(x.shortcuts.len() > 1))
.unwrap_or(false);
}
// The frontend always provides this
let path =
path.log_expect("No path specified by frontend when one should have already existed");

View file

@ -36,6 +36,7 @@ use crate::logging::LoggingErrors;
use dirs::home_dir;
use std::collections::HashSet;
use std::fs::remove_file;
use crate::http;
@ -117,7 +118,7 @@ pub struct LocalInstallation {
/// Relative paths to generated files
pub files: Vec<String>,
/// Absolute paths to generated shortcut files
pub shortcuts: Vec<String>,
pub shortcuts: HashSet<String>,
}
macro_rules! declare_messenger_callback {

View file

@ -11,6 +11,7 @@ use crate::config::PackageDescription;
use crate::logging::LoggingErrors;
#[cfg(windows)]
use crate::native::create_desktop_shortcut;
pub struct InstallDesktopShortcutTask {
@ -84,6 +85,7 @@ impl Task for InstallDesktopShortcutTask {
.to_str()
.log_expect("Unable to build shortcut metadata (exe)");
#[cfg(windows)]
installed_files.push(create_desktop_shortcut(
&shortcut.name,
&shortcut.description,
@ -99,7 +101,7 @@ impl Task for InstallDesktopShortcutTask {
let packages = &mut context.database.packages;
for pack in packages {
if pack.name == self.name {
pack.shortcuts.append(&mut installed_files);
pack.shortcuts.extend(installed_files.clone());
}
}

View file

@ -23,6 +23,7 @@ use crate::logging::LoggingErrors;
use crate::archives;
use crate::tasks::install_desktop_shortcut::InstallDesktopShortcutTask;
use std::collections::HashSet;
use std::fs::OpenOptions;
use std::path::Path;
@ -172,7 +173,7 @@ impl Task for InstallPackageTask {
context.database.packages.push(LocalInstallation {
name: package.name,
version,
shortcuts: Vec::new(),
shortcuts: HashSet::new(),
files: installed_files,
});

View file

@ -91,7 +91,7 @@ impl Task for InstallShortcutsTask {
let packages = &mut context.database.packages;
for pack in packages {
if pack.name == self.name {
pack.shortcuts.append(&mut installed_files);
pack.shortcuts.extend(installed_files.clone());
}
}