Skip to content

Commit

Permalink
Redo shortcut buttons in Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb Smith committed Jun 28, 2022
1 parent 2c6d5ba commit 9559fba
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
2 changes: 2 additions & 0 deletions bcml/assets/src/js/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ class Settings extends React.Component {

makeShortcut = async desktop => {
try {
this.props.onProgress("Creating shortcut...");
await pywebview.api.make_shortcut({ desktop });
this.props.onDone();
} catch (error) {
this.props.onError(error);
}
Expand Down
25 changes: 14 additions & 11 deletions bcml/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
from oead.aamp import ParameterIO, ParameterList # pylint:disable=import-error
from webview import Window # pylint: disable=wrong-import-order

from bcml import pickles, DEBUG # pylint: disable=unused-import
from bcml import bcml as rsext
from bcml import pickles, DEBUG # pylint: disable=unused-import
from bcml.__version__ import VERSION


Expand Down Expand Up @@ -1237,16 +1238,18 @@ def create_bcml_graphicpack_if_needed():


def create_shortcuts(desktop: bool, start_menu: bool):
from pycrosskit.shortcuts import Shortcut

Shortcut(
"BCML",
shutil.which("bcml"),
"BOTW Cross-Platform Mod Loader",
str(get_exec_dir() / "data" / "bcml.ico"),
desktop,
start_menu,
)
if desktop:
rsext.manager.create_shortcut(
str(get_python_exe(True)),
str(get_exec_dir() / "data" / "bcml.ico"),
str(Path(r"~\Desktop\BCML.lnk").expanduser())
)
if start_menu:
rsext.manager.create_shortcut(
str(get_python_exe(True)),
str(get_exec_dir() / "data" / "bcml.ico"),
str(Path(r"~\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\BCML.lnk").expanduser())
)


def download_webview2():
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ dependencies = [
"botw-havok~=0.3.18",
"oead~=1.2.4",
"packaging~=21.3",
"pycrosskit~=1.0.4.1",
"pythonnet~=2.5.2; platform_system == 'Windows' and python_version < '3.9'",
"pythonnet>=3.0.0rc1; platform_system == 'Windows' and python_version >= '3.9'",
"pyqtwebengine~=5.15.2; platform_system == 'Linux'",
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ botw-utils~=0.2.3
botw-havok~=0.3.18
oead~=1.2.0
packaging~=21.3
pycrosskit~=1.0.4.1
pythonnet~=2.5.2; platform_system == 'Windows' and python_version < "3.9"
pythonnet>=3.0.0rc1; platform_system == 'Windows' and python_version >= "3.9"
PyQt5; platform_system == 'Linux'
Expand Down
19 changes: 19 additions & 0 deletions src/manager.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
use crate::{util, Result};
use anyhow::Context;
use join_str::jstr;
#[cfg(windows)]
use mslnk::ShellLink;
use pyo3::prelude::*;
use rayon::prelude::*;
use std::{collections::BTreeSet, path::PathBuf};

pub fn manager_mod(py: Python, parent: &PyModule) -> PyResult<()> {
let manager_module = PyModule::new(py, "manager")?;
#[cfg(windows)]
manager_module.add_wrapped(wrap_pyfunction!(create_shortcut))?;
manager_module.add_wrapped(wrap_pyfunction!(link_master_mod))?;
parent.add_submodule(manager_module)?;
Ok(())
}

#[cfg(windows)]
#[pyfunction]
fn create_shortcut(_py: Python, py_path: String, ico_path: String, dest: String) -> PyResult<()> {
let make = || -> anyhow::Result<()> {
let mut link = ShellLink::new(&py_path)?;
link.set_arguments(Some("-m bcml".into()));
link.set_name(Some("BCML".into()));
link.set_icon_location(Some(ico_path));
std::fs::create_dir_all(std::path::Path::new(&dest).parent().unwrap())?;
link.create_lnk(&dest)?;
Ok(())
};
Ok(make()?)
}

#[pyfunction]
fn link_master_mod(py: Python, output: Option<String>) -> PyResult<()> {
if let Some(output) = output
Expand Down

0 comments on commit 9559fba

Please sign in to comment.