From 7d444006d130c0a58c0430ca4cb985e6bbb1a666 Mon Sep 17 00:00:00 2001 From: Matthew Welch Date: Tue, 12 Jan 2021 20:51:15 -0800 Subject: [PATCH] Moved generating the nav bar and tab content to the website Fixed issue with loading local files within the packaged app Fixed issue with 1.0.0 schema tab name --- package.json | 2 +- src/index.js | 118 ++++------------------------------ src/js/editor.js | 6 +- src/schemas/1.0.0_schema.json | 2 +- 4 files changed, 19 insertions(+), 109 deletions(-) diff --git a/package.json b/package.json index 4d79657..f6964e5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "webeditor", "productName": "webeditor", - "version": "1.0.0", + "version": "1.1.0", "description": "My Electron application description", "main": "src/index.js", "scripts": { diff --git a/src/index.js b/src/index.js index e9ac2a3..509c5fe 100644 --- a/src/index.js +++ b/src/index.js @@ -1,13 +1,14 @@ const { app, BrowserWindow, ipcMain, dialog, Menu } = require('electron'); const Store = require("electron-store"); const fs = require("fs"); +const path = require("path"); const util = require('util') let Validator = require("jsonschema").Validator; let validator = new Validator(); let all_schemas = [ - "src/schemas/current_schema.json", - "src/schemas/1.0.0_schema.json", + path.join(app.getAppPath(), "src/schemas/current_schema.json"), + path.join(app.getAppPath(), "src/schemas/1.0.0_schema.json"), ] let schema_updaters = { "1.0.0_schema.json": update_1_0_0_schema @@ -103,14 +104,13 @@ function createSplashScreen() { store.set("recent_files", []); } - splash_screen.loadFile('src/splash.html'); - + splash_screen.loadFile(path.join(app.getAppPath(), "src/splash.html")); // Open the DevTools. // splash_screen.webContents.openDevTools(); // store.openInEditor(); } -function createEditorWindow() { +function createEditorWindow(json) { let main_window = new BrowserWindow({ width: 1000, height: 600, @@ -118,11 +118,14 @@ function createEditorWindow() { webPreferences: { nodeIntegration: true } - }); + }) main_window.maximize(); updateMenuBar(); - main_window.loadFile("src/editor.html"); + main_window.loadFile(path.join(app.getAppPath(), "src/editor.html")) + .then(() => { + main_window.webContents.send("open", json); + }); // Open the DevTools. // main_window.webContents.openDevTools(); return main_window; @@ -174,10 +177,7 @@ function openFile(file_path="", new_file=false) { current_file = file_path if (new_file) { let old_window = BrowserWindow.getFocusedWindow(); - let window = createEditorWindow(); - window.once("ready-to-show", () => { - window.webContents.send("open", json); - }) + createEditorWindow(json); old_window.close(); } else { let window = BrowserWindow.getFocusedWindow(); @@ -196,99 +196,7 @@ function saveFile(json_data, create_new_file) { } } if (current_file) { - let tables_data = json_data["tables"] fs.writeFileSync(current_file, JSON.stringify(json_data, null, 4)); - let nav_content_path = current_file.replace(".json", "-nav-content.html"); - let tab_content_path = current_file.replace(".json", "-tab-content.html"); - let nav = ""; - let tabs = ""; - let table_tabs = {"": []}; - let tables_added = []; - - for (let table_data of tables_data) { - if (table_data["tab_name"] === "") { - table_tabs[""].push(table_data["id"]); - } else { - if (!Object.keys(table_tabs).includes(table_data["tab_name"])) { - table_tabs[table_data["tab_name"]] = [table_data]; - } else { - table_tabs[table_data["tab_name"]].push(table_data); - } - } - } - - for (let table_data of tables_data) { - let table_id = table_data["id"]; - if (table_data["hidden"]) {continue;} - if (tables_added.includes(table_id)) {continue;} - let li; - if (table_tabs[""].includes(table_id)) { - li = $("
  • ").addClass("nav-item"); - let tab_link = $("") - .attr({"id": table_id+"-tab", - "class": "nav-link", - "data-bs-toggle": "tab", - "href": "#"+table_id, - "role": "tab", - "aria-controls": table_id, - "aria-selected": false}) - .html(table_data["name"]); - li.append(tab_link); - let div = $("
    ") - .attr({"id": table_id, - "class": "tab-pane fade", - "role": "tabpanel", - "aria-labelledby": table_id+"-tab"}) - let h3 = $("

    ") - .attr("id", table_id+"-header") - .html(`${table_data["name"]} (/)`); - div.append(h3) - .append(`

    ${table_data["description"]}

    `) - .append(`
    `); - tabs += div.prop("outerHTML"); - tables_added.push(table_id) - } else { - li = $("
  • ").addClass("nav-item dropdown"); - let a = $("") - .attr({"class": "nav-link dropdown-toggle", - "href": "#", - "data-bs-toggle": "dropdown", - "role": "button", - "aria-expanded": false}) - .html(table_data["tab_name"]); - li.append(a) - let ul = $("