All files / app/codeCharta/services/version version.service.ts

100% Statements 16/16
100% Branches 2/2
100% Functions 2/2
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 291x 1x 1x 1x 1x     1x 3x   3x     3x 3x 1x 1x     2x 1x       1x        
import packageJson from "../../../../package.json"
import { Injectable } from "@angular/core"
import { MatDialog } from "@angular/material/dialog"
import { ChangelogDialogComponent } from "../../ui/dialogs/changelogDialog/changelogDialog.component"
import { compareVersion } from "./utils/compareVersion"
 
@Injectable({ providedIn: "root" })
export class VersionService {
    readonly version = packageJson.version
 
    constructor(private dialog: MatDialog) {}
 
    synchronizeLocalCodeChartaVersion() {
        const savedPreviousVersion = localStorage.getItem("codeChartaVersion")
        if (savedPreviousVersion === null) {
            localStorage.setItem("codeChartaVersion", this.version)
            return
        }
 
        if (compareVersion(savedPreviousVersion, this.version) < 0) {
            this.dialog.open(ChangelogDialogComponent, {
                panelClass: "cc-changelog-dialog",
                data: { previousVersion: savedPreviousVersion, currentVersion: this.version }
            })
            localStorage.setItem("codeChartaVersion", this.version)
        }
    }
}