diff --git a/main.js b/main.js index 16c5da64..578a4f9c 100644 --- a/main.js +++ b/main.js @@ -32,9 +32,9 @@ function createWindow() { minHeight: 600, icon: path.join(__dirname, 'www/img/icons/kiwix-64.png'), webPreferences: { - // nodeIntegration: false, + nodeIntegration: false, // contextIsolation: true, - preload: path.join(__dirname, 'preload.js'), + preload: path.join(__dirname, 'preload.js') // webSecurity: false // preload: 'app://www/preload.js' } @@ -89,6 +89,7 @@ app.on('ready', () => { // let parsedPath = relPath.replace(/\.\.\//g, function(p0) { // i++; // }); + console.log(relPath + '+' + linkUrl); return relPath + linkUrl; }); callback({ diff --git a/www/js/app.js b/www/js/app.js index e47d1de9..8ab2e0e6 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -1368,11 +1368,10 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki // Create a fake File object (this avoids extensive patching of later code) var file = {}; file.name = params.packagedFile; - // @TODO: Create a params.filePath in init.js - file.path = 'archives'; + file.path = params.archivePath + '/' + file.name; file.readMode = 'electron'; // Get file size - fs.stat(file.path + '/' + file.name, function(err, stats) { + fs.stat(file.path, function(err, stats) { file.size = stats.size; console.log("Packaged file size is: " + file.size); }); @@ -1748,6 +1747,11 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki uiUtil.systemAlert("One or more files does not appear to be a ZIM file!"); return; } + // Allow reading with electron if we have the path info + if (typeof window.fs !== 'undefined' && files[i].path) { + files[i].readMode = 'electron'; + console.log("File path is: " + files[i].path); + } } // Check that user hasn't picked just part of split ZIM if (files.length == 1 && /\.zim\w\w/i.test(files[0].name)) { diff --git a/www/js/init.js b/www/js/init.js index f506f8a0..da1b3ef5 100644 --- a/www/js/init.js +++ b/www/js/init.js @@ -33,6 +33,7 @@ var state = {}; var params = {}; params['version'] = "0.9.9.92 Wikivoyage Beta"; //DEV: do not set this dynamically -- it is compared to the cookie "version" in order to show first-time info, and the cookie is updated in app.js params['packagedFile'] = "wikivoyage_en.zim"; //For packaged Kiwix JS (e.g. with Wikivoyage file), set this to the filename (for split files, give the first chunk *.zimaa) and place file(s) in default storage +params['archivePath'] = "archives"; //The directory containing the packaged archive(s) (relative to www/index.html) params['fileVersion'] = "wikivoyage_en_all_novid_2019-07 (20-Jul-2019)"; //Use generic name for actual file, and give version here params['cachedStartPage'] = "Main_Page" || false; //If you have cached the start page for quick start, give its URI here params['kiwixDownloadLink'] = "https://download.kiwix.org/zim/wikivoyage/"; //Include final slash diff --git a/www/js/lib/util.js b/www/js/lib/util.js index b9c925ce..35af589b 100644 --- a/www/js/lib/util.js +++ b/www/js/lib/util.js @@ -215,7 +215,7 @@ define(['q'], function (q) { if (file.readMode === 'electron') { // We are reading a packaged file and have to use Electron fs.read (so we don't have to pick the file) var buffer = new Uint8Array(size); - fs.open(file.path + '/' + file.name, 'r', function (err, fd) { + fs.open(file.path, 'r', function (err, fd) { if (err) { console.error('Could not find file!', err); } else {