Skip to content

Commit

Permalink
WIup UP
Browse files Browse the repository at this point in the history
  • Loading branch information
mjacobus committed Sep 22, 2023
1 parent 0ee0553 commit 5af3a43
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 54 deletions.
2 changes: 0 additions & 2 deletions src/ApplicationDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { screen, dialog, BrowserWindow } = require("electron");
const ControlWindow = require("./ControlWindow");
const DisplayWindow = require("./DisplayWindow");
const ApplicationMenu = require("./ApplicationMenu");
const { clearThumbnails } = require("./utils");

class ApplicationDriver {
constructor(app) {
Expand All @@ -13,7 +12,6 @@ class ApplicationDriver {
}

quit() {
clearThumbnails();
this.app.quit();
}

Expand Down
9 changes: 4 additions & 5 deletions src/ControlWindow.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { createFilePayload, isFileSupported } = require("./utils");
const { ipcMain } = require("electron");
const fs = require("fs");
const path = require("path");
Expand Down Expand Up @@ -27,13 +26,13 @@ class ControlWindow extends Window {
}

clearFiles() {
this.store.clearCollection("app.files");
this.medias.deleteAll();
this.webContents.send("clear-files");
}

removeFile(fileId) {
const file = this.medias.find(fileId);
this.medias.remove(file);
this.medias.delete(file);
console.log("file removed", file.getId(), file.getPath());
}

Expand All @@ -55,8 +54,8 @@ class ControlWindow extends Window {

onFinishLoad() {
this.webContents.on("did-finish-load", () => {
this.store.get("app.files", []).forEach((file) => {
this.addFile(file);
this.medias.all().forEach((file) => {
this.webContents.send("add-file", file.getId());
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/DisplayWindow.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { BrowserWindow, screen, ipcMain } = require("electron");
const { ipcMain } = require("electron");

const Window = require("./Window");

Expand Down
2 changes: 1 addition & 1 deletion src/pages/controls.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { on } = require("delegated-events");
const { ipcRenderer } = require("electron");
const { isImage, isVideo, mediaProgress } = require("../utils");
const { mediaProgress } = require("../utils");
const MediaFiles = require("../MediaFiles");

const files = new MediaFiles();
Expand Down
2 changes: 1 addition & 1 deletion src/pages/display-window.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { ipcRenderer } = require("electron");
const { isImage, isVideo, maximizeImage } = require("../utils");
const { maximizeImage } = require("../utils");
const MediaFiles = require("../MediaFiles");

const files = new MediaFiles();
Expand Down
44 changes: 0 additions & 44 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,48 +38,6 @@ const maximizeImage = (image, window) => {
)}px`;
};

const createFilePayload = (filePath) => {
const file = { url: `file://${filePath}` };
if (isImage(filePath)) {
const dimensions = sizeOf(filePath);
file.width = dimensions.width;
file.height = dimensions.height;
}

if (isVideo(filePath)) {
const thumbnail = createVideoThumbnail(filePath);
file.thumbnail = new URL(`file://${thumbnail}`).toString();
}

return file;
};

const clearThumbnails = () => {
const folder = path.join(app.getPath("appData"), "JW Play", "thumbnails");
try {
fs.rmSync(folder, { recursive: true });
} catch (e) {}
};

const createVideoThumbnail = (file) => {
try {
const size = "320x180";
const folder = path.join(app.getPath("appData"), "JW Play", "thumbnails");
const filename = uuid() + `-${size}.png`;
fs.mkdirSync(folder, { recursive: true });
ffmpeg(file).screenshots({
timestamps: [2],
folder,
filename,
size,
});
const screenshot = path.join(folder, filename);
return screenshot;
} catch (error) {
console.log(error);
}
};

function secondsToTime(totalSeconds) {
totalSeconds = Math.floor(totalSeconds);
let hours = Math.floor(totalSeconds / 3600);
Expand Down Expand Up @@ -121,8 +79,6 @@ module.exports = {
isVideo,
isFileSupported,
maximizeImage,
clearThumbnails,
createFilePayload,
mediaProgress,
secondsToTime,
uuid,
Expand Down

0 comments on commit 5af3a43

Please sign in to comment.