Skip to content

Commit

Permalink
Fix: Display Server Package Updates Correctly in Update Panel (#2003)
Browse files Browse the repository at this point in the history
* Fix: Display Server Package Updates Correctly in Update Panel

fix #1960

* FIX: fetch method to all components

* update:remove logs
  • Loading branch information
mabasian authored Aug 27, 2024
1 parent b85dda2 commit 6d2de78
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
v-else
class="w-4 h-4 bg-red-700 rounded-full p-1 text-[10px] text-gray-200 text-center flex justify-center items-center mr-5"
>
<span>{{ numberOfUpdatablePackages }}</span>
<span>{{ serverStore.numberOfUpdatablePackages }}</span>
</div>
</div>
</div>
Expand Down Expand Up @@ -257,7 +257,7 @@ import ControlService from "@/store/ControlService";
import { useServices } from "@/store/services.js";
import { useNodeHeader } from "@/store/nodeHeader";
import { onMounted, computed, ref, watchEffect } from "vue";
import { useUpdateCheck } from "@/composables/version.js";
import { useUpdateCheck, useUpgradablePackages } from "@/composables/version.js";
import { useServers } from "@/store/servers";
import { useFooter } from "@/store/theFooter";
Expand All @@ -273,14 +273,16 @@ const footerStore = useFooter();
const openButton = ref("Open OS Update Panel");
const { getUpgradablePackages } = useUpgradablePackages();
//Data
const stereumApp = ref({
current: "alpha",
latest: "2.0",
autoUpdate: "",
});
const osVersionCurrent = ref("-");
const numberOfUpdatablePackages = ref(0);
const searchingForOsUpdates = ref(false);
//Computed
Expand Down Expand Up @@ -358,19 +360,15 @@ const searchOsUpdates = async () => {
}
searchingForOsUpdates.value = true;
setTimeout(async () => {
await getUpdatablePackagesCount();
searchingForOsUpdates.value = false;
}, 10);
};
const getUpdatablePackagesCount = async () => {
try {
const packagesCount = await ControlService.getCountOfUpdatableOSUpdate();
const numPackages = Number(packagesCount);
numberOfUpdatablePackages.value = isNaN(numPackages) || !numPackages ? 0 : numPackages;
} catch (error) {
console.log(error);
if (serverStore.numberOfUpdatablePackages === null || serverStore.upgradablePackages.value.length === 0) {
setTimeout(async () => {
await getUpgradablePackages();
serverStore.numberOfUpdatablePackages = serverStore.upgradablePackages.value.length || 0;
searchingForOsUpdates.value = false;
}, 10);
} else {
searchingForOsUpdates.value = false;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
src="/animation/loading/loading-circle.gif"
/>
<div v-else class="w-full col-start-1 col-span-1 bg-red-700 rounded-sm flex justify-center item-center">
<span class="text-sm font-semibold text-gray-300 text-center">{{ numberOfUpdatablePackages }}</span>
<span class="text-sm font-semibold text-gray-300 text-center">{{
serverStore.numberOfUpdatablePackages
}}</span>
</div>

<span class="col-start-2 col-span-full text-md font-semibold text-gray-300">{{
Expand Down Expand Up @@ -98,11 +100,13 @@ import { ref, onMounted, computed, reactive, watchEffect } from "vue";
import { useServers } from "@/store/servers";
import { useFooter } from "@/store/theFooter";
import i18n from "@/includes/i18n";
import { useUpgradablePackages } from "@/composables/version.js";
const t = i18n.global.t;
const footerStore = useFooter();
const serverStore = useServers();
const { getUpgradablePackages } = useUpgradablePackages();
const osVersionCurrent = ref("");
const updateStatus = reactive({
Expand All @@ -114,10 +118,10 @@ const stereumApp = ref({
latest: "2.0",
autoUpdate: "",
});
const numberOfUpdatablePackages = ref(null);
const searchingForUpdatablePackages = ref(false);
const newUpdates = computed(() => serverStore.upgradablePackages);
const newUpdates = computed(() => serverStore.upgradablePackages.value);
const onOff = computed(() => (stereumApp.value.autoUpdate == "on" ? "text-green-700" : "text-red-700"));
//Watchers
Expand All @@ -132,9 +136,16 @@ watchEffect(() => {
//Lifecycle
onMounted(async () => {
await getUpgradablePackages();
searchingForUpdatablePackages.value = true;
if (serverStore.numberOfUpdatablePackages === null || serverStore.upgradablePackages.value.length === 0) {
await getUpgradablePackages();
}
await getOsVersion();
await getSettings();
searchingForUpdatablePackages.value = false;
});
//Methods
Expand All @@ -161,25 +172,31 @@ const getOsVersion = async () => {
}
};
const getUpgradablePackages = async () => {
const fetchUpgradablePackages = async () => {
searchingForUpdatablePackages.value = true;
try {
serverStore.upgradablePackages = await ControlService.getUpgradeablePackages();
if (serverStore.upgradablePackages) {
numberOfUpdatablePackages.value = serverStore.upgradablePackages.length;
if (serverStore.numberOfUpdatablePackages === null || serverStore.upgradablePackages.value.length === 0) {
try {
await getUpgradablePackages();
serverStore.numberOfUpdatablePackages = serverStore.upgradablePackages.value.length;
} catch (error) {
console.error("Failed to fetch upgradable packages:", error);
} finally {
searchingForUpdatablePackages.value = false;
}
} catch (error) {
console.error("Failed to fetch upgradable packages:", error);
serverStore.upgradablePackages = [];
} else {
searchingForUpdatablePackages.value = false;
}
};
const updateAll = async () => {
serverStore.isUpdateProcessing = true;
try {
await ControlService.updateOS();
await getUpgradablePackages(); // Refresh the list of upgradable packages
await fetchUpgradablePackages();
updateStatus.message = "All packages updated successfully!";
updateStatus.color = "text-green-500";
} catch (error) {
Expand Down
53 changes: 44 additions & 9 deletions launcher/src/composables/version.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,48 @@
import ControlService from '@/store/ControlService'
import ControlService from "@/store/ControlService";
import { useNodeHeader } from "@/store/nodeHeader";
import { useServices } from "@/store/services";
import { useBackendServices } from '@/composables/services';
import { useBackendServices } from "@/composables/services";
import { useServers } from "@/store/servers";

export function useUpgradablePackages() {
const serverStore = useServers();

// Method to get upgradable packages
const getUpgradablePackages = async () => {
// Only fetch if the data hasn't been loaded before
if (serverStore.numberOfUpdatablePackages === null || serverStore.upgradablePackages.value.length === 0) {
try {
// Fetch the upgradable packages
const packages = await ControlService.getUpgradeablePackages();
serverStore.upgradablePackages.value = packages || [];

if (serverStore.upgradablePackages.value.length > 0) {
serverStore.numberOfUpdatablePackages = serverStore.upgradablePackages.value.length;
} else {
serverStore.numberOfUpdatablePackages = 0;
}
} catch (error) {
console.error("Failed to fetch upgradable packages:", error);
serverStore.upgradablePackages.value = [];
}
}
};

return {
getUpgradablePackages,
};
}

export async function useUpdateCheck() {
const serviceStore = useServices();
const nodeHeaderStore = useNodeHeader();
if (!nodeHeaderStore.updating) {
nodeHeaderStore.searchingForUpdates = true;

let services = await useBackendServices() //get configurations of all services in backend format
let services = await useBackendServices(); //get configurations of all services in backend format

// fetch all version information
let versions = {}
let versions = {};
try {
versions.latest = await ControlService.checkUpdates();
versions.currentStereum = await ControlService.getCurrentStereumVersion();
Expand All @@ -30,23 +60,29 @@ export async function useUpdateCheck() {
let newAvailableUpdates = [];
if (versions.latest && services?.length > 0) {
services.forEach((service) => {
if (!versions.latest[service.network] || !versions.latest[service.network][service.service]) service.network = "mainnet";
if (!versions.latest[service.network] || !versions.latest[service.network][service.service]) service.network = "prater";
if (!versions.latest[service.network] || !versions.latest[service.network][service.service])
service.network = "mainnet";
if (!versions.latest[service.network] || !versions.latest[service.network][service.service])
service.network = "prater";
if (versions.latest[service.network] && versions.latest[service.network][service.service]) {
if (service.service === "ErigonService" && !service.imageVersion.startsWith("v")) {
service.imageVersion = "v" + service.imageVersion;
service.imageVersion = service.imageVersion.replace("-arm64", "");
}
if (
service.imageVersion !=
versions.latest[service.network][service.service][versions.latest[service.network][service.service].length - 1]
versions.latest[service.network][service.service][
versions.latest[service.network][service.service].length - 1
]
) {
nodeHeaderStore.isUpdateAvailable = true;
newAvailableUpdates.push({
id: service.id,
name: service.service.replace(/(Beacon|Validator|Service)/gm, ""),
version:
versions.latest[service.network][service.service][versions.latest[service.network][service.service].length - 1],
versions.latest[service.network][service.service][
versions.latest[service.network][service.service].length - 1
],
});
console.log("Service Update Available!");
}
Expand Down Expand Up @@ -75,4 +111,3 @@ export async function useUpdateCheck() {
nodeHeaderStore.searchingForUpdates = false;
}
}

1 change: 1 addition & 0 deletions launcher/src/store/servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const useServers = defineStore("servers", {
serverUpdates: [],
isUpdateProcessing: false,
upgradablePackages: [],
numberOfUpdatablePackages: null,
allTasks: [],
isMajorUpgradeActive: false,
isMajorUpgradeButtonActive: false,
Expand Down

0 comments on commit 6d2de78

Please sign in to comment.