mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-09 12:19:46 -04:00
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:
parent
a54729ae00
commit
747a30aa8c
5
main.js
5
main.js
@ -32,9 +32,9 @@ function createWindow() {
|
|||||||
minHeight: 600,
|
minHeight: 600,
|
||||||
icon: path.join(__dirname, 'www/img/icons/kiwix-64.png'),
|
icon: path.join(__dirname, 'www/img/icons/kiwix-64.png'),
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
// nodeIntegration: false,
|
nodeIntegration: false,
|
||||||
// contextIsolation: true,
|
// contextIsolation: true,
|
||||||
preload: path.join(__dirname, 'preload.js'),
|
preload: path.join(__dirname, 'preload.js')
|
||||||
// webSecurity: false
|
// webSecurity: false
|
||||||
// preload: 'app://www/preload.js'
|
// preload: 'app://www/preload.js'
|
||||||
}
|
}
|
||||||
@ -89,6 +89,7 @@ app.on('ready', () => {
|
|||||||
// let parsedPath = relPath.replace(/\.\.\//g, function(p0) {
|
// let parsedPath = relPath.replace(/\.\.\//g, function(p0) {
|
||||||
// i++;
|
// i++;
|
||||||
// });
|
// });
|
||||||
|
console.log(relPath + '+' + linkUrl);
|
||||||
return relPath + linkUrl;
|
return relPath + linkUrl;
|
||||||
});
|
});
|
||||||
callback({
|
callback({
|
||||||
|
@ -1368,11 +1368,10 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
|
|||||||
// Create a fake File object (this avoids extensive patching of later code)
|
// Create a fake File object (this avoids extensive patching of later code)
|
||||||
var file = {};
|
var file = {};
|
||||||
file.name = params.packagedFile;
|
file.name = params.packagedFile;
|
||||||
// @TODO: Create a params.filePath in init.js
|
file.path = params.archivePath + '/' + file.name;
|
||||||
file.path = 'archives';
|
|
||||||
file.readMode = 'electron';
|
file.readMode = 'electron';
|
||||||
// Get file size
|
// Get file size
|
||||||
fs.stat(file.path + '/' + file.name, function(err, stats) {
|
fs.stat(file.path, function(err, stats) {
|
||||||
file.size = stats.size;
|
file.size = stats.size;
|
||||||
console.log("Packaged file size is: " + file.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!");
|
uiUtil.systemAlert("One or more files does not appear to be a ZIM file!");
|
||||||
return;
|
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
|
// Check that user hasn't picked just part of split ZIM
|
||||||
if (files.length == 1 && /\.zim\w\w/i.test(files[0].name)) {
|
if (files.length == 1 && /\.zim\w\w/i.test(files[0].name)) {
|
||||||
|
@ -33,6 +33,7 @@ var state = {};
|
|||||||
var params = {};
|
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['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['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['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['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
|
params['kiwixDownloadLink'] = "https://download.kiwix.org/zim/wikivoyage/"; //Include final slash
|
||||||
|
@ -215,7 +215,7 @@ define(['q'], function (q) {
|
|||||||
if (file.readMode === 'electron') {
|
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)
|
// 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);
|
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) {
|
if (err) {
|
||||||
console.error('Could not find file!', err);
|
console.error('Could not find file!', err);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user