1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//! A library for modding Electron apps in-memory, without modifying any program files.
//!
//! This library was made for improving the modding experience for Discord, but it can be used for any Electron app.
//!
//! # Features
//!
//! - `asar`: Enables the ASAR archive builder. (enabled by default)
//! - `uuid`: Enables the use of random UUIDs for ASAR archive names. (enabled by default)
//!
//! # Examples
//!
//! electron-hook maps the original `app.asar` to `_app.asar`,
//! so keep this in mind if you need to call the original file anywhere,
//! as shown in this example.
//!
//! ```rust,ignore
//! use electron_hook::asar::Asar;
//!
//! let mod_dir = mod_artifact_dir("moonlight");
//!
//! let _download_url = "https://github.com/moonlight-mod/moonlight/releases/latest/download/dist.tar.gz";
//! // extract and save `_download_url` into `mod_dir`
//!
//! let mod_entrypoint = mod_dir.join("injector.js");
//!
//! let template = r#"
//! console.log("Mod injected!!!");
//! let asar = require("path").resolve(__dirname, "../_app.asar");
//! require(process.env.MODLOADER_MOD_ENTRYPOINT).inject(asar);
//! "#;
//!
//! // Create the asar file
//! let asar = Asar::new()
//! .with_id("moonlight")
//! .with_template(template)
//! .with_mod_entrypoint(mod_dir)
//! .create()
//! .unwrap();
//!
//! electron_hook::launch(
//! "/path/to/executable/Discord",
//! asar.path().to_str().unwrap(),
//! vec!["--pass-arguments-here"],
//! None, // Optional profile directory
//! true, // Detach the process
//! );
//! ```
// For Linux
// For Windows
// TODO: Re-implement Windows support.
// TODO: For MacOS
/// Launches an Electron executable with the provided information.
///
/// `id` on Linux: the path to the executable.
///
/// `id` on Windows: the path to the directory containing `Update.exe`.
///
/// `library_path`: The path to the electron-hook `.so` or `.dll`
///
/// `asar_path`: The path to the ASAR file to inject
///
/// `args`: Arguments to pass to the executable
///
/// `detach`: It is recommended to set `detach` to true to prevent the process from dying when the parent process is closed.
/// Launches an Electron executable through Flatpak with the provided information.
///
/// This is only available on Linux.
///
/// TODO: This only supports global packages. Are --user flatpak packages handled differently?
///
/// `id`: The ID of the flatpak package.
///
/// `library_path`: The path to the electron-hook `.so` or `.dll`
///
/// `asar_path`: The path to the ASAR file to inject
///
/// `args`: Arguments to pass to the executable
///
/// `detach`: It is recommended to set `detach` to true to prevent the process from dying when the parent process is closed.
/// The ID of a Flatpak package.