Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Somfic/EliteVA
Browse files Browse the repository at this point in the history
  • Loading branch information
Somfic committed Apr 14, 2024
2 parents ae4b30a + 1126e44 commit 590f361
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 61 deletions.
3 changes: 2 additions & 1 deletion src-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"type": "module",
"dependencies": {
"@tauri-apps/api": "^1.5.3",
"sass": "^1.72.0"
"sass": "^1.72.0",
"svelte-markdown": "^0.4.1"
}
}
192 changes: 156 additions & 36 deletions src-client/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import Logo from '$lib/Logo.svelte';
import SvelteMarkdown from 'svelte-markdown';
import { invoke } from '@tauri-apps/api/tauri';
import { listen } from '@tauri-apps/api/event';
import { onMount } from 'svelte';
Expand All @@ -20,10 +20,27 @@
error_message: string;
}
interface NewVersion {
title: string;
version: string;
changelog: string;
url: string;
}
onMount(() => {
progress = 'fetching';
text = 'Starting updater ... ';
listen('new_version', (event) => {
let message = event.payload as NewVersion;
title = message.title;
version = message.version;
changelog = message.changelog;
url = message.url;
invoke('show_window');
});
listen('message', (event) => {
let message = event.payload as Message;
progress = message.is_fetching ? 'fetching' : message.progress;
Expand All @@ -37,15 +54,23 @@
});
listen('error', (event) => {
isPrompting = false;
let message = event.payload as Error;
progress = 'none';
text = message.message;
error_message = message.error_message;
});
invoke('update_eliteva');
invoke('get_new_version');
});
let isPrompting = true;
let title: string;
let version: string;
let changelog: string;
let url: string;
let progress: number | 'fetching' | 'none' = 'none';
let text: string = '';
let error_message = '';
Expand All @@ -54,23 +79,68 @@
// Copy error message to clipboard
navigator.clipboard.writeText(error_message);
}
function updateNow() {
isPrompting = false;
invoke('update_now');
}
function updateLater() {
isPrompting = false;
invoke('update_later');
}
function skipUpdate() {
isPrompting = false;
invoke('skip_update');
}
</script>

<main>
<Logo />
<h3>VoiceAttack plugin for Elite: Dangerous</h3>
<div class="progress" class:none={progress == 'none'}>
{#if progress === 'none'}
<div class="progress-bar" style="width: 0%"></div>
{:else if progress === 'fetching'}
<div class="progress-bar fetching" style="width: 100%"></div>
{:else}
<div class="progress-bar number" style="width: {progress}%"></div>
{/if}
</div>
<h2>{text}</h2>
{#if error_message}
<button on:click={() => copy()}>Copy error code</button>
<main class:prompt={isPrompting}>
{#if isPrompting}
<div class="header">
<h3>A new EliteVA update is available!</h3>
<h1>{title}</h1>
<h2 class="pill">EliteVA {version}</h2>
</div>
<div class="content">
<p><b>Changelog</b></p>
<SvelteMarkdown source={changelog} />
<!-- <a href={url} target="_blank">See GitHub release</a> -->
</div>
<div class="footer">
<div class="buttons">
<button class="main" on:click={() => updateNow()}>Update now</button>
<button on:click={() => updateLater()}>Remind me later</button>
<!-- <button on:click={() => skipUpdate()}>Skip this version</button> -->
</div>
</div>
{:else}
<div class="header">
<Logo />
<h3>VoiceAttack plugin for Elite: Dangerous</h3>
</div>
<div class="content">
<div class="progress" class:none={progress == 'none'}>
{#if progress === 'none'}
<div class="progress-bar" style="width: 0%"></div>
{:else if progress === 'fetching'}
<div class="progress-bar fetching" style="width: 100%"></div>
{:else}
<div class="progress-bar number" style="width: {progress}%"></div>
{/if}
</div>
</div>
<div class="footer">
<h3>{text}</h3>
<div class="buttons">
{#if error_message}
<button on:click={() => copy()}>Copy error code</button>
{:else}
<button class="hidden" />
{/if}
</div>
</div>
{/if}
</main>

Expand All @@ -81,26 +151,47 @@
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-top: 80px;
height: 100vh;
padding: 0 5rem;
}
padding: 2rem 4rem;
.header {
text-align: center;
h3 {
opacity: 0.5;
font-weight: 500;
font-size: 1rem;
}
}
.content {
flex-grow: 1;
margin-top: 4rem;
}
h2 {
text-align: center;
margin-top: 2rem;
font-size: 1.25rem;
font-weight: 600;
color: rgba(255, 255, 255, 0.9);
.footer {
}
}
h3 {
text-align: center;
margin-top: 0;
font-size: 1rem;
font-weight: 500;
color: rgba(255, 255, 255, 0.85);
.title {
display: flex;
flex-direction: column;
gap: 1rem;
h1,
h2,
h3 {
margin: 0;
}
h1 {
font-size: 2rem;
}
h2 {
font-size: 1.5rem;
opacity: 0.5;
}
}
.progress {
Expand Down Expand Up @@ -141,15 +232,38 @@
}
}
.buttons {
display: flex;
flex-grow: 1;
align-items: center;
justify-content: center;
}
.pill,
button {
font-size: 0.8em;
font-size: 0.9em;
opacity: 0.85;
cursor: pointer;
margin: 0 0.2rem;
background-color: rgba(255, 255, 255, 0.1);
border-radius: 10px;
border: 2px solid rgba(255, 255, 255, 0.25);
padding: 5px 10px;
padding: 5px 12px;
transition: 200ms ease;
}
button {
cursor: pointer;
&.main {
background-color: $accent;
border: 2px solid rgba(255, 255, 255, 0.5);
font-weight: bold;
&:hover {
background-color: lighten($accent, 0.6);
}
}
&:hover {
background-color: rgba(255, 255, 255, 0.25);
Expand All @@ -160,6 +274,12 @@
}
}
a {
color: $accent;
cursor: pointer;
text-decoration: underline;
}
@keyframes move {
0% {
background-position: 0 0;
Expand Down
18 changes: 18 additions & 0 deletions src-client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4"
integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==

"@types/marked@^5.0.1":
version "5.0.2"
resolved "https://registry.yarnpkg.com/@types/marked/-/marked-5.0.2.tgz#ca6b0cd7a5c8799c8cd0963df0b3e1a9021dcdfa"
integrity sha512-OucS4KMHhFzhz27KxmWg7J+kIYqyqoW5kdIEI319hqARQQUTqhao3M/F+uFnDXD0Rg72iDDZxZNxq5gvctmLlg==

"@types/pug@^2.0.6":
version "2.0.10"
resolved "https://registry.yarnpkg.com/@types/pug/-/pug-2.0.10.tgz#52f8dbd6113517aef901db20b4f3fca543b88c1f"
Expand Down Expand Up @@ -650,6 +655,11 @@ magic-string@^0.30.4, magic-string@^0.30.5:
dependencies:
"@jridgewell/sourcemap-codec" "^1.4.15"

marked@^5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/marked/-/marked-5.1.2.tgz#62b5ccfc75adf72ca3b64b2879b551d89e77677f"
integrity sha512-ahRPGXJpjMjwSOlBoTMZAK7ATXkli5qCPxZ21TG44rx1KEo44bii4ekgTDQPNRQ4Kh7JMb9Ub1PVk1NxRSsorg==

mdn-data@2.0.30:
version "2.0.30"
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-2.0.30.tgz#ce4df6f80af6cfbe218ecd5c552ba13c4dfa08cc"
Expand Down Expand Up @@ -915,6 +925,14 @@ svelte-hmr@^0.15.3:
resolved "https://registry.yarnpkg.com/svelte-hmr/-/svelte-hmr-0.15.3.tgz#df54ccde9be3f091bf5f18fc4ef7b8eb6405fbe6"
integrity sha512-41snaPswvSf8TJUhlkoJBekRrABDXDMdpNpT2tfHIv4JuhgvHqLMhEPGtaQn0BmbNSTkuz2Ed20DF2eHw0SmBQ==

svelte-markdown@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/svelte-markdown/-/svelte-markdown-0.4.1.tgz#ddf13cfd6e0f29a02a82854b48766b527ec90f8d"
integrity sha512-pOlLY6EruKJaWI9my/2bKX8PdTeP5CM0s4VMmwmC2prlOkjAf+AOmTM4wW/l19Y6WZ87YmP8+ZCJCCwBChWjYw==
dependencies:
"@types/marked" "^5.0.1"
marked "^5.1.2"

svelte-preprocess@^5.1.3:
version "5.1.3"
resolved "https://registry.yarnpkg.com/svelte-preprocess/-/svelte-preprocess-5.1.3.tgz#7682239fe53f724c845b53026816fdfe15d028f9"
Expand Down
4 changes: 3 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ reqwest = { version = "0.12", features = ["json", "stream"] }
octocrab = "0.37.0"
futures-util = "0.3.30"
zip = "0.6.6"
winreg = "0.52.0"
anyhow = "1.0"

[target.'cfg(windows)'.dependencies]
winreg = "0.52.0"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.
# If you use cargo directly instead of tauri's cli you can use this feature flag to switch between tauri's `dev` and `build` modes.
Expand Down
15 changes: 10 additions & 5 deletions src-tauri/src/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,23 @@ fn stop_voiceattack_process() -> Result<()> {
}

fn get_voiceattack_installation_directory() -> Result<PathBuf> {
let def = winreg::RegKey::predef(winreg::enums::HKEY_CURRENT_USER);
let key = def
#[cfg(target_os = "windows")]
{
let def = winreg::RegKey::predef(winreg::enums::HKEY_CURRENT_USER);
let key = def
.open_subkey(r"Software\VoiceAttack.com\VoiceAttack")
.context(
"Could not find VoiceAttack installation directory in the registry. Subkey does not exist",
)?;

let path = key
let path = key
.get_value::<String, _>("installpath")
.context( "Could not find VoiceAttack installation directory in the registry. Keyvalue 'installpath' does not exist")?;

Ok(std::path::PathBuf::from(path))
return Ok(std::path::PathBuf::from(path));
}

Err(anyhow::anyhow!("Unsupported OS"))
}

fn get_eliteva_installation_directory(
Expand All @@ -86,7 +91,7 @@ fn get_eliteva_installation_directory(
Ok(directory)
}

async fn query_latest_release(owner: &str, repo: &str) -> Result<Release> {
pub async fn query_latest_release(owner: &str, repo: &str) -> Result<Release> {
let release = octocrab::instance()
.repos(owner, repo)
.releases()
Expand Down
Loading

0 comments on commit 590f361

Please sign in to comment.