pub struct Asar {
pub id: String,
pub template: String,
pub wm_class: Option<String>,
pub mod_entrypoint: String,
pub profile_dir: Option<String>,
}Expand description
A builder for creating ASAR archives and writing them to the filesystem.
§Usage
use electron_hook::asar::Asar;
use electron_hook::paths::{mod_artifact_dir, data_profile_dir};
let entrypoint = mod_artifact_dir("vencord").join("patcher.js");
let profile_dir = data_profile_dir("vencord");
let asar = Asar::new()
.with_id("vencord-release")
.with_template("require(process.env.MODLOADER_MOD_ENTRYPOINT);")
.with_mod_entrypoint(entrypoint.to_str().unwrap())
.with_profile_dir(profile_dir.to_str().unwrap()) // Optional
.create();
// Linux: /home/CoolPerson/.cache/electron-hook/asar/vencord-release.asar
// Windows: C:/Users/CoolPerson/AppData/Local/electron-hook/asar/vencord-release.asar
// MacOS: TODOFields§
§id: StringThe unique identifier for the ASAR archive.
e.g. if this is set to my-mod-name, the final name will be {id}.asar.
This can either be a random UUID (with the uuid feature) or a custom reusable ID.
The final path will be something like:
Linux: /home/CoolPerson/.cache/electron-hook/asar/my-mod-name.asar
Windows: C:/Users/CoolPerson/AppData/Local/electron-hook/asar/my-mod-name.asar
MacOS: TODO
template: StringThe template for the index.js that will go into the ASAR archive.
There are multiple environment variables that can be used in the template:
| Environment Variable | Description | Notes |
|---|---|---|
MODLOADER_EXECUTABLE | Specifies the path to the Modloader executable. | |
MODLOADER_MOD_ENTRYPOINT | The path to the entrypoint of the mod. | |
MODLOADER_ASAR_ID | The name of the ASAR ID selected | |
MODLOADER_ASAR_PATH | The path to the ASAR file. | |
MODLOADER_LIBRARY_PATH | The path to the .dll or .so. | |
MODLOADER_ORIGINAL_ASAR_RELATIVE | The relative path to the original ASAR file | Is always ../_app.asar |
MODLOADER_PROFILE_DIR | The path to the custom profile directory | Optional |
MODLOADER_WM_CLASS | The WM_CLASS of the Electron application. | Optional |
MODLOADER_FOLDER_NAME | the app- | Windows only |
For a basic implementation, you want to at least require your mod, e.g.:
require(process.env.MODLOADER_MOD_ENTRYPOINT);wm_class: Option<String>The WM_CLASS of the application that the mod is for.
You can use this to make it show as a different application on your Linux taskbar.
This (probably) has no effect on Windows.
mod_entrypoint: StringThe entrypoint for the mod. This should be the path to the main file for your mod.
Preferably, you should get the path using [electron_hook::paths::mod_artifact_dir]
You can use it like so:
use electron_hook::paths::mod_artifact_dir;
let entrypoint = mod_artifact_dir("vencord").join("patcher.js");
// Linux: /home/CoolPerson/.cache/electron-hook/mods/vencord/patcher.js
// Windows: C:/Users/CoolPerson/AppData/Local/electron-hook/mods/vencord/patcher.js
// MacOS: TODOprofile_dir: Option<String>An optional alternative profile for the mod.
A profile is a unique instance of an application’s data directory - meaning separate settings, cache, chromium instance, etc. You do not need to use this for basic installs, but if you want to run multiple instances of the same client with different mods or settings, you can use this.
Preferably, you should get the path using [electron_hook::paths::data_profile_dir]
You can use it like so:
use electron_hook::paths::data_profile_dir;
let profile_dir = data_profile_dir("moonlight");
// Linux: /home/CoolPerson/.local/share/electron-hook/profiles/moonlight
// Windows: C:/Users/CoolPerson/AppData/Roaming/electron-hook/profiles/moonlight
// MacOS: TODOImplementations§
Source§impl Asar
impl Asar
Sourcepub fn with_id(self, id: &str) -> Self
pub fn with_id(self, id: &str) -> Self
Provide a reusable ID for the ASAR archive to use.
See Asar::id
Sourcepub fn with_template(self, template: &str) -> Self
pub fn with_template(self, template: &str) -> Self
Provide the template for your index.js to use
See Asar::template
Sourcepub fn with_mod_entrypoint(self, mod_entrypoint: &str) -> Self
pub fn with_mod_entrypoint(self, mod_entrypoint: &str) -> Self
Provide the entrypoint for your mod.
Sourcepub fn with_wm_class(self, wm_class: &str) -> Self
pub fn with_wm_class(self, wm_class: &str) -> Self
Provide the WM_CLASS of the application on launch.
See Asar::wm_class
Sourcepub fn with_profile_dir(self, profile_dir: &str) -> Self
pub fn with_profile_dir(self, profile_dir: &str) -> Self
Provide the profile directory for your mod.