Make Angular PWA automatically installable on windows desktop

39 Views Asked by At

I have created an angular PWA app which I can install using browser's built-in install option or prompting the user through event "beforeinstallprompt" . But I want to distribute my software as windows desktop app , so it should be directly installable without manually installing through browser window. Also, I dont want to use any framework like electron.

Reference to my app.component.ts

import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { DisplayComponent } from './display/display.component';
import { SwUpdate } from '@angular/service-worker';


@Component({
  selector: 'app-root',
  standalone: true,
  imports: [RouterOutlet, DisplayComponent],
  templateUrl: './app.component.html',
  styleUrl: './app.component.css'
})
export class AppComponent {
  title = 'ConfigAppPwa';

  constructor(private swUpdate: SwUpdate){}

  ngOnInit() {
    // Listen for the beforeinstallprompt event
    window.addEventListener('beforeinstallprompt', (event: any) => {
      event.preventDefault(); // Prevent the default browser prompt
      const installPrompt = confirm('Install the app?');
      
      if (installPrompt) {
        event.prompt(); // Show the custom install prompt
        event.userChoice.then((choiceResult: any) => {
          if (choiceResult.outcome === 'accepted') {
            console.log('User accepted the install prompt');
          } else {
            console.log('User dismissed the install prompt');
          }
        });
      }
    });

  }


}
0

There are 0 best solutions below