Skip to content

Commit e749bf4

Browse files
committed
chore: refactor a bit
1 parent d3e1f37 commit e749bf4

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/main/asar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ export function unpackAsar(dir: string, file: string): string {
66
const filePath = join(dir, file);
77
const unpackedName = `${filePath}.unpacked`;
88
try {
9-
if (statSync(filePath).isDirectory() || !filePath.endsWith(".asar")) return file;
9+
if (statSync(filePath).isDirectory() || !filePath.endsWith(".asar")) return filePath;
1010
extractAll(filePath, unpackedName);
1111
rmSync(filePath);
1212
} catch (err) {
1313
console.log(err);
1414
}
1515
console.log(`Asar ${filePath} replaced with folder`);
16-
return `${file}.unpacked`;
16+
return unpackedName;
1717
}

src/main/ipc/installer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,11 @@ export async function installAddon(
235235

236236
try {
237237
if (existsSync(filePath)) rmSync(filePath, { recursive: true, force: true });
238+
238239
const unpacked = `${filePath}.unpacked`;
239-
if (existsSync(unpacked)) rmSync(unpacked, { recursive: true, force: true });
240+
if (path.endsWith(".unpacked") && existsSync(unpacked))
241+
rmSync(unpacked, { recursive: true, force: true });
242+
240243
await writeFile(filePath, buf);
241244
} catch (err) {
242245
return {

src/main/ipc/plugins.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ export const isFileAPlugin = (f: Dirent | Stats, name: string): boolean => {
2020
};
2121

2222
function getPlugin(pluginName: string): RepluggedPlugin {
23-
pluginName = unpackAsar(PLUGINS_DIR, pluginName);
24-
const pluginPath = join(PLUGINS_DIR, pluginName);
23+
const pluginPath = unpackAsar(PLUGINS_DIR, pluginName);
2524
const manifestPath = join(pluginPath, "manifest.json");
2625
if (!manifestPath.startsWith(`${PLUGINS_DIR}${sep}`)) {
2726
// Ensure file changes are restricted to the base path

src/main/ipc/themes.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ export const isFileATheme = (f: Dirent | Stats, name: string): boolean => {
2020
};
2121

2222
async function getTheme(path: string): Promise<RepluggedTheme> {
23-
path = unpackAsar(THEMES_DIR, path);
24-
25-
const themePath = join(THEMES_DIR, path);
23+
const themePath = unpackAsar(THEMES_DIR, path);
2624
const manifestPath = join(themePath, "manifest.json");
2725
if (!manifestPath.startsWith(`${THEMES_DIR}${sep}`)) {
2826
// Ensure file changes are restricted to the base path

0 commit comments

Comments
 (0)