|
|
|
@ -1,46 +1,24 @@ |
|
|
|
|
"use strict"; |
|
|
|
|
|
|
|
|
|
const {app, BrowserWindow, ipcMain, dialog} = require("electron"); |
|
|
|
|
const path = require("path"); |
|
|
|
|
const fs = require("fs/promises"); |
|
|
|
|
const util = require("util"); |
|
|
|
|
const {app, BrowserWindow, ipcMain, dialog, Menu} = require("electron"); |
|
|
|
|
const path = require("path"); |
|
|
|
|
const fs = require("fs/promises"); |
|
|
|
|
const util = require("util"); |
|
|
|
|
|
|
|
|
|
const {isDevelopment} = require("./Util"); |
|
|
|
|
const {parser} = require("./Parser"); |
|
|
|
|
|
|
|
|
|
class WindowManager { |
|
|
|
|
mainWindow; |
|
|
|
|
windows; |
|
|
|
|
|
|
|
|
|
constructor() { |
|
|
|
|
constructor(parent) { |
|
|
|
|
this.app = parent; |
|
|
|
|
this.mainWindow = null; |
|
|
|
|
this.windows = []; |
|
|
|
|
|
|
|
|
|
app.whenReady().then(() => this.init()); |
|
|
|
|
|
|
|
|
|
ipcMain.handle("WindowManager::openFile", async () => { |
|
|
|
|
if (!this.mainWindow) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
const result = await dialog.showOpenDialog(this.mainWindow, { |
|
|
|
|
title : "open file", |
|
|
|
|
filters : [ |
|
|
|
|
{ |
|
|
|
|
name : "Markdown files", |
|
|
|
|
extensions : [".md"] |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (result.canceled || result.filePaths.length < 1) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
const fileContents = await fs.readFile(result.filePaths[0], {encoding : "utf-8"}); |
|
|
|
|
const basePath = path.dirname(result.filePaths[0]); |
|
|
|
|
const data = parser(fileContents); |
|
|
|
|
|
|
|
|
|
return [basePath, data]; |
|
|
|
|
}); |
|
|
|
|
ipcMain.handle("WindowManager::openFile", async () => this.app.openFile()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
init() { |
|
|
|
@ -53,7 +31,7 @@ class WindowManager { |
|
|
|
|
if (isDevelopment()) |
|
|
|
|
this.mainWindow.loadURL("http://localhost:3000"); |
|
|
|
|
else |
|
|
|
|
this.mainWindow.loadFile(`file://${path.join(__dirname, "ui", "build", "index.html")}`); |
|
|
|
|
this.mainWindow.loadURL(`file://${__dirname}/ui/build/index.html`); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static _CreateWindow(options = null, parent = null) { |
|
|
|
@ -61,6 +39,7 @@ class WindowManager { |
|
|
|
|
width : 800, |
|
|
|
|
height : 600, |
|
|
|
|
show : false, |
|
|
|
|
devTools : isDevelopment(), |
|
|
|
|
webPreferences : { |
|
|
|
|
contextIsolation : true, |
|
|
|
|
preload : path.join(__dirname, "..", "contextAPI.js") |
|
|
|
|