1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-11-30 18:24:27 +01:00

Added models list population

This commit is contained in:
Nayam Amarshe 2023-04-09 11:18:53 +05:30
parent 0265c8e148
commit 33f85d96d4
6 changed files with 47 additions and 17 deletions

View File

@ -1,7 +1,6 @@
const commands = { const commands = {
SELECT_FILE: "Select a File", SELECT_FILE: "Select a File",
SELECT_FOLDER: "Select a Folder", SELECT_FOLDER: "Select a Folder",
SELECT_CUSTOM_MODEL_FOLDER: "Select a Custom Model Folder",
UPSCAYL: "Upscale the Image", UPSCAYL: "Upscale the Image",
UPSCAYL_DONE: "Upscaling Done", UPSCAYL_DONE: "Upscaling Done",
UPSCAYL_PROGRESS: "Send Progress from Main to Renderer", UPSCAYL_PROGRESS: "Send Progress from Main to Renderer",
@ -18,7 +17,9 @@ const commands = {
UPSCAYL_VIDEO_PROGRESS: "Send Video Upscale Progress from Main to Renderer", UPSCAYL_VIDEO_PROGRESS: "Send Video Upscale Progress from Main to Renderer",
FFMPEG_VIDEO_DONE: "Ran FFMpeg successfully", FFMPEG_VIDEO_DONE: "Ran FFMpeg successfully",
FFMPEG_VIDEO_PROGRESS: "Running FFMpeg for frame extraction", FFMPEG_VIDEO_PROGRESS: "Running FFMpeg for frame extraction",
CUSTOM_MODEL_FILES_LIST: "Get custom model files list", SELECT_CUSTOM_MODEL_FOLDER: "Select a Custom Model Folder",
GET_MODELS_LIST: "Send models list from main to renderer",
CUSTOM_MODEL_FILES_LIST: "Send custom model files list to renderer",
}; };
export default commands; export default commands;

View File

@ -196,6 +196,15 @@ const getModels = (folderPath: string) => {
return models; return models;
}; };
ipcMain.on(commands.GET_MODELS_LIST, async (event, payload) => {
if (payload) {
mainWindow.webContents.send(
commands.CUSTOM_MODEL_FILES_LIST,
getModels(payload)
);
}
});
//------------------------Select Custom Models Folder---------------------// //------------------------Select Custom Models Folder---------------------//
ipcMain.handle(commands.SELECT_CUSTOM_MODEL_FOLDER, async (event, message) => { ipcMain.handle(commands.SELECT_CUSTOM_MODEL_FOLDER, async (event, message) => {
const { canceled, filePaths: folderPaths } = await dialog.showOpenDialog({ const { canceled, filePaths: folderPaths } = await dialog.showOpenDialog({

View File

@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
const commands = { const commands = {
SELECT_FILE: "Select a File", SELECT_FILE: "Select a File",
SELECT_FOLDER: "Select a Folder", SELECT_FOLDER: "Select a Folder",
SELECT_CUSTOM_MODEL_FOLDER: "Select a Custom Model Folder",
UPSCAYL: "Upscale the Image", UPSCAYL: "Upscale the Image",
UPSCAYL_DONE: "Upscaling Done", UPSCAYL_DONE: "Upscaling Done",
UPSCAYL_PROGRESS: "Send Progress from Main to Renderer", UPSCAYL_PROGRESS: "Send Progress from Main to Renderer",
@ -19,6 +18,8 @@ const commands = {
UPSCAYL_VIDEO_PROGRESS: "Send Video Upscale Progress from Main to Renderer", UPSCAYL_VIDEO_PROGRESS: "Send Video Upscale Progress from Main to Renderer",
FFMPEG_VIDEO_DONE: "Ran FFMpeg successfully", FFMPEG_VIDEO_DONE: "Ran FFMpeg successfully",
FFMPEG_VIDEO_PROGRESS: "Running FFMpeg for frame extraction", FFMPEG_VIDEO_PROGRESS: "Running FFMpeg for frame extraction",
CUSTOM_MODEL_FILES_LIST: "Get custom model files list", SELECT_CUSTOM_MODEL_FOLDER: "Select a Custom Model Folder",
GET_MODELS_LIST: "Send models list from main to renderer",
CUSTOM_MODEL_FILES_LIST: "Send custom model files list to renderer",
}; };
exports.default = commands; exports.default = commands;

View File

@ -167,6 +167,11 @@ const getModels = (folderPath) => {
} }
return models; return models;
}; };
electron_1.ipcMain.on(commands_1.default.GET_MODELS_LIST, (event, payload) => __awaiter(void 0, void 0, void 0, function* () {
if (payload) {
mainWindow.webContents.send(commands_1.default.CUSTOM_MODEL_FILES_LIST, getModels(payload));
}
}));
//------------------------Select Custom Models Folder---------------------// //------------------------Select Custom Models Folder---------------------//
electron_1.ipcMain.handle(commands_1.default.SELECT_CUSTOM_MODEL_FOLDER, (event, message) => __awaiter(void 0, void 0, void 0, function* () { electron_1.ipcMain.handle(commands_1.default.SELECT_CUSTOM_MODEL_FOLDER, (event, message) => __awaiter(void 0, void 0, void 0, function* () {
const { canceled, filePaths: folderPaths } = yield electron_1.dialog.showOpenDialog({ const { canceled, filePaths: folderPaths } = yield electron_1.dialog.showOpenDialog({

View File

@ -45,19 +45,6 @@ function SettingsTab({
const [customModelOptions, setCustomModelOptions] = useState<TModelsList>([]); const [customModelOptions, setCustomModelOptions] = useState<TModelsList>([]);
const [modelOptions, setModelOptions] = useAtom(modelsListAtom); const [modelOptions, setModelOptions] = useAtom(modelsListAtom);
// EFFECTS
useEffect(() => {
// CUSTOM FOLDER LISTENER
window.electron.on(
commands.CUSTOM_MODEL_FILES_LIST,
(_, modelsList: string[]) => {
modelsList.forEach((model: string) => {
setModelOptions((prev) => [...prev, { label: model, value: model }]);
});
}
);
}, []);
useEffect(() => { useEffect(() => {
themeChange(false); themeChange(false);
@ -223,6 +210,7 @@ function SettingsTab({
if (customModelPath !== null) { if (customModelPath !== null) {
setCustomModelsPath(customModelPath); setCustomModelsPath(customModelPath);
window.electron.send(commands.GET_MODELS_LIST, customModelPath);
} }
}}> }}>
Select Folder Select Folder

View File

@ -11,6 +11,8 @@ import Tabs from "../components/Tabs";
import SettingsTab from "../components/SettingsTab"; import SettingsTab from "../components/SettingsTab";
import { useAtom } from "jotai"; import { useAtom } from "jotai";
import { logAtom } from "../atoms/logAtom"; import { logAtom } from "../atoms/logAtom";
import { modelsListAtom } from "../atoms/modelsListAtom";
import { customModelsPathAtom } from "../atoms/userSettingsAtom";
const Home = () => { const Home = () => {
// STATES // STATES
@ -40,6 +42,8 @@ const Home = () => {
}); });
const [selectedTab, setSelectedTab] = useState(0); const [selectedTab, setSelectedTab] = useState(0);
const [logData, setLogData] = useAtom(logAtom); const [logData, setLogData] = useAtom(logAtom);
const [customModelsPath, setCustomModelsPath] = useAtom(customModelsPathAtom);
const [modelOptions, setModelOptions] = useAtom(modelsListAtom);
// (function () { // (function () {
// let info = console.info; // let info = console.info;
@ -151,6 +155,28 @@ const Home = () => {
setUpscaledVideoPath(data); setUpscaledVideoPath(data);
addToLog(data); addToLog(data);
}); });
// CUSTOM FOLDER LISTENER
window.electron.on(
commands.CUSTOM_MODEL_FILES_LIST,
(_, modelsList: string[]) => {
console.log("🚀 => file: index.tsx:161 => modelsList:", modelsList);
modelsList.forEach((model: string) => {
setModelOptions((prev) => [...prev, { label: model, value: model }]);
});
}
);
}, []);
useEffect(() => {
const customModelsPath = JSON.parse(
localStorage.getItem("customModelsPath")
);
if (customModelsPath !== null) {
window.electron.send(commands.GET_MODELS_LIST, customModelsPath);
}
}, []); }, []);
useEffect(() => { useEffect(() => {