mirror of
https://github.com/rommapp/romm.git
synced 2026-06-28 06:46:00 +00:00
check if new version is available
This commit is contained in:
@@ -31,10 +31,10 @@ from utils.auth import (
|
||||
CustomCSRFMiddleware,
|
||||
create_default_admin_user,
|
||||
)
|
||||
from utils import get_version
|
||||
from utils import get_version, check_new_version
|
||||
from config.config_loader import config, ConfigDict
|
||||
|
||||
app = FastAPI(title="RomM API", version="0.1.0")
|
||||
app = FastAPI(title="RomM API", version=get_version())
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
@@ -95,6 +95,7 @@ class SchedulerDict(TypedDict):
|
||||
|
||||
class HeartbeatReturn(TypedDict):
|
||||
VERSION: str
|
||||
NEW_VERSION: str | None
|
||||
ROMM_AUTH_ENABLED: bool
|
||||
WATCHER: WatcherDict
|
||||
SCHEDULER: SchedulerDict
|
||||
@@ -106,6 +107,7 @@ class HeartbeatReturn(TypedDict):
|
||||
def heartbeat() -> HeartbeatReturn:
|
||||
return {
|
||||
"VERSION": get_version(),
|
||||
"NEW_VERSION": check_new_version(),
|
||||
"ROMM_AUTH_ENABLED": ROMM_AUTH_ENABLED,
|
||||
"WATCHER": {
|
||||
"ENABLED": ENABLE_RESCAN_ON_FILESYSTEM_CHANGE,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import re
|
||||
import requests
|
||||
import subprocess as sp
|
||||
from packaging.version import parse, InvalidVersion
|
||||
from __version__ import __version__
|
||||
|
||||
LANGUAGES = [
|
||||
@@ -143,3 +145,17 @@ def get_version() -> str | None:
|
||||
return None
|
||||
branch = [a for a in output.split("\n") if a.find("*") >= 0][0]
|
||||
return branch[branch.find("*") + 2 :]
|
||||
|
||||
|
||||
def check_new_version() -> str | None:
|
||||
response = requests.get("https://api.github.com/repos/zurdi15/romm/releases/latest")
|
||||
try:
|
||||
last_version = response.json()["name"][1:] # remove leading 'v' from 'vX.X.X'
|
||||
except KeyError: # rate limit reached
|
||||
return None
|
||||
try:
|
||||
if parse(get_version()) < parse(last_version):
|
||||
return last_version
|
||||
except InvalidVersion:
|
||||
pass
|
||||
return None
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { inject } from "vue";
|
||||
import { inject, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import type { Emitter } from "mitt";
|
||||
import type { Events } from "@/types/emitter";
|
||||
|
||||
import storeAuth from "@/stores/auth";
|
||||
import { defaultAvatarPath } from "@/utils"
|
||||
import storeHeartbeat from "@/stores/heartbeat";
|
||||
import { defaultAvatarPath } from "@/utils";
|
||||
import { api } from "@/services/api";
|
||||
|
||||
// Props
|
||||
@@ -13,8 +13,17 @@ defineProps<{ rail?: boolean }>();
|
||||
const router = useRouter();
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
const auth = storeAuth();
|
||||
const heartbeat = storeHeartbeat();
|
||||
const newVersion = heartbeat.data.NEW_VERSION;
|
||||
localStorage.setItem("newVersion", newVersion)
|
||||
const newVersionDismissed = ref(localStorage.getItem("dismissNewVersion") === newVersion);
|
||||
|
||||
// Functions
|
||||
function dismissNewVersion() {
|
||||
localStorage.setItem("dismissNewVersion", newVersion);
|
||||
newVersionDismissed.value = true;
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
api
|
||||
.post("/logout", {})
|
||||
@@ -38,8 +47,12 @@ async function logout() {
|
||||
<template>
|
||||
<v-list-item height="60" class="bg-primary text-button" rounded="0">
|
||||
<template v-if="!rail">
|
||||
<div class="text-no-wrap text-truncate text-subtitle-1">{{ auth.user?.username }}</div>
|
||||
<div class="text-no-wrap text-truncate text-caption text-romm-accent-1">{{ auth.user?.role }}</div>
|
||||
<div class="text-no-wrap text-truncate text-subtitle-1">
|
||||
{{ auth.user?.username }}
|
||||
</div>
|
||||
<div class="text-no-wrap text-truncate text-caption text-romm-accent-1">
|
||||
{{ auth.user?.role }}
|
||||
</div>
|
||||
</template>
|
||||
<template v-slot:prepend>
|
||||
<v-avatar :class="{ 'my-2': rail }">
|
||||
@@ -69,4 +82,18 @@ async function logout() {
|
||||
block
|
||||
@click="logout()"
|
||||
></v-btn>
|
||||
<v-list-item
|
||||
class="bg-terciary py-3"
|
||||
v-if="newVersion && !newVersionDismissed"
|
||||
>
|
||||
<v-col class="px-0 py-1">
|
||||
<span
|
||||
>New version available <span class="text-romm-accent-1">{{ newVersion }}</span></span
|
||||
>
|
||||
</v-col>
|
||||
<v-col class="px-0 py-1">
|
||||
<span><a target="_blank" :href="`https://github.com/zurdi15/romm/releases/tag/v${newVersion}`">See what's new!</a></span>
|
||||
</v-col>
|
||||
<template v-slot:append><v-icon title="Dismiss" @click="dismissNewVersion()">mdi-close</v-icon></template>
|
||||
</v-list-item>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user