-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: check for vue updates, closes #1181
- Loading branch information
Showing
4 changed files
with
135 additions
and
43 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
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
69 changes: 69 additions & 0 deletions
69
packages/app-frontend/src/features/header/AppSelectItem.vue
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,69 @@ | ||
<script lang="ts"> | ||
import { defineComponent, computed } from '@vue/composition-api' | ||
import { useVueVersionCheck } from './vue-version-check' | ||
export default defineComponent({ | ||
props: { | ||
app: { | ||
type: Object, | ||
required: true | ||
} | ||
}, | ||
setup (props) { | ||
const { getLatestVersion } = useVueVersionCheck() | ||
const latestVersion = computed(() => getLatestVersion(props.app.version)) | ||
const hasNewVersion = computed(() => latestVersion.value !== props.app.version) | ||
return { | ||
latestVersion, | ||
hasNewVersion | ||
} | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="leading-tight"> | ||
<div class="app-button flex items-center"> | ||
<span class="truncate flex-1">{{ app.name }}</span> | ||
<span class="flex-none flex items-center"> | ||
<img | ||
src="~@front/assets/vue-logo.svg" | ||
class="w-6 h-6" | ||
alt="Vue" | ||
> | ||
<span>{{ app.version }}</span> | ||
<span | ||
v-if="hasNewVersion" | ||
class="ml-2 text-sm text-green-500 flex items-center space-x-0.5" | ||
> | ||
<VueIcon | ||
icon="new_releases" | ||
class="w-5 h-5" | ||
/> | ||
<span>{{ latestVersion }}</span> | ||
</span> | ||
</span> | ||
|
||
<template v-if="$shared.debugInfo"> | ||
<span | ||
v-tooltip="'id'" | ||
class="text-white px-1 rounded bg-gray-500 mx-1" | ||
> | ||
{{ app.id }} | ||
</span> | ||
</template> | ||
</div> | ||
<div | ||
v-if="app.iframe" | ||
class="flex items-center space-x-1 text-2xs font-mono text-gray-500" | ||
> | ||
<VueIcon | ||
icon="web" | ||
class="w-4 h-4" | ||
/> | ||
<span>{{ app.iframe }}</span> | ||
</div> | ||
</div> | ||
</template> |
35 changes: 35 additions & 0 deletions
35
packages/app-frontend/src/features/header/vue-version-check.ts
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,35 @@ | ||
import { ref, onMounted } from '@vue/composition-api' | ||
import semver from 'semver' | ||
|
||
const packageData = ref<any>(null) | ||
|
||
export function useVueVersionCheck () { | ||
onMounted(async () => { | ||
if (!packageData.value) { | ||
try { | ||
const response = await fetch('https://registry.npmjs.org/vue', { | ||
headers: { | ||
mode: 'no-cors' | ||
} | ||
}) | ||
const data = await response.json() | ||
packageData.value = data | ||
} catch (e) { | ||
if (process.env.NODE_ENV !== 'development') { | ||
console.error(e) | ||
} | ||
} | ||
} | ||
}) | ||
|
||
function getLatestVersion (currentVersion: string): string { | ||
if (packageData.value && packageData.value.versions) { | ||
return semver.maxSatisfying(Object.keys(packageData.value.versions), `^${currentVersion}`) | ||
} | ||
return currentVersion | ||
} | ||
|
||
return { | ||
getLatestVersion | ||
} | ||
} |