Skip to content

Commit

Permalink
temp fix #287
Browse files Browse the repository at this point in the history
  • Loading branch information
mienaiyami committed Sep 25, 2023
1 parent 9859582 commit 1f7d59f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 83 deletions.
1 change: 0 additions & 1 deletion forge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import fs from "fs";
const config: ForgeConfig = {
packagerConfig: {
name: "Yomikiru",
//todo check if need to change bin for linux
asar: true,
executableName: process.platform === "win32" ? "Yomikiru" : "yomikiru",
},
Expand Down
9 changes: 0 additions & 9 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ import { setAniSearchOpen } from "./store/isAniSearchOpen";
import { setAnilistCurrentManga } from "./store/anilistCurrentManga";
import { toggleOpenSetting } from "./store/isSettingOpen";

// window.logger.log("New window opening...");

// todo: why was i exporting this?
// export { themesMain };

interface IAppContext {
pageNumberInputRef: React.RefObject<HTMLInputElement>;
bookProgressRef: React.RefObject<HTMLInputElement>;
Expand Down Expand Up @@ -464,14 +459,10 @@ const App = (): ReactElement => {
if (appSettings.syncThemes) filesToWatch.push(themesPath);
const watcher = window.chokidar.watch(filesToWatch);
watcher.on("change", (path) => {
// // todo: make it to ignore first call if another called within 2sec
// setTimeout(() => {
//todo test is removing timeout cause issues
if (path === historyPath) dispatch(refreshHistory());
if (path === bookmarksPath) dispatch(refreshBookmark());
if (path === settingsPath) dispatch(refreshAppSettings());
if (path === themesPath) dispatch(refreshThemes());
// }, 1500);
});

window.addEventListener("keydown", eventsOnStart);
Expand Down
2 changes: 0 additions & 2 deletions src/renderer/Components/Element/InputColorReal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ const InputColorReal = () => {
(e.relatedTarget && e.relatedTarget.getAttribute("data-focus-guard") === "true")
)
return;
// colorSelectData.focusBackElem && colorSelectData.focusBackElem.focus();
//todo, check if creates any issue or move to FocusLock
colorSelectData.onBlur && colorSelectData.onBlur(e);
setColorSelectData(null);
}}
Expand Down
76 changes: 30 additions & 46 deletions src/renderer/Components/Reader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const Reader = () => {

const [images, setImages] = useState<string[]>([]);
const [imageWidthContainer, setImageWidthContainer] = useState<
{ index: number; isWide: boolean; img: HTMLCanvasElement | HTMLImageElement }[]
{ index: number; isWide: boolean; img: HTMLCanvasElement | HTMLImageElement | string }[]
>([]);
// take element from `imageWidthContainer` using index
const [imageElementsIndex, setImageElementsIndex] = useState<number[][]>([]);
Expand Down Expand Up @@ -601,7 +601,11 @@ const Reader = () => {
setImagesLoaded((init) => init + 1);
setImageWidthContainer((init) => [
...init,
{ img, index: i, isWide: success ? img.height / img.width <= 1.2 : false },
{
img: dynamic ? "file://" + e.replaceAll("#", "%23") : img,
index: i,
isWide: success ? img.height / img.width <= 1.2 : false,
},
]);
};
if (appSettings.useCanvasBasedReader) {
Expand Down Expand Up @@ -640,28 +644,17 @@ const Reader = () => {
setImagesLoaded((init) => init + 1);
setImageWidthContainer((init) => [...init, { img: canvas, index: i, isWide: false }]);
};
} else {
} else if (!dynamic) {
img.setAttribute("draggable", "false");
img.setAttribute("data-pagenumber", JSON.stringify(i + 1));
if (dynamic) {
img.loading = "lazy";
img.height = window.innerHeight - 50;
img.width = window.innerHeight / 1.5;
}
img.classList.add("readerImg");

img.onload = (e) => {
if (dynamic) {
(e.target as HTMLImageElement).removeAttribute("height");
(e.target as HTMLImageElement).removeAttribute("width");
(e.target as HTMLImageElement).style.opacity = "1";
} else {
setImageDecodeQueue((init) => {
init.push(img);
return [...init];
});
loaded(true);
}
setImageDecodeQueue((init) => {
init.push(img);
return [...init];
});
loaded(true);
};
img.onerror = () => {
!dynamic && loaded();
Expand All @@ -671,22 +664,22 @@ const Reader = () => {
};
}
if (dynamic) {
img.setAttribute("data-src", "file://" + e.replaceAll("#", "%23"));
img.style.opacity = "0";
dynamic && loaded(true);
loaded(true);
} else {
img.src = "file://" + e.replaceAll("#", "%23");
}
});
}, [images]);
useEffect(() => {
//todo use just src for image and canvas, add canvas using element outside
[...document.querySelector("section.imgCont")!.children].forEach((e, i) => {
imageElementsIndex[i].forEach((canvasIndex) => {
const elem = imageWidthContainer[canvasIndex].img;
if (elem instanceof HTMLElement) e.appendChild(elem);
});
});
}, [imageElementsIndex]);
//todo improve
useLayoutEffect(() => {
if (imagesLength > 0 && imagesLength === imageWidthContainer.length) {
imageWidthContainer.sort((a, b) => a.index - b.index);
Expand Down Expand Up @@ -747,15 +740,7 @@ const Reader = () => {
useEffect(() => {
if (imagesLoaded !== 0 && imagesLength !== 0) {
dispatch(setLoadingMangaPercent((100 * imagesLoaded) / imagesLength));
if (imagesLength === imagesLoaded) {
dispatch(setLoadingManga(false));
// console.log(currentPageNumber);
// setFirstScrolled(true);
// scrollToPage(currentPageNumber, "auto");
// setTimeout(() => {
// scrollToPage(currentPageNumber, "auto");
// }, 3000);
}
if (imagesLength === imagesLoaded) dispatch(setLoadingManga(false));
}
}, [imagesLoaded]);
useLayoutEffect(() => {
Expand Down Expand Up @@ -854,16 +839,6 @@ const Reader = () => {
if (clickPos > 60) openPrevPageRef.current?.click();
}
}

// const clickPos =
// ((e.clientX - (isSideListPinned ? sideListWidth : 0)) / e.currentTarget.offsetWidth) * 100;
// if (appSettings.readerSettings.readerTypeSelected === 0) {
// if (clickPos <= 40) openPrevChapterRef.current?.click();
// if (clickPos > 60) openNextChapterRef.current?.click();
// } else {
// if (clickPos <= 40) openPrevPageRef.current?.click();
// if (clickPos > 60) openNextPageRef.current?.click();
// }
}}
>
<div className="wrapper">
Expand Down Expand Up @@ -1175,7 +1150,6 @@ const Reader = () => {
}}
>
{imageElementsIndex.map((e, i) => {
//todo check it is cause performance issue for !dynamic
const props = {
className:
"row " +
Expand All @@ -1200,9 +1174,6 @@ const Reader = () => {
!appSettings.readerSettings.widthClamped
? appSettings.readerSettings.maxHeight + "px"
: "auto",
height: appSettings.readerSettings.dynamicLoading
? `${window.innerHeight - 50}px`
: "auto",
},
key: i,
};
Expand All @@ -1226,7 +1197,20 @@ const Reader = () => {
// unloading image does not free ram
}}
{...props}
></InView>
>
{imageElementsIndex[i].map(
(e) =>
typeof imageWidthContainer[e].img === "string" && (
<img
className="readerImg"
draggable={false}
data-pagenumber={imageWidthContainer[e].index + 1}
loading="lazy"
data-src={imageWidthContainer[e].img}
/>
)
)}
</InView>
);
return <div {...props}></div>;
})}
Expand Down
7 changes: 1 addition & 6 deletions src/renderer/MainImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,6 @@ export const settingValidatorData = {
const themeProps = themeJSON.allData[0].main;

const formats = {
/**
* Supported image formats.
*/
image: {
list: [".jpg", ".jpeg", ".png", ".webp", ".svg", ".apng", ".gif", ".avif"],
test: function (str: string) {
Expand Down Expand Up @@ -433,7 +430,7 @@ declare global {
// todo: fix
// todo: make better way to do this
/**
* why did i add this? bcoz fking linkInReader state is showing initial only in App.tsx
* why did i add this? bcoz linkInReader state is showing initial only in App.tsx
*/
linkInReader: {
type: "image" | "book" | "";
Expand Down Expand Up @@ -1198,8 +1195,6 @@ export function promptSelectDir(
});

if (!result) return;
// todo, why need window.path.sep
// const path = asFile ? (multi ? result : result[0]) : window.path.normalize(result[0] + window.path.sep);
const path = asFile ? (multi ? result : result[0]) : window.path.normalize(result[0]);
cb && cb(path);
}
Expand Down
19 changes: 0 additions & 19 deletions src/renderer/store/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,6 @@ const history = createSlice({
}
saveJSONfile(historyPath, stateDup);
},
// todo: getlink from state directly;
// todo: fix; when called in App.tsx linkInReader is initialVlue even if changed
// updateLastHistoryPage: (state, action: PayloadAction<{ linkInReader: string }>) => {
// const index = state.findIndex((e) => e.link === action.payload.linkInReader);
// // todo : removed ` || action.payload.linkInReader === ""`; check consequences
// // not working on closing window
// // use sth like window.lastMangaOpened;
// window.logger.log("asking to save ", action.payload);
// if (index > -1) {
// console.log(`Updating ${state[index].mangaName} to page ${window.app.currentPageNumber}`);
// state[index].page = window.app.currentPageNumber;
// saveJSONfile(historyPath, state);
// }
// },

/**
* only for manga/image reader
Expand All @@ -146,11 +132,6 @@ const history = createSlice({
const link = window.app.linkInReader.link;
const index = stateDup.findIndex((e) => e.data.link === link);
if (index > -1) {
// console.log(
// `Updating ${(stateDup[index] as MangaHistoryItem).data.mangaName} to page ${
// window.app.currentPageNumber
// }`
// );
(stateDup[index] as MangaHistoryItem).data.page = window.app.currentPageNumber;
saveJSONfile(historyPath, stateDup);
}
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2835,6 +2835,12 @@ body {
transform: translate3d(0, 0, 0);
image-orientation: none;
max-width: var(--max-width);
&::not([src]) {
width: calc(100vh - 50px);
height: calc(100vh / 1.5);
opacity: 0;
}
opacity: 1;
}
//todo check if it is even needed
&.widthClamped {
Expand Down

0 comments on commit 1f7d59f

Please sign in to comment.