mirror of
https://github.com/ivabus/gui
synced 2025-04-23 14:07:14 +03:00
Detect if tea cli is installed or needs update and prompt user (#251)
* issue-230: detect if tea cli is installed or needs update and prompt user * issue-230: detect if tea cli is installed or needs update and prompt user --------- Co-authored-by: neil <neil@neils-MacBook-Pro.local>
This commit is contained in:
parent
6e6c636d9c
commit
beb57ce015
5 changed files with 167 additions and 14 deletions
101
modules/desktop/src/components/tea-update/tea-update.svelte
Normal file
101
modules/desktop/src/components/tea-update/tea-update.svelte
Normal file
|
@ -0,0 +1,101 @@
|
|||
<script lang="ts">
|
||||
import { t } from '$libs/translations';
|
||||
import Button from '@tea/ui/button/button.svelte';
|
||||
import { openTerminal } from '@native';
|
||||
import { packagesStore } from '$libs/stores';
|
||||
import { PackageStates, type GUIPackage } from '$libs/types';
|
||||
|
||||
type CliUpdateState = 'unknown' | 'not_installed' | 'update_required' | 'up_to_date' | 'updated';
|
||||
|
||||
$: updateState = 'unknown' as CliUpdateState;
|
||||
|
||||
const getCliUpdateState = (pkg: GUIPackage | null): CliUpdateState => {
|
||||
if (!pkg) {
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
if (pkg.state != PackageStates.INSTALLED){
|
||||
return 'not_installed';
|
||||
}
|
||||
|
||||
if (!pkg.installed_versions?.includes(pkg.version)) {
|
||||
return 'update_required';
|
||||
}
|
||||
|
||||
return 'up_to_date';
|
||||
}
|
||||
|
||||
packagesStore.subscribeToPackage("tea_xyz", (pkg) => {
|
||||
if (updateState !== 'updated' ) {
|
||||
updateState = getCliUpdateState(pkg);
|
||||
}
|
||||
});
|
||||
|
||||
const onOpenTerminal = async () => {
|
||||
console.log("installing tea...")
|
||||
try {
|
||||
openTerminal(`sh <(curl https://tea.xyz)`);
|
||||
} catch (error) {
|
||||
console.log("install failed")
|
||||
}
|
||||
updateState = 'updated';
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if updateState === 'not_installed'}
|
||||
<div class="banner flex items-center justify-center text-primary">
|
||||
<span class="text-white mr-4">{$t('package.install-tea-cli')}</span>
|
||||
<button class="button" on:click={onOpenTerminal}>{$t("package.install-tea-label")}</button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if updateState === 'update_required'}
|
||||
<div class="banner flex items-center justify-center text-primary">
|
||||
<span class="text-white mr-4">{$t('package.update-tea-cli')}</span>
|
||||
<button class="button" on:click={onOpenTerminal}>{$t("package.update-tea-label")}</button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.banner {
|
||||
background-color: #FF4100;
|
||||
margin-bottom: 16px;
|
||||
border-radius: 4px;
|
||||
padding: 6px;
|
||||
z-index: 1;
|
||||
position: relative;
|
||||
padding-top: 12px;
|
||||
padding-bottom: 12px;
|
||||
}
|
||||
|
||||
.button {
|
||||
color: white;
|
||||
border: 1px solid white;
|
||||
padding: 6px 24px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.button::before {
|
||||
position: absolute;
|
||||
content: "";
|
||||
background: #e1e1e1;
|
||||
transition-duration: 0.2s;
|
||||
z-index: -1;
|
||||
inset: 0px auto auto 0px;
|
||||
width: 0px;
|
||||
height: 100%;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.button:hover::before {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
color: #1a1a1a;
|
||||
background: #e1e1e1;
|
||||
transition: color 0.3s ease 0s, background 0s ease 0.3s;
|
||||
}
|
||||
</style>
|
|
@ -140,7 +140,7 @@ export const openTerminal = (cmd: string) => ipcRenderer.invoke("open-terminal",
|
|||
export const shellOpenExternal = (link: string) => shell.openExternal(link);
|
||||
|
||||
export const listenToChannel = (channel: string, callback: (msg: string, ...args: any) => void) => {
|
||||
ipcRenderer.on(channel, (_, message: string, ...args: any[]) => callback(message, ...args));
|
||||
ipcRenderer.on(channel, (_: any, message: string, ...args: any[]) => callback(message, ...args));
|
||||
};
|
||||
|
||||
export const relaunch = () => ipcRenderer.invoke("relaunch");
|
||||
|
|
|
@ -38,7 +38,11 @@
|
|||
"reinstall-label": "re-install",
|
||||
"my-installs-title": "my installs",
|
||||
"check-for-updates": "check for updates",
|
||||
"details": "details"
|
||||
"details": "details",
|
||||
"install-tea-label": "Install tea cli",
|
||||
"update-tea-label": "Update now",
|
||||
"install-tea-cli": "This app requires our command-line interface",
|
||||
"update-tea-cli": "An update is available for tea cli"
|
||||
},
|
||||
"script": {
|
||||
"top-list-title": "Top scripts this week",
|
||||
|
@ -112,7 +116,11 @@
|
|||
"reinstall-label": "re-install",
|
||||
"my-installs-title": "my installs",
|
||||
"check-for-updates": "check for updates",
|
||||
"details": "details"
|
||||
"details": "details",
|
||||
"install-tea-label": "Install tea cli",
|
||||
"update-tea-label": "Update now",
|
||||
"install-tea-cli": "This app requires our command-line interface",
|
||||
"update-tea-cli": "An update is available for tea cli"
|
||||
},
|
||||
"script": {
|
||||
"top-list-title": "Top scripts this week",
|
||||
|
@ -186,7 +194,11 @@
|
|||
"reinstall-label": "re-install",
|
||||
"my-installs-title": "my installs",
|
||||
"check-for-updates": "check for updates",
|
||||
"details": "details"
|
||||
"details": "details",
|
||||
"install-tea-label": "Install tea cli",
|
||||
"update-tea-label": "Update now",
|
||||
"install-tea-cli": "This app requires our command-line interface",
|
||||
"update-tea-cli": "An update is available for tea cli"
|
||||
},
|
||||
"script": {
|
||||
"top-list-title": "Top scripts this week",
|
||||
|
@ -261,7 +273,11 @@
|
|||
"needs-update-label": "update",
|
||||
"my-installs-title": "my installs",
|
||||
"check-for-updates": "check for updates",
|
||||
"details": "details"
|
||||
"details": "details",
|
||||
"install-tea-label": "Install tea cli",
|
||||
"update-tea-label": "Update now",
|
||||
"install-tea-cli": "This app requires our command-line interface",
|
||||
"update-tea-cli": "An update is available for tea cli"
|
||||
},
|
||||
"script": {
|
||||
"top-list-title": "Top scripts this week",
|
||||
|
@ -335,7 +351,11 @@
|
|||
"reinstall-label": "re-install",
|
||||
"my-installs-title": "my installs",
|
||||
"check-for-updates": "check for updates",
|
||||
"details": "details"
|
||||
"details": "details",
|
||||
"install-tea-label": "Install tea cli",
|
||||
"update-tea-label": "Update now",
|
||||
"install-tea-cli": "This app requires our command-line interface",
|
||||
"update-tea-cli": "An update is available for tea cli"
|
||||
},
|
||||
"script": {
|
||||
"top-list-title": "Top scripts this week",
|
||||
|
@ -409,7 +429,11 @@
|
|||
"reinstall-label": "neu installieren",
|
||||
"my-installs-title": "my installs",
|
||||
"check-for-updates": "check for updates",
|
||||
"details": "details"
|
||||
"details": "details",
|
||||
"install-tea-label": "Install tea cli",
|
||||
"update-tea-label": "Update now",
|
||||
"install-tea-cli": "This app requires our command-line interface",
|
||||
"update-tea-cli": "An update is available for tea cli"
|
||||
},
|
||||
"script": {
|
||||
"top-list-title": "Top scripts this week",
|
||||
|
@ -483,7 +507,11 @@
|
|||
"reinstall-label": "re-install",
|
||||
"my-installs-title": "my installs",
|
||||
"check-for-updates": "check for updates",
|
||||
"details": "details"
|
||||
"details": "details",
|
||||
"install-tea-label": "Install tea cli",
|
||||
"update-tea-label": "Update now",
|
||||
"install-tea-cli": "This app requires our command-line interface",
|
||||
"update-tea-cli": "An update is available for tea cli"
|
||||
},
|
||||
"script": {
|
||||
"top-list-title": "Top scripts this week",
|
||||
|
@ -557,7 +585,11 @@
|
|||
"reinstall-label": "re-install",
|
||||
"my-installs-title": "my installs",
|
||||
"check-for-updates": "check for updates",
|
||||
"details": "details"
|
||||
"details": "details",
|
||||
"install-tea-label": "Install tea cli",
|
||||
"update-tea-label": "Update now",
|
||||
"install-tea-cli": "This app requires our command-line interface",
|
||||
"update-tea-cli": "An update is available for tea cli"
|
||||
},
|
||||
"script": {
|
||||
"top-list-title": "Top scripts this week",
|
||||
|
@ -631,7 +663,11 @@
|
|||
"reinstall-label": "re-install",
|
||||
"my-installs-title": "my installs",
|
||||
"check-for-updates": "check for updates",
|
||||
"details": "details"
|
||||
"details": "details",
|
||||
"install-tea-label": "Install tea cli",
|
||||
"update-tea-label": "Update now",
|
||||
"install-tea-cli": "This app requires our command-line interface",
|
||||
"update-tea-cli": "An update is available for tea cli"
|
||||
},
|
||||
"script": {
|
||||
"top-list-title": "Top scripts this week",
|
||||
|
@ -705,7 +741,11 @@
|
|||
"reinstall-label": "re-install",
|
||||
"my-installs-title": "my installs",
|
||||
"check-for-updates": "check for updates",
|
||||
"details": "details"
|
||||
"details": "details",
|
||||
"install-tea-label": "Install tea cli",
|
||||
"update-tea-label": "Update now",
|
||||
"install-tea-cli": "This app requires our command-line interface",
|
||||
"update-tea-cli": "An update is available for tea cli"
|
||||
},
|
||||
"script": {
|
||||
"top-list-title": "Top scripts this week",
|
||||
|
@ -779,7 +819,11 @@
|
|||
"reinstall-label": "re-install",
|
||||
"my-installs-title": "my installs",
|
||||
"check-for-updates": "check for updates",
|
||||
"details": "details"
|
||||
"details": "details",
|
||||
"install-tea-label": "Install tea cli",
|
||||
"update-tea-label": "Update now",
|
||||
"install-tea-cli": "This app requires our command-line interface",
|
||||
"update-tea-cli": "An update is available for tea cli"
|
||||
},
|
||||
"script": {
|
||||
"top-list-title": "Top scripts this week",
|
||||
|
@ -853,7 +897,11 @@
|
|||
"reinstall-label": "re-install",
|
||||
"my-installs-title": "my installs",
|
||||
"check-for-updates": "check for updates",
|
||||
"details": "details"
|
||||
"details": "details",
|
||||
"install-tea-label": "Install tea cli",
|
||||
"update-tea-label": "Update now",
|
||||
"install-tea-cli": "This app requires our command-line interface",
|
||||
"update-tea-cli": "An update is available for tea cli"
|
||||
},
|
||||
"script": {
|
||||
"top-list-title": "Top scripts this week",
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
import SearchPopupResults from '$components/search-popup-results/search-popup-results.svelte';
|
||||
|
||||
import TeaUpdate from '$components/tea-update/tea-update.svelte';
|
||||
|
||||
let view: HTMLElement;
|
||||
|
||||
$: if ($navigating) view.scrollTop = 0;
|
||||
|
@ -29,6 +31,9 @@
|
|||
<Notification {notification} />
|
||||
{/each}
|
||||
<section class="relative pt-24" bind:this={view}>
|
||||
<div class="content">
|
||||
<TeaUpdate />
|
||||
</div>
|
||||
<figure />
|
||||
<div class="content">
|
||||
<slot />
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<script lang="ts">
|
||||
import Button from "../button/button.svelte";
|
||||
import ImgLoader from "../img-loader/img-loader.svelte";
|
||||
import type { ListActionItem } from "../types";
|
||||
|
||||
export let title: string;
|
||||
|
|
Loading…
Reference in a new issue