Skip to content

Commit

Permalink
added custom temp folder
Browse files Browse the repository at this point in the history
  • Loading branch information
mienaiyami committed Jul 14, 2023
1 parent 4dee917 commit 2fe1e8b
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 9 deletions.
32 changes: 23 additions & 9 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,32 @@

**Due to release changes, existing users (v2.11.5 and below) might need to manually update the app.**

<!-- ## Added
## Added

- EPUB : Collapsible tiles for side list. #190 -->
- Option to hide extra data when hovering bookmark/history. Added "path" to extra data.
- Double click in center of screen to enter zen mode.
- Auto refresh reader side-list option.
- Custom temp folder. Might improve extracting speed in some cases.

## Changed

- UI Changes in settings.
- Reverted theme selector.
- Moved force low brightness to other settings.

<!-- ## Fixed
- Unable to open folders ending with supported extension names. -->
- UI Changes.
- Symmetric theme selector and more.
- Slider/range UI change.
- Fade and scale in effect on anilist popups.
- Moved file saving to backend, single handler.
- Moved un-zipper to backend.
- Don't show variable same as property name when linking in theme maker.
- Issue link in settings.
- Replaced RGB sliders in "color filters" with color input.
- Show EPUB chapter name on title when "Epub : Load By Chapter" selected.
- Show image count instead of "No Directories" on home locations tab.

## Fixed

- Multiple settings rewrite on opening reader.
- EPUB progress saving issue, maybe. #134.
- EPUB chapter not auto focusing when reading in zen mode. #177.
- Error after refreshing reader side-list and changing chapter if any folder is changed in default location.

---
11 changes: 11 additions & 0 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ if (IS_PORTABLE) {
////18/05/23 - decided to not use it anymore as it make scrolling laggy
if (fs.existsSync(path.join(app.getPath("userData"), "DISABLE_HARDWARE_ACCELERATION")))
app.disableHardwareAcceleration();
if (fs.existsSync(path.join(app.getPath("userData"), "TEMP_PATH"))) {
const tempPath = fs.readFileSync(path.join(app.getPath("userData"), "TEMP_PATH"), "utf-8");
if (fs.existsSync(tempPath)) app.setPath("temp", tempPath);
else fs.rmSync(tempPath);
}

// change path in `settings.tsx as well if changing log path
log.transports.file.resolvePath = () => path.join(app.getPath("userData"), "logs/main.log");
Expand Down Expand Up @@ -394,6 +399,12 @@ const registerListener = () => {
deleteOptionInExplorerMenu_epub();
});
}
ipcMain.handle("changeTempPath", (e, newPath: string) => {
app.setPath("temp", newPath);
const lockFile = path.join(app.getPath("userData"), "TEMP_PATH");
if (newPath === process.env.TEMP && fs.existsSync(lockFile)) fs.rmSync(lockFile);
fs.writeFileSync(lockFile, newPath);
});
if (process.platform === "linux") {
ipcMain.on("showInExplorer", (e, filePath) => {
if (!fs.lstatSync(filePath).isDirectory()) filePath = path.dirname(filePath);
Expand Down
65 changes: 65 additions & 0 deletions src/Components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const Settings = (): ReactElement => {
const [currentTab, setCurrentTab] = useState(0);

const [anilistUsername, setAnilistUsername] = useState("Error");
const [tempFolder, setTempFolder] = useState(window.electron.app.getPath("temp"));

// disabled hardware acceleration
const [HAValue, setHAValue] = useState(
Expand All @@ -58,6 +59,19 @@ const Settings = (): ReactElement => {
}
}, [isSettingOpen]);

useEffect(() => {
if (tempFolder !== window.electron.app.getPath("temp"))
try {
if (window.fs.existsSync(tempFolder)) {
window.electron.ipcRenderer.invoke("changeTempPath", tempFolder).then(() => {
window.logger.log("Temp path changed to", tempFolder);
});
} else throw new Error("Folder does not exist : " + tempFolder);
} catch (reason) {
window.logger.error("Unable to change temp path.", reason);
}
}, [tempFolder]);

useEffect(() => {
if (anilistToken)
window.al.getUserName().then((name) => {
Expand Down Expand Up @@ -1028,6 +1042,56 @@ const Settings = (): ReactElement => {
</button>
</div>
</div>
<div className="settingItem2">
<h3>Custom Temp Folder</h3>
<div className="desc">
Folder where app will extract archives or epub or render pdf. It can have big
effect on extracting speed depending on type of drive (ssd, faster drives) or
storage left (10GB+ recommended).
<br /> Defaults to temp folder provided by OS.
</div>
<div className="main row">
<input
type="text"
placeholder="No path Selected"
value={tempFolder}
readOnly
/>
<button
// onFocus={(e) => e.currentTarget.blur()}
onClick={(e) => {
promptSelectDir((path) => {
setTempFolder(path);
// const target = e.currentTarget;
// target.innerText = "Applying...";
// setTimeout(() => {
// window.location.reload();
// // target.innerText = "Select";
// }, 3000);
});
}}
>
Select
</button>
<button
onClick={(e) => {
if (process.env.TEMP) setTempFolder(process.env.TEMP);
else
window.dialog.customError({
message: "Unable to get default temp path.",
});
// const target = e.currentTarget;
// target.innerText = "Applying...";
// setTimeout(() => {
// window.location.reload();
// // target.innerText = "Clear";
// }, 3000);
}}
>
Default
</button>
</div>
</div>
<div className="settingItem2 otherSettings">
<h3>Other Settings</h3>
<div className="toggleItem">
Expand Down Expand Up @@ -1505,6 +1569,7 @@ const Settings = (): ReactElement => {
</code>
.
</li>
<li>Double click in center 20% of window to toggle zen mode.</li>
</ul>
</li>
<li>
Expand Down

0 comments on commit 2fe1e8b

Please sign in to comment.