Use electron to read files if we have path info

Former-commit-id: 23b41c88e5ce9184e3665d25d184d31ea4a66392 [formerly 7288cd7e3477d0fcc0d8284fd75a6f14cbce2003]
Former-commit-id: 00616e33c763969d097ae317fee99e19035bb3b1
This commit is contained in:
Jaifroid 2019-08-01 10:06:37 +01:00
parent a54729ae00
commit 747a30aa8c
4 changed files with 12 additions and 6 deletions

View File

@ -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({

View File

@ -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)) {

View File

@ -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

View File

@ -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 {