Fix error when missing data file

master
v-crispadvice 2023-07-07 20:43:16 +03:00
parent 5be8ef57f9
commit 6a3c6c9a83
1 changed files with 12 additions and 11 deletions

View File

@ -2,9 +2,6 @@
* Copyright 2023 SHOGEL * Copyright 2023 SHOGEL
* We believe in Finnish * We believe in Finnish
*/ */
var Layout = require("Layout");
var locale = require("locale");
var storage = require("Storage");
// Constants // Constants
let SWAP_SIDE_BUZZ_MILLISECONDS = 50; let SWAP_SIDE_BUZZ_MILLISECONDS = 50;
@ -13,13 +10,15 @@ let CARD_EMPTY = "empty card";
let CARD_LINE_LENGTH = 9; let CARD_LINE_LENGTH = 9;
let CARD_LINE_FONT = "20%"; let CARD_LINE_FONT = "20%";
// Global variables // Modules
let cards = []; var Layout = require("Layout");
var locale = require("locale");
var storage = require("Storage");
let cardIndex = 0; // Global variables
let backSide = false; var cards = [];
let lastDragX = 0; var cardIndex = 0;
let lastDragY = 0; var backSide = false;
// Cards data // Cards data
function wordWrap(str, maxLength) { function wordWrap(str, maxLength) {
@ -48,10 +47,12 @@ function wordWrap(str, maxLength) {
} }
function loadLocalCards() { function loadLocalCards() {
var cardsJSON = "";
if (storage.read(CARD_DATA_FILE)) if (storage.read(CARD_DATA_FILE))
{ {
refreshCards(storage.readJSON(CARD_DATA_FILE, 1) || {},false); cardsJSON = storage.readJSON(CARD_DATA_FILE, 1) || {};
} }
refreshCards(cardsJSON,false);
} }
function refreshCards(cardsJSON,showMsg) function refreshCards(cardsJSON,showMsg)
@ -88,7 +89,7 @@ let queueDraw = function() {
var cardLayout = new Layout( { var cardLayout = new Layout( {
type:"v", c: [ type:"v", c: [
{type:"txt", font:"6x8:3", label:"", id:"widgets", fillx:1 }, {type:"txt", font:"6x8:3", label:"", id:"widgets", fillx:1 },
{type:"txt", font:CARD_LINE_FONT, label:"ABCDEFGHIJ KLMNOPQRST UVWXYZÅÄÖ", filly:1, id:"card" }, {type:"txt", font:CARD_LINE_FONT, label:"ABCDEFGHIJ KLMNOPQRST UVWXYZ<EFBFBD><EFBFBD><EFBFBD>", filly:1, id:"card" },
{type:"txt", font:"6x8:2", label:"00:00", id:"clock", fillx:1, bgCol:g.theme.fg, col:g.theme.bg } {type:"txt", font:"6x8:2", label:"00:00", id:"clock", fillx:1, bgCol:g.theme.fg, col:g.theme.bg }
] ]
}, {lazy:true}); }, {lazy:true});