Use the correct icon for the application shortcuts

This commit is contained in:
James Rowe 2019-12-06 00:27:44 -07:00
parent 6af46ec703
commit d2ad619d87
4 changed files with 12 additions and 1 deletions

View File

@ -43,7 +43,8 @@ extern "C" int saveShortcut(
const wchar_t *description, const wchar_t *description,
const wchar_t *path, const wchar_t *path,
const wchar_t *args, const wchar_t *args,
const wchar_t *workingDir) const wchar_t *workingDir,
const wchar_t *exePath)
{ {
const char *errStr = NULL; const char *errStr = NULL;
HRESULT h; HRESULT h;
@ -82,6 +83,9 @@ extern "C" int saveShortcut(
shellLink->SetDescription(description); shellLink->SetDescription(description);
if (path != NULL) if (path != NULL)
shellLink->SetPath(path); shellLink->SetPath(path);
// default to using the first icon in the exe (usually correct)
if (exePath != NULL)
shellLink->SetIconLocation(exePath, 0);
if (args != NULL) if (args != NULL)
shellLink->SetArguments(args); shellLink->SetArguments(args);
if (workingDir != NULL) if (workingDir != NULL)

View File

@ -39,6 +39,7 @@ mod natives {
path: *const winapi::ctypes::wchar_t, path: *const winapi::ctypes::wchar_t,
args: *const winapi::ctypes::wchar_t, args: *const winapi::ctypes::wchar_t,
workingDir: *const winapi::ctypes::wchar_t, workingDir: *const winapi::ctypes::wchar_t,
exePath: *const winapi::ctypes::wchar_t,
) -> ::std::os::raw::c_int; ) -> ::std::os::raw::c_int;
pub fn isDarkThemeActive() -> ::std::os::raw::c_uint; pub fn isDarkThemeActive() -> ::std::os::raw::c_uint;
@ -59,6 +60,7 @@ mod natives {
target: &str, target: &str,
args: &str, args: &str,
working_dir: &str, working_dir: &str,
exe_path: &str,
) -> Result<String, String> { ) -> Result<String, String> {
let source_file = format!( let source_file = format!(
"{}\\Microsoft\\Windows\\Start Menu\\Programs\\{}.lnk", "{}\\Microsoft\\Windows\\Start Menu\\Programs\\{}.lnk",
@ -78,6 +80,8 @@ mod natives {
U16CString::from_str(args).log_expect("Error while converting to wchar_t"); U16CString::from_str(args).log_expect("Error while converting to wchar_t");
let native_working_dir = let native_working_dir =
U16CString::from_str(working_dir).log_expect("Error while converting to wchar_t"); U16CString::from_str(working_dir).log_expect("Error while converting to wchar_t");
let native_exe_path =
U16CString::from_str(exe_path).log_expect("Error while converting to wchar_t");
let shortcutResult = unsafe { let shortcutResult = unsafe {
saveShortcut( saveShortcut(
@ -86,6 +90,7 @@ mod natives {
native_target.as_ptr(), native_target.as_ptr(),
native_args.as_ptr(), native_args.as_ptr(),
native_working_dir.as_ptr(), native_working_dir.as_ptr(),
native_exe_path.as_ptr(),
) )
}; };

View File

@ -58,6 +58,7 @@ impl Task for InstallGlobalShortcutsTask {
// TODO: Send by list // TODO: Send by list
"", "",
&starting_dir, &starting_dir,
"",
)?; )?;
if !shortcut_file.is_empty() { if !shortcut_file.is_empty() {

View File

@ -83,6 +83,7 @@ impl Task for InstallShortcutsTask {
// TODO: Send by list // TODO: Send by list
&format!("--launcher \"{}\"", exe_path), &format!("--launcher \"{}\"", exe_path),
&starting_dir, &starting_dir,
exe_path,
)?); )?);
} }