Skip to content

Commit

Permalink
make error visible
Browse files Browse the repository at this point in the history
  • Loading branch information
xpadev-net committed Nov 3, 2022
1 parent 27b55db commit a9e37dc
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 29 deletions.
80 changes: 53 additions & 27 deletions electron/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ ipcMain.on("request", async (IpcMainEvent, args) => {
fps: fps,
});
} else {
console.log(args);
mainWindow.webContents.send("response", {
type: "message",
target: "main",
message: `unknown IPC Message: ${JSON.stringify(value)}`
});
}
});

Expand Down Expand Up @@ -167,23 +171,35 @@ const convertStart = async(IpcMainEvent,value) => {
});
renderWindow.removeMenu();
renderWindow.loadURL(`file://${__dirname}/html/index.html?render`);
conv = new Converter();
conv.createInputFromFile(targetFileName, videoOption);
input = conv.createInputStream({
f: "image2pipe",
r: fps,
filter_complex: `pad=width=max(iw\\,ih*(16/9)):height=ow/(16/9):x=(ow-iw)/2:y=(oh-ih)/2,scale=1920x1080,overlay=x=0:y=0`,
});
conv.output(outputPath.filePath, { vcodec: "libx264", "b:v": "0","cq":"25" }); // output to file
await conv.run();
renderWindow.webContents.send("response", {
type: "end",
target: "render",
});
mainWindow.webContents.send("response", {
type: "end",
target: "main",
});

if (!app.isPackaged) {
renderWindow.webContents.openDevTools();
}
try {
conv = new Converter();
conv.createInputFromFile(targetFileName, videoOption);
input = conv.createInputStream({
f: "image2pipe",
r: fps,
filter_complex: `pad=width=max(iw\\,ih*(16/9)):height=ow/(16/9):x=(ow-iw)/2:y=(oh-ih)/2,scale=1920x1080,overlay=x=0:y=0`,
});
conv.output(outputPath.filePath, { vcodec: "libx264", "b:v": "0","cq":"25" }); // output to file
await conv.run();
renderWindow.webContents.send("response", {
type: "end",
target: "render",
});
mainWindow.webContents.send("response", {
type: "end",
target: "main",
});
}catch (e){
mainWindow.webContents.send("response", {
type: "message",
target: "main",
message: `unknown error: ${JSON.stringify(e)}`
});
}
}
const selectMovie = async(IpcMainEvent) => {
const path = await dialog.showOpenDialog({
Expand All @@ -200,23 +216,28 @@ const selectMovie = async(IpcMainEvent) => {
],
});
if (path.canceled) {
return;
}
let ffprobe
try {
ffprobe = execSync(
`${ffprobePath} "${path.filePaths[0].replace(/"/g,"\\\"")}" -hide_banner -v quiet -print_format json -show_streams`
);
}catch (e) {
IpcMainEvent.reply("response", {
type: "selectMovie",
target: "main",
message: "cancelled",
message: "input file is not movie(ffprobe fail)",
});
return;
}
const ffprobe = execSync(
`${ffprobePath} "${path.filePaths[0].replace(/"/g,"\\\"")}" -hide_banner -v quiet -print_format json -show_streams`
);
let metadata;
metadata = JSON.parse(ffprobe.toString());
if (!metadata.streams) {
if (!metadata.streams||!Array.isArray(metadata.streams)) {
IpcMainEvent.reply("response", {
type: "selectMovie",
target: "main",
message: "input file is not movie",
message: "input file is not movie(stream not found)",
});
return;
}
Expand All @@ -233,7 +254,7 @@ const selectMovie = async(IpcMainEvent) => {
IpcMainEvent.reply("response", {
type: "selectMovie",
target: "main",
message: "fail to get resolution from input file",
message: "input file is not movie(fail to get resolution from input file)",
});
return;
}
Expand Down Expand Up @@ -267,10 +288,10 @@ const selectComment = async(IpcMainEvent) => {
const parser = new DOMParser();
data = parser.parseFromString(fileData, "application/xml");
type = "niconicome";
}else if(file.match(/\.txt/)){
}else if(file.match(/\.txt$/)){
data = fileData;
type = "legacyOwner";
}else if(file.match(/\.json/)){
}else if(file.match(/\.json$/)){
const json = JSON.parse(fileData);
if (json?.meta?.status===200&&typeGuard.v1.threads(json?.data?.threads)){
data = json.data.threads;
Expand All @@ -290,6 +311,11 @@ const selectComment = async(IpcMainEvent) => {
data = json;
}
}else{
mainWindow.webContents.send("response", {
type: "message",
target: "main",
message: `unknown input format`
});
return;
}

Expand Down
8 changes: 6 additions & 2 deletions src/@types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ type apiResponseType =
| apiResponseStartMain
| apiResponseStartRender
| apiResponseEndMain
| apiResponseEndRender;
| apiResponseEndRender
| apiResponse;
type apiResponseToMain = {
target: "main";
};
Expand Down Expand Up @@ -105,7 +106,10 @@ type apiResponseEndMain = {
type apiResponseEndRender = {
type: "end";
} & apiResponseToRender;

type apiResponse = {
type: "message",
message: string;
} & apiResponseToMain
type options = {
showCollision: boolean;
showCommentCount: boolean;
Expand Down
6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ const init = () => {
window.api.onResponse((data) => {
if (data.target !== "main") return;
if (typeGuard.main.selectMovie(data)) {
if (data.message){
movieMessage.innerText = data.message;
return;
}
const {path,width,height,duration} = data.data;
movieMessage.innerText = `path:${path.filePaths}, width:${width}, height:${height}, duration:${duration}`;
duration_ = duration;
Expand Down Expand Up @@ -219,6 +223,8 @@ const init = () => {
clipStart=clipEnd=undefined;
clipStartInput.value=clipEndInput.value="";
alert("変換が完了しました");
} else if(typeGuard.main.message(data)){
alert(data.message);
}
});
const progress = (element: HTMLElement, current: number, max: number) => {
Expand Down
2 changes: 2 additions & 0 deletions src/typeGuard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const typeGuard = {
typeof i === "object" && (i as apiResponseStartMain).type === "start",
end: (i: unknown): i is apiResponseEndMain =>
typeof i === "object" && (i as apiResponseEndMain).type === "end",
message: (i: unknown): i is apiResponse =>
typeof i === "object" && (i as apiResponse).type === "message",
},
render: {
start: (i: unknown): i is apiResponseStartRender =>
Expand Down

0 comments on commit a9e37dc

Please sign in to comment.