Skip to content

Commit 91039e9

Browse files
committed
version: add What's new link
Signed-off-by: 🕷️ <[email protected]>
1 parent b96546d commit 91039e9

File tree

5 files changed

+68
-7
lines changed

5 files changed

+68
-7
lines changed

build.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const buildOptions: BuildOptions = {
2626
__app_name__: `"browser-api-monitor@${manifest.version}"`,
2727
__app_version__: `"${manifest.version}"`,
2828
__home_page__: `"${manifest.homepage_url}"`,
29+
__release_page__:
30+
`"https://github.com/zendive/browser-api-monitor/releases"`,
2931
__mirror__: `${isMirror}`,
3032
},
3133
bundle: true,

src/api/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const APPLICATION_VERSION = __app_version__;
22
export const APPLICATION_NAME = __app_name__;
33
export const APPLICATION_HOME_PAGE = __home_page__;
4+
export const APPLICATION_RELEASE_PAGE = __release_page__;

src/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ declare global {
55
let __app_name__: string;
66
let __app_version__: string;
77
let __home_page__: string;
8+
let __release_page__: string;
89
let __mirror__: boolean;
910
}

src/state/meta.state.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { local } from '../api/storage/storage.ts';
2+
import { APPLICATION_VERSION } from '../api/env.ts';
3+
4+
const METADATA_KEY = 'METADATA';
5+
6+
/**
7+
* Check if current extension's version has been written in local storage
8+
* and if not - assume it's a newer version or fresh install
9+
*/
10+
export async function isExtensionFresh() {
11+
const meta = await local.get([METADATA_KEY]);
12+
13+
return !meta || !meta[METADATA_KEY] || !meta[METADATA_KEY].version ||
14+
meta[METADATA_KEY].version !== APPLICATION_VERSION;
15+
}
16+
17+
export function rememberCurrentVersion() {
18+
local.set({ [METADATA_KEY]: { version: APPLICATION_VERSION } }).catch(
19+
() => {},
20+
);
21+
}

src/view/menu/Version.svelte

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,50 @@
11
<script lang="ts">
22
import {
33
APPLICATION_HOME_PAGE,
4+
APPLICATION_RELEASE_PAGE,
45
APPLICATION_VERSION,
56
} from '../../api/env.ts';
7+
import { onMount } from 'svelte';
8+
import {
9+
isExtensionFresh,
10+
rememberCurrentVersion,
11+
} from '../../state/meta.state.ts';
12+
13+
let isFresh = $state(false);
14+
15+
onMount(async () => {
16+
isFresh = await isExtensionFresh();
17+
});
18+
19+
function onClick() {
20+
rememberCurrentVersion();
21+
isFresh = false;
22+
}
623
</script>
724

8-
<a
9-
target="_blank"
10-
href={APPLICATION_HOME_PAGE}
11-
title={APPLICATION_HOME_PAGE}
12-
>
13-
v{APPLICATION_VERSION}
14-
</a>
25+
{#if isFresh}
26+
<a
27+
target="_blank"
28+
href={APPLICATION_RELEASE_PAGE}
29+
title="What's new"
30+
class="is-fresh"
31+
onclick={onClick}
32+
>
33+
v{APPLICATION_VERSION}
34+
</a>
35+
{:else}
36+
<a
37+
target="_blank"
38+
href={APPLICATION_HOME_PAGE}
39+
title={APPLICATION_HOME_PAGE}
40+
>
41+
v{APPLICATION_VERSION}
42+
</a>
43+
{/if}
44+
45+
<style lang="scss">
46+
.is-fresh {
47+
color: var(--attention);
48+
font-weight: bold;
49+
}
50+
</style>

0 commit comments

Comments
 (0)