mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 05:37:33 -05:00 
			
		
		
		
	Merge pull request #6480 from turbo124/v5-develop
Revert service worker changes
This commit is contained in:
		
						commit
						5b35a2c458
					
				@ -112,6 +112,7 @@ class BaseController extends Controller
 | 
				
			|||||||
          'company.groups',
 | 
					          'company.groups',
 | 
				
			||||||
          'company.payment_terms',
 | 
					          'company.payment_terms',
 | 
				
			||||||
          'company.designs.company',
 | 
					          'company.designs.company',
 | 
				
			||||||
 | 
					          'company.expense_categories',
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function __construct()
 | 
					    public function __construct()
 | 
				
			||||||
 | 
				
			|||||||
@ -226,7 +226,7 @@ class Company extends BaseModel
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function activities()
 | 
					    public function activities()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return $this->hasMany(Activity::class)->orderBy('id', 'DESC')->take(300);
 | 
					        return $this->hasMany(Activity::class)->orderBy('id', 'DESC')->take(50);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -3,24 +3,25 @@
 | 
				
			|||||||
<head>
 | 
					<head>
 | 
				
			||||||
    <!-- Source: https://github.com/invoiceninja/invoiceninja -->
 | 
					    <!-- Source: https://github.com/invoiceninja/invoiceninja -->
 | 
				
			||||||
    <!-- Version: {{ config('ninja.app_version') }} -->
 | 
					    <!-- Version: {{ config('ninja.app_version') }} -->
 | 
				
			||||||
  <base href="{{ $_SERVER['REQUEST_URI'] }}">
 | 
					 | 
				
			||||||
  <meta charset="UTF-8">
 | 
					  <meta charset="UTF-8">
 | 
				
			||||||
 | 
					  <title>Invoice Ninja</title>
 | 
				
			||||||
  <meta name="google-signin-client_id" content="{{ config('services.google.client_id') }}">
 | 
					  <meta name="google-signin-client_id" content="{{ config('services.google.client_id') }}">
 | 
				
			||||||
  <link rel="manifest" href="manifest.json?v={{ config('ninja.app_version') }}">
 | 
					  <link rel="manifest" href="manifest.json?v={{ config('ninja.app_version') }}">
 | 
				
			||||||
  <script src="{{ asset('js/pdf.min.js') }}"></script>
 | 
					  <script src="{{ asset('js/pdf.min.js') }}"></script>
 | 
				
			||||||
  <script type="text/javascript">
 | 
					  <script type="text/javascript">
 | 
				
			||||||
    pdfjsLib.GlobalWorkerOptions.workerSrc = "{{ asset('js/pdf.worker.min.js') }}";
 | 
					    pdfjsLib.GlobalWorkerOptions.workerSrc = "{{ asset('js/pdf.worker.min.js') }}";
 | 
				
			||||||
  </script>
 | 
					  </script>
 | 
				
			||||||
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">
 | 
					</head>
 | 
				
			||||||
  <meta name="description" content="Invoice Clients, Track Work-Time, Get Paid Online.">
 | 
					<body style="background-color:#888888;">
 | 
				
			||||||
  <!-- iOS meta tags & icons -->
 | 
					
 | 
				
			||||||
  <meta name="apple-mobile-web-app-capable" content="yes">
 | 
					 | 
				
			||||||
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
 | 
					 | 
				
			||||||
  <meta name="apple-mobile-web-app-title" content="invoiceninja_client">
 | 
					 | 
				
			||||||
  <link rel="apple-touch-icon" href="icons/Icon-192.png">
 | 
					 | 
				
			||||||
  <title>Invoice Ninja</title>
 | 
					 | 
				
			||||||
  <link rel="manifest" href="manifest.json">
 | 
					 | 
				
			||||||
  <style>
 | 
					  <style>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* fix for blurry fonts 
 | 
				
			||||||
 | 
					    flt-glass-pane {
 | 
				
			||||||
 | 
					        image-rendering: pixelated;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    */
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
    /* https://projects.lukehaas.me/css-loaders/ */
 | 
					    /* https://projects.lukehaas.me/css-loaders/ */
 | 
				
			||||||
    .loader,
 | 
					    .loader,
 | 
				
			||||||
    .loader:before,
 | 
					    .loader:before,
 | 
				
			||||||
@ -34,7 +35,7 @@
 | 
				
			|||||||
      animation: load7 1.8s infinite ease-in-out;
 | 
					      animation: load7 1.8s infinite ease-in-out;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    .loader {
 | 
					    .loader {
 | 
				
			||||||
      color: #FFFFFF;
 | 
					      color: #ffffff;
 | 
				
			||||||
      font-size: 10px;
 | 
					      font-size: 10px;
 | 
				
			||||||
      margin: 80px auto;
 | 
					      margin: 80px auto;
 | 
				
			||||||
      position: relative;
 | 
					      position: relative;
 | 
				
			||||||
@ -79,85 +80,85 @@
 | 
				
			|||||||
        box-shadow: 0 2.5em 0 0;
 | 
					        box-shadow: 0 2.5em 0 0;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  </style>
 | 
					  </style>
 | 
				
			||||||
</head>
 | 
					
 | 
				
			||||||
<body style="background-color:#888888;">
 | 
					 | 
				
			||||||
  <!-- This script installs service_worker.js to provide PWA functionality to
 | 
					 | 
				
			||||||
       application. For more information, see:
 | 
					 | 
				
			||||||
       https://developers.google.com/web/fundamentals/primers/service-workers -->
 | 
					 | 
				
			||||||
  <script>
 | 
					  <script>
 | 
				
			||||||
    @if (request()->clear_local)
 | 
					    @if (request()->clear_local)
 | 
				
			||||||
      window.onload = function() {
 | 
					      window.onload = function() {
 | 
				
			||||||
        window.localStorage.clear();
 | 
					        window.localStorage.clear();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    @endif
 | 
					    @endif
 | 
				
			||||||
    var serviceWorkerVersion = null;
 | 
					    
 | 
				
			||||||
    var scriptLoaded = false;
 | 
					 | 
				
			||||||
    function loadMainDartJs() {
 | 
					 | 
				
			||||||
      if (scriptLoaded) {
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      scriptLoaded = true;
 | 
					 | 
				
			||||||
      var scriptTag = document.createElement('script');
 | 
					 | 
				
			||||||
    @if(config('ninja.flutter_renderer') == 'hosted')
 | 
					 | 
				
			||||||
        scriptTag.src = 'main.dart.js';
 | 
					 | 
				
			||||||
    @else
 | 
					 | 
				
			||||||
        scriptTag.src = 'main.foss.dart.js';
 | 
					 | 
				
			||||||
    @endif
 | 
					 | 
				
			||||||
      scriptTag.type = 'application/javascript';
 | 
					 | 
				
			||||||
      document.body.append(scriptTag);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if ('serviceWorker' in navigator) {
 | 
					    if ('serviceWorker' in navigator) {
 | 
				
			||||||
      // Service workers are supported. Use them.
 | 
					 | 
				
			||||||
      window.addEventListener('load', function () {
 | 
					      window.addEventListener('load', function () {
 | 
				
			||||||
        // Wait for registration to finish before dropping the <script> tag.
 | 
					        navigator.serviceWorker.register('flutter_service_worker.js?v={{ config('ninja.app_version') }}');
 | 
				
			||||||
        // Otherwise, the browser will load the script multiple times,
 | 
					 | 
				
			||||||
        // potentially different versions.
 | 
					 | 
				
			||||||
        var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
 | 
					 | 
				
			||||||
        navigator.serviceWorker.register(serviceWorkerUrl)
 | 
					 | 
				
			||||||
          .then((reg) => {
 | 
					 | 
				
			||||||
            function waitForActivation(serviceWorker) {
 | 
					 | 
				
			||||||
              serviceWorker.addEventListener('statechange', () => {
 | 
					 | 
				
			||||||
                if (serviceWorker.state == 'activated') {
 | 
					 | 
				
			||||||
                  console.log('Installed new service worker.');
 | 
					 | 
				
			||||||
                  loadMainDartJs();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
            if (!reg.active && (reg.installing || reg.waiting)) {
 | 
					
 | 
				
			||||||
              // No active web worker and we have installed or are installing
 | 
					    document.addEventListener('DOMContentLoaded', function(event) {
 | 
				
			||||||
              // one for the first time. Simply wait for it to activate.
 | 
					      document.getElementById('loader').style.display = 'none';
 | 
				
			||||||
              waitForActivation(reg.installing ?? reg.waiting);
 | 
					    });
 | 
				
			||||||
            } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
 | 
					
 | 
				
			||||||
              // When the app updates the serviceWorkerVersion changes, so we
 | 
					    
 | 
				
			||||||
              // need to ask the service worker to update.
 | 
					    function invokeServiceWorkerUpdateFlow() {
 | 
				
			||||||
              console.log('New service worker available.');
 | 
					      // you have a better UI here, reloading is not a great user experince here.
 | 
				
			||||||
              reg.update();
 | 
					      const confirmed = alert('New version of the app is available. Refresh now');
 | 
				
			||||||
              waitForActivation(reg.installing);
 | 
					      if (confirmed == true) {
 | 
				
			||||||
 | 
					        window.location.reload();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    async function handleServiceWorker() {
 | 
				
			||||||
 | 
					      if ('serviceWorker' in navigator) {
 | 
				
			||||||
 | 
					        // get the ServiceWorkerRegistration instance
 | 
				
			||||||
 | 
					        const registration = await navigator.serviceWorker.getRegistration();
 | 
				
			||||||
 | 
					        // (it is also returned from navigator.serviceWorker.register() function)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (registration) {
 | 
				
			||||||
 | 
					          // detect Service Worker update available and wait for it to become installed
 | 
				
			||||||
 | 
					          registration.addEventListener('updatefound', () => {
 | 
				
			||||||
 | 
					            if (registration.installing) {
 | 
				
			||||||
 | 
					              // wait until the new Service worker is actually installed (ready to take over)
 | 
				
			||||||
 | 
					              registration.installing.addEventListener('statechange', () => {
 | 
				
			||||||
 | 
					                if (registration.waiting) {
 | 
				
			||||||
 | 
					                  // if there's an existing controller (previous Service Worker), show the prompt
 | 
				
			||||||
 | 
					                  if (navigator.serviceWorker.controller) {
 | 
				
			||||||
 | 
					                    invokeServiceWorkerUpdateFlow(registration);
 | 
				
			||||||
                  } else {
 | 
					                  } else {
 | 
				
			||||||
              // Existing service worker is still good.
 | 
					                    // otherwise it's the first install, nothing to do
 | 
				
			||||||
              console.log('Loading app from service worker.');
 | 
					                    console.log('Service Worker initialized for the first time');
 | 
				
			||||||
              loadMainDartJs();
 | 
					                  }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
              });
 | 
					              });
 | 
				
			||||||
        // If service worker doesn't succeed in a reasonable amount of time,
 | 
					 | 
				
			||||||
        // fallback to plaint <script> tag.
 | 
					 | 
				
			||||||
        setTimeout(() => {
 | 
					 | 
				
			||||||
          if (!scriptLoaded) {
 | 
					 | 
				
			||||||
            console.warn(
 | 
					 | 
				
			||||||
              'Failed to load app from service worker. Falling back to plain <script> tag.',
 | 
					 | 
				
			||||||
            );
 | 
					 | 
				
			||||||
            loadMainDartJs();
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }, 4000);
 | 
					 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
    } else {
 | 
					
 | 
				
			||||||
      // Service workers not supported. Just drop the <script> tag.
 | 
					          let refreshing = false;
 | 
				
			||||||
      loadMainDartJs();
 | 
					
 | 
				
			||||||
 | 
					          // detect controller change and refresh the page
 | 
				
			||||||
 | 
					          navigator.serviceWorker.addEventListener('controllerchange', () => {
 | 
				
			||||||
 | 
					            if (!refreshing) {
 | 
				
			||||||
 | 
					              window.location.reload();
 | 
				
			||||||
 | 
					              refreshing = true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    handleServiceWorker();
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
  </script>
 | 
					  </script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @if(config('ninja.flutter_renderer') == 'hosted')
 | 
				
			||||||
 | 
					    <script defer src="main.dart.js?v={{ config('ninja.app_version') }}" type="application/javascript"></script>
 | 
				
			||||||
 | 
					  @else
 | 
				
			||||||
 | 
					    <script defer src="main.foss.dart.js?v={{ config('ninja.app_version') }}" type="application/javascript"></script>
 | 
				
			||||||
 | 
					  @endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <center style="padding-top: 150px" id="loader">
 | 
					  <center style="padding-top: 150px" id="loader">
 | 
				
			||||||
    <div class="loader"></div>
 | 
					    <div class="loader"></div>
 | 
				
			||||||
  </center>
 | 
					  </center>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</body>
 | 
					</body>
 | 
				
			||||||
</html>
 | 
					</html>
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user