feat: Added "Whats New" indicator to Preferences button (#2107)

This commit is contained in:
Aman Harwara
2022-12-17 00:35:25 +05:30
committed by GitHub
parent 51aed0a518
commit f559442a67
4 changed files with 46 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
import { Environment } from '@standardnotes/models'
import { StorageServiceInterface, StorageKey } from '@standardnotes/services'
import { Changelog, ChangelogVersion } from './Changelog'
import { ChangelogServiceInterface } from './ChangelogServiceInterface'
import { ChangelogLastReadVersionListener, ChangelogServiceInterface } from './ChangelogServiceInterface'
import { LegacyWebToDesktopVersionMapping } from './LegacyDesktopMapping'
import { LegacyWebToMobileVersionMapping } from './LegacyMobileMapping'
@@ -10,9 +10,18 @@ const DesktopDownloadsUrlBase = 'https://github.com/standardnotes/app/releases/t
export class ChangelogService implements ChangelogServiceInterface {
private changeLog?: Changelog
private lastReadChangeListeners: ChangelogLastReadVersionListener[] = []
constructor(private environment: Environment, private diskService: StorageServiceInterface) {}
public addLastReadChangeListener(listener: ChangelogLastReadVersionListener) {
this.lastReadChangeListeners.push(listener)
return () => {
this.lastReadChangeListeners = this.lastReadChangeListeners.filter((l) => l !== listener)
}
}
private async performDownloadChangelog(): Promise<Changelog> {
const response = await fetch(WebChangelogUrl)
const changelog = await response.text()
@@ -47,7 +56,11 @@ export class ChangelogService implements ChangelogServiceInterface {
return
}
this.diskService.setValue(StorageKey.LastReadChangelogVersion, this.changeLog.versions[0].version)
const version = this.changeLog.versions[0].version
this.diskService.setValue(StorageKey.LastReadChangelogVersion, version)
if (version) {
this.lastReadChangeListeners.forEach((listener) => listener(version))
}
}
public getLastReadVersion(): string | undefined {

View File

@@ -1,6 +1,9 @@
import { Changelog, ChangelogVersion } from './Changelog'
export type ChangelogLastReadVersionListener = (version: string) => void
export interface ChangelogServiceInterface {
addLastReadChangeListener(listener: ChangelogLastReadVersionListener): () => void
getChangelog(): Promise<Changelog>
getVersions(): Promise<ChangelogVersion[]>
getDesktopDownloadsUrl(version: string): string