From 6185c6181ec7a97b3e077248aa7095516142ad49 Mon Sep 17 00:00:00 2001 From: Matthew Welch Date: Mon, 11 Jan 2021 20:26:02 -0800 Subject: [PATCH] Removed unused code Checks if recent file valid before showing --- src/index.js | 58 +++--------------------------------------------- src/js/splash.js | 15 +++++++++---- 2 files changed, 14 insertions(+), 59 deletions(-) diff --git a/src/index.js b/src/index.js index 68d0747..e9ac2a3 100644 --- a/src/index.js +++ b/src/index.js @@ -60,58 +60,6 @@ let menu_template = [ } ] -let table_col_schema = { - "id": "/table_column", - "type": "array", - "items": { - "type": "object", - "properties": { - "field": {"type": "string"}, - "title": {"type": "string"}, - "sortable": {"type": "boolean"}, - "selectable": {"type": "boolean"}, - } - } -} - -let table_row_schema = { - "id": "/table_row", - "type": "array", - "items": { - "type": "object", - "properties": { - "uid": {"type": "string", "pattern": /row\d+/}, - }, - "patternProperties": { - "column\d+": {"type": "string"} - }, - "minProperties": 2 - } -} - -let table_schema = { - "id": "/table", - "type": "object", - "properties": { - "id": {"type": "string"}, - "name": {"type": "string"}, - "filter": {"type": "boolean"}, - "hidden": {"type": "boolean"}, - "tab_name": {"type": "string"}, - "description": {"type": "string"}, - "columns": {"$ref": "/table_column"}, - "rows": {"$ref": "/table_row"} - } -} - -let data_file_schema = { - "type": "object", - "properties": { - "version": {"type": "string"}, - "tables": {"$ref": "/table"} - } -} - // Handle creating/removing shortcuts on Windows when installing/uninstalling. if (require('electron-squirrel-startup')) { // eslint-disable-line global-require app.quit(); @@ -158,7 +106,7 @@ function createSplashScreen() { splash_screen.loadFile('src/splash.html'); // Open the DevTools. - splash_screen.webContents.openDevTools(); + // splash_screen.webContents.openDevTools(); // store.openInEditor(); } @@ -176,7 +124,7 @@ function createEditorWindow() { main_window.loadFile("src/editor.html"); // Open the DevTools. - main_window.webContents.openDevTools(); + // main_window.webContents.openDevTools(); return main_window; } @@ -218,7 +166,7 @@ function openFile(file_path="", new_file=false) { if (file_path === "") { file_path = chooseFile("Open website data"); } - if (file_path) { + if (file_path && fs.existsSync(file_path)) { let result = checkFile(file_path); if (result) { let json = getUpdatedJson(result); diff --git a/src/js/splash.js b/src/js/splash.js index 98198cc..825a86c 100644 --- a/src/js/splash.js +++ b/src/js/splash.js @@ -1,13 +1,20 @@ -const { ipcRenderer } = require('electron') +const { ipcRenderer } = require('electron'); +const fs = require("fs"); async function showRecentFiles() { let recent_files = await ipcRenderer.invoke("get-store-value", "recent_files"); - if (recent_files.length === 0) { + let valid_recent_files = []; + for (let file of recent_files) { + if (fs.existsSync(file)) { + valid_recent_files.push(file); + } + } + if (valid_recent_files.length === 0) { $("#recent-files").css("display", "none"); $("#splash").css("width", "100%") } else { - for (let file of recent_files) { - let recent_file_link = $("") + for (let file of valid_recent_files) { + let recent_file_link = $("") .addClass("btn list-group-item list-group-item-action") .text(file.replace(/^.*[\\\/]/, '')) .attr({"data-bs-toggle": "tooltip", "data-bs-placement": "bottom", "title": file})