-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(projects): add version update notifications
- Loading branch information
Showing
8 changed files
with
100 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { Plugin } from 'vite'; | ||
|
||
export function setupHtmlPlugin(buildTime: string) { | ||
const plugin: Plugin = { | ||
name: 'html-plugin', | ||
apply: 'build', | ||
transformIndexHtml(html) { | ||
return html.replace('<head>', `<head>\n <meta name="buildTime" content="${buildTime}">`); | ||
} | ||
}; | ||
|
||
return plugin; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { createElement } from 'react'; | ||
import { Button } from 'antd'; | ||
import { $t } from '../locales'; | ||
|
||
export function setupAppVersionNotification() { | ||
let isShow = false; | ||
|
||
document.addEventListener('visibilitychange', async () => { | ||
const preConditions = [!isShow, document.visibilityState === 'visible', !import.meta.env.DEV]; | ||
|
||
if (!preConditions.every(Boolean)) return; | ||
|
||
const buildTime = await getHtmlBuildTime(); | ||
|
||
if (buildTime === BUILD_TIME) { | ||
return; | ||
} | ||
|
||
isShow = true; | ||
|
||
window.$notification?.open({ | ||
message: $t('system.updateTitle'), | ||
description: $t('system.updateContent'), | ||
btn: (() => { | ||
return createElement( | ||
'div', | ||
{ style: { display: 'flex', justifyContent: 'end', gap: '12px', width: '325px' } }, | ||
[ | ||
createElement( | ||
Button, | ||
{ | ||
onClick() { | ||
window.$notification?.destroy(); | ||
} | ||
}, | ||
$t('system.updateCancel') | ||
), | ||
createElement( | ||
Button, | ||
{ | ||
type: 'primary', | ||
onClick() { | ||
location.reload(); | ||
} | ||
}, | ||
$t('system.updateConfirm') | ||
) | ||
] | ||
); | ||
})(), | ||
onClose() { | ||
isShow = false; | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
async function getHtmlBuildTime() { | ||
const res = await fetch(`/index.html?time=${Date.now()}`); | ||
|
||
const html = await res.text(); | ||
|
||
const match = html.match(/<meta name="buildTime" content="(.*)">/); | ||
|
||
const buildTime = match?.[1] || ''; | ||
|
||
return buildTime; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters