Source

frontend/ezra_init.js

  1. /* This file is part of Ezra Bible App.
  2. Copyright (C) 2019 - 2023 Ezra Bible App Development Team <contact@ezrabibleapp.net>
  3. Ezra Bible App is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. Ezra Bible App is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with Ezra Bible App. See the file LICENSE.
  13. If not, see <http://www.gnu.org/licenses/>. */
  14. /**
  15. * This module is the second one loaded (after platform_init.js) and handles the app's `load` event.
  16. * It then detects whether we are running on Electron or Cordova and initiates the corresponding startup logic.
  17. * @module ezra_init
  18. * @category Startup
  19. */
  20. window.app = null;
  21. // Platform Helper
  22. var PlatformHelper = null;
  23. var Startup = null;
  24. if (window.isElectron) {
  25. PlatformHelper = require('./app/lib/platform_helper.js');
  26. Startup = require('./app/frontend/startup.js');
  27. } else {
  28. PlatformHelper = require('../lib/platform_helper.js');
  29. Startup = require('./startup.js');
  30. }
  31. window.platformHelper = new PlatformHelper();
  32. window.startup = new Startup();
  33. window.cordovaPlatform = null;
  34. window.electronPlatform = null;
  35. // Extend NodeList with the forEach function from Array
  36. NodeList.prototype.forEach = Array.prototype.forEach;
  37. $.create_xml_doc = function(string)
  38. {
  39. var doc = (new DOMParser()).parseFromString(string, 'text/xml');
  40. return doc;
  41. };
  42. window.addEventListener('load', function() {
  43. console.log("load event fired!");
  44. window.startup.earlyRestoreLocalizedString();
  45. if (platformHelper.isCordova()) {
  46. var CordovaPlatform = require('./platform/cordova_platform.js');
  47. window.cordovaPlatform = new CordovaPlatform();
  48. window.cordovaPlatform.init();
  49. } else if (platformHelper.isElectron()) {
  50. var ElectronPlatform = require('./app/frontend/platform/electron_platform.js');
  51. window.electronPlatform = new ElectronPlatform();
  52. console.log("Initializing app on Electron platform ...");
  53. window.startup.initApplication();
  54. } else {
  55. console.error("FATAL: Unsupported platform");
  56. window.startup.initApplication();
  57. }
  58. });
  59. if (platformHelper.isCordova() || platformHelper.isTest()) {
  60. $('#loading-subtitle').show();
  61. }