Skip to content

Commit

Permalink
Forbid PDF opening if not matching TeX file
Browse files Browse the repository at this point in the history
  • Loading branch information
Red-Rapious committed Jun 23, 2022
1 parent d04f3af commit 507d0b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
47 changes: 23 additions & 24 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (isDevelopementEnvironement) {

let mainWindow;
let openedFilePath;
let openedFolderPath;
//let openedFolderPath;

const handleError = (location = "undefined") => {
new Notification({
Expand All @@ -24,6 +24,26 @@ const handleError = (location = "undefined") => {
//alert("An error occured during " + location);
};

const openFile = (filePath) => {
fs.readFile(filePath, "utf-8", (error, content) => {
if (error) {
handleError("the opening of the file");
}
else {
openedFilePath = filePath;
app.addRecentDocument(filePath);
settings.set("current-file", { data: filePath });
mainWindow.webContents.send("document-opened", { filePath, content });
}
});
};

const openFolder = (folderPath) => {
//openedFolderPath = folderPath;
settings.set("current-folder", { data: folderPath });
mainWindow.webContents.send("folder-opened", { folderPath });
};

const createWindow = () => {
mainWindow = new BrowserWindow({
width: 1600,
Expand Down Expand Up @@ -165,26 +185,7 @@ const createWindow = () => {
Menu.setApplicationMenu(menu);
};

const openFile = (filePath) => {
openedFilePath = filePath;

fs.readFile(filePath, "utf-8", (error, content) => {
if (error) {
handleError("the opening of the file");
}
else {
app.addRecentDocument(filePath);
settings.set("current-file", { data: filePath });
mainWindow.webContents.send("document-opened", { filePath, content });
}
});
};

const openFolder = (folderPath) => {
openedFolderPath = folderPath;
settings.set("current-folder", { data: folderPath });
mainWindow.webContents.send("folder-opened", { folderPath });
};
app.whenReady().then(createWindow);

app.on("open-file", (_, filePath) => {
openFile(filePath);
Expand All @@ -194,8 +195,6 @@ app.on("open-folder", (_, folderPath) => {
openFolder(folderPath);
});

app.whenReady().then(createWindow);

ipcMain.on("create-document-triggered", () => {
dialog.showSaveDialog(mainWindow, {
filters: [{name: "LaTeX files", extensions: ["tex"]}]
Expand Down Expand Up @@ -252,5 +251,5 @@ ipcMain.on("update-file-content", (_, textareaContent) => {
});

ipcMain.on("open-given-file", (_, filePath) => {
openFile(filePath);
if (fs.existsSync(filePath)) openFile(filePath);
});
2 changes: 1 addition & 1 deletion src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ window.addEventListener("DOMContentLoaded", () => {
const handleFolderChange = (folderPath) => {
/* On folder change, updates the side folder structure tree */

openedFolderPath = folderPath
openedFolderPath = folderPath;
htmlCode = createFolderStructureHTML(getFolderStructure(openedFolderPath));

// Opens a non-specific TeX file
Expand Down

0 comments on commit 507d0b4

Please sign in to comment.