import { Injectable } from '@angular/core' ; import { Globals } from '../shared/globals' ; import { SharedService } from './sharedService' ; @ Injectable ( ) export class BrowserService implements SharedService { private static readonly modName = 'selectedMod' ; constructor ( ) { if ( Globals . isElectron ) { return ; } } public static async init ( ) { if ( Globals . isElectron ) { return ; } const selectedMod = localStorage . getItem ( this . modName ) || '' ; try { await this . updateMod ( selectedMod ) ; } catch ( ex ) { console . error ( 'Could not select mod: ' , ex ) ; } } private static async updateMod ( mod ) { await fetch ( Globals . URL + 'api/select' , { method : 'POST' , headers : { 'Accept' : 'application/json' , 'Content-Type' : 'application/json' } , body : JSON . stringify ( { mod } ) } ) ; } public async saveModSelect ( mod ) { localStorage . setItem ( BrowserService . modName , mod ) ; await BrowserService . updateMod ( mod ) ; } public getSelectedMod ( ) { return localStorage . getItem ( BrowserService . modName ) || '' ; } public relaunch ( ) { location . reload ( ) ; } }