Skip to content

Commit

Permalink
option to open epub from window explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
mienaiyami committed Apr 26, 2023
1 parent 54e9d85 commit c19febf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 24 deletions.
66 changes: 44 additions & 22 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,31 @@ const addOptionToExplorerMenu = () => {
if (error) log.error(error);
});
};
// registry, remove option "open in reader" in explorer context menu
const deleteOldOptionInExplorerMenu = () => {
const regDelete = `Windows Registry Editor Version 5.00
[-HKEY_CURRENT_USER\\Software\\Classes\\directory\\shell\\MangaReader]
const addOptionToExplorerMenu_epub = () => {
app;
const appPath = IS_PORTABLE
? app.getPath("exe").replace(/\\/g, "\\\\")
: path.join(app.getPath("exe"), `../../${app.name}.exe`).replace(/\\/g, "\\\\");
const regInit = `Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\\.cbz\\shell\\MangaReader]
[-HKEY_CLASSES_ROOT\\MangaReader]
[HKEY_CLASSES_ROOT\\.epub\\shell\\Yomikiru]
@="Open in Yomikiru"
"Icon"="${appPath}"
[HKEY_CLASSES_ROOT\\.zip\\OpenWithProgids]
"MangaReader"=-
[HKEY_CLASSES_ROOT\\.epub\\shell\\Yomikiru\\command]
@="\\"${appPath}\\" \\"%V\\""
`;
fs.writeFileSync(path.join(app.getPath("temp"), "deleteOpenWithMangaReader.reg"), regDelete);

const tempPath = app.getPath("temp");
fs.writeFileSync(path.join(tempPath, "createOpenWithYomikiru-epub.reg"), regInit);

const op = {
name: "MangaReader",
name: "Yomikiru",
icns: app.getPath("exe"),
};
sudo.exec(
"regedit.exe /S " + path.join(app.getPath("temp"), "deleteOpenWithMangaReader.reg"),
op,
function (error) {
if (error) log.error(error);
}
);
sudo.exec("regedit.exe /S " + path.join(tempPath, "createOpenWithYomikiru-epub.reg"), op, function (error) {
if (error) log.error(error);
});
};
const deleteOptionInExplorerMenu = () => {
const regDelete = `Windows Registry Editor Version 5.00
Expand All @@ -133,6 +133,25 @@ const deleteOptionInExplorerMenu = () => {
}
);
};
const deleteOptionInExplorerMenu_epub = () => {
const regDelete = `Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\\.epub\\shell\\Yomikiru]
`;
fs.writeFileSync(path.join(app.getPath("temp"), "deleteOpenWithYomikiru-epub.reg"), regDelete);
const op = {
name: "Yomikiru",
icns: app.getPath("exe"),
};
sudo.exec(
"regedit.exe /S " + path.join(app.getPath("temp"), "deleteOpenWithYomikiru-epub.reg"),
op,
function (error) {
if (error) log.error(error);
}
);
};

const handleSquirrelEvent = () => {
if (process.argv.length === 1) {
Expand Down Expand Up @@ -185,8 +204,8 @@ const handleSquirrelEvent = () => {
fs.unlinkSync(
path.resolve(homedir(), "AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Yomikiru.lnk")
);
deleteOldOptionInExplorerMenu();
deleteOptionInExplorerMenu();
deleteOptionInExplorerMenu_epub();
if (fs.existsSync(path.resolve(homedir(), "Desktop/Yomikiru.lnk")))
fs.unlinkSync(path.resolve(homedir(), "Desktop/Yomikiru.lnk"));
const uninstallFull = `
Expand Down Expand Up @@ -354,8 +373,11 @@ const registerListener = () => {
ipcMain.on("deleteOptionInExplorerMenu", () => {
deleteOptionInExplorerMenu();
});
ipcMain.on("deleteOldOptionInExplorerMenu", () => {
deleteOldOptionInExplorerMenu();
ipcMain.on("addOptionToExplorerMenu:epub", () => {
addOptionToExplorerMenu_epub();
});
ipcMain.on("deleteOptionInExplorerMenu:epub", () => {
deleteOptionInExplorerMenu_epub();
});
}
if (process.platform === "linux") {
Expand Down
12 changes: 10 additions & 2 deletions src/Components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -522,12 +522,20 @@ const Settings = (): ReactElement => {
>
Remove
</button>

<button
onClick={() =>
window.electron.ipcRenderer.send("addOptionToExplorerMenu:epub")
}
>
Add(EPub)
</button>
<button
onClick={() =>
window.electron.ipcRenderer.send("deleteOldOptionInExplorerMenu")
window.electron.ipcRenderer.send("deleteOptionInExplorerMenu:epub")
}
>
Remove(Old version)
Remove(EPub)
</button>
</td>
</tr>
Expand Down

0 comments on commit c19febf

Please sign in to comment.