Skip to content

Commit

Permalink
Updater improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Nov 3, 2022
1 parent d2dd8eb commit 4501aba
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
4 changes: 2 additions & 2 deletions interface/components/updateAlert.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 13l-3 3m0 0l-3-3m3 3V8m0 13a9 9 0 110-18 9 9 0 010 18z" />
</svg>

<p class="updateText mx-1 text-lg font-bold">New Authme update available! Click install to download and install the update automatically.</p>
<p class="updateText mx-1 text-lg font-bold">New Authme update available! Click install to download and install the update.</p>

<button type="button" class="updateRestart smallButton" on:click={installUpdate}>
<button type="button" class="installUpdate smallButton" on:click={installUpdate}>
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" />
</svg>
Expand Down
13 changes: 13 additions & 0 deletions interface/utils/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,16 @@ export const migrationImageConverter = (data: string): string => {

return returnString
}

/**
* Convert markdown to text
*/
export const markdownConverter = (text: string) => {
const body = text
.replaceAll("###", "")
.replaceAll("*", " -")
.replaceAll(/(#[0-9])\w+/g, "")
.replaceAll("- ", "- ")

return body
}
27 changes: 17 additions & 10 deletions interface/utils/update.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { updater, dialog } from "@tauri-apps/api"
import { updater, dialog, os } from "@tauri-apps/api"
import { relaunch } from "@tauri-apps/api/process"
import { getState, setState } from "interface/stores/state"
import { dev } from "../../build.json"
import { markdownConverter } from "./convert"
import logger from "./logger"
import { open } from "./navigate"

const state = getState()
let releaseNotes: string

/**
* Check for auto update
Expand All @@ -15,9 +16,7 @@ export const checkForUpdate = async () => {
try {
const { shouldUpdate, manifest } = await updater.checkUpdate()
if (shouldUpdate) {
releaseNotes = manifest.body

logger.log(`Latest update: ${JSON.stringify(manifest)}`)
logger.log(`Latest update: ${JSON.stringify(manifest)} ${manifest.body}`)

state.updateAvailable = true
setState(state)
Expand All @@ -29,12 +28,20 @@ export const checkForUpdate = async () => {
}

export const installUpdate = async () => {
document.querySelector(".updateText").textContent = "Downloading update... Please wait!"
const system = await os.type()

if (system !== "Windows_NT") {
open("https://authme.levminer.com/#downloads")
} else {
document.querySelector(".updateText").textContent = "Downloading update... Please wait!"
document.querySelector(".installUpdate").style.display = "none"

await updater.installUpdate()
await relaunch()
await updater.installUpdate()
await relaunch()
}
}

export const showReleaseNotes = () => {
dialog.message(releaseNotes)
export const showReleaseNotes = async () => {
const res = await (await fetch("https://api.levminer.com/api/v1/authme/releases")).json()
dialog.message(markdownConverter(res.body.split("Other")[0]))
}

0 comments on commit 4501aba

Please sign in to comment.