Skip to main content

Asar

Struct Asar 

Source
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: TODO

Fields§

§id: String

The 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: String

The 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 VariableDescriptionNotes
MODLOADER_EXECUTABLESpecifies the path to the Modloader executable.
MODLOADER_MOD_ENTRYPOINTThe path to the entrypoint of the mod.
MODLOADER_ASAR_IDThe name of the ASAR ID selected
MODLOADER_ASAR_PATHThe path to the ASAR file.
MODLOADER_LIBRARY_PATHThe path to the .dll or .so.
MODLOADER_ORIGINAL_ASAR_RELATIVEThe relative path to the original ASAR fileIs always ../_app.asar
MODLOADER_PROFILE_DIRThe path to the custom profile directoryOptional
MODLOADER_WM_CLASSThe WM_CLASS of the Electron application.Optional
MODLOADER_FOLDER_NAMEthe app- folder nameWindows 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: String

The 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: TODO
§profile_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: TODO

Implementations§

Source§

impl Asar

Source

pub fn new() -> Self

Create a new Asar builder.

Source

pub fn get_path(&self) -> Option<PathBuf>

Get the path to the ASAR archive.

Source

pub fn with_uuid(self) -> Self

Generate a random UUID for the ASAR archive to use.

Source

pub fn with_id(self, id: &str) -> Self

Provide a reusable ID for the ASAR archive to use.

See Asar::id

Source

pub fn with_template(self, template: &str) -> Self

Provide the template for your index.js to use

See Asar::template

Source

pub fn with_mod_entrypoint(self, mod_entrypoint: &str) -> Self

Provide the entrypoint for your mod.

See Asar::mod_entrypoint

Source

pub fn with_wm_class(self, wm_class: &str) -> Self

Provide the WM_CLASS of the application on launch.

See Asar::wm_class

Source

pub fn with_profile_dir(self, profile_dir: &str) -> Self

Provide the profile directory for your mod.

See Asar::profile_dir

Source

pub fn create(&self) -> Result<PathBuf, String>

Create the ASAR file and write it to disk, returning the path to the ASAR file.

See Usage for how the path is generated.

Trait Implementations§

Source§

impl Debug for Asar

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Asar

Source§

fn default() -> Asar

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Asar

§

impl RefUnwindSafe for Asar

§

impl Send for Asar

§

impl Sync for Asar

§

impl Unpin for Asar

§

impl UnsafeUnpin for Asar

§

impl UnwindSafe for Asar

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.