Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Auto update
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Sep 14, 2022
1 parent 166e7bf commit bad2966
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 14 deletions.
21 changes: 21 additions & 0 deletions core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tauri-build = { version = "1.0.4", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.5", features = ["api-all", "system-tray"] }
tauri = { version = "1.0.5", features = ["api-all", "system-tray", "updater"] }
window-vibrancy = "0.1.3"
auto-launch = "0.3.0"
sysinfo = "0.25.3"
Expand Down
5 changes: 4 additions & 1 deletion core/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@
"csp": "default-src blob: data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'"
},
"updater": {
"active": false
"active": true,
"endpoints": ["https://gist.github.com/Levminer/5a11ff3014b63bf4760ec378fe3c9441/raw/b25f2adde007f7ae4ea5986f43649941c92c5885/update.json"],
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDU1MzQyQUNFQTRDNkYwMjMKUldRajhNYWt6aW8wVlJWOUFvanRGSGhoUGZMeFJFS2VkYUNvVkFBMXRBUGN3T2p1aHlsSEtQUTkK",
"dialog": false
},
"windows": [
{
Expand Down
16 changes: 9 additions & 7 deletions interface/components/updateAlert.svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<div class="updateAlert w-full bg-popup-blue">
<div class="updateAlert z-10 w-full bg-popup-blue">
<div class="container mx-auto flex items-center justify-between px-6 py-4">
<div class="flex items-center justify-center gap-3">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<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 version available. Starting the update...</p>
<p class="updateText mx-1 text-lg font-bold">New Authme update available! Click install to download and install the update automatically.</p>

<button type="button" class="updateRestart smallButton">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
<button type="button" class="updateRestart 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>
<span data-loc>Restart</span>
<span data-loc>Install</span>
</button>

<button type="button" class="smallButton">
<button type="button" class="smallButton" on:click={showReleaseNotes}>
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2 13a2 2 0 002-2V9a2 2 0 00-2-2h-2m-4-3H9M7 16h6M7 8h6v4H7V8z" />
</svg>
Expand All @@ -31,6 +31,8 @@
</div>

<script>
import { installUpdate, showReleaseNotes } from "interface/libraries/update"
const hidePopup = () => {
document.querySelector(".updateAlert").style.display = "none"
}
Expand Down
7 changes: 6 additions & 1 deletion interface/layout/app.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

<div class="w-full overflow-hidden overflow-y-scroll">
<BuildNumber />

{#if $state.updateAvailable}
<UpdateAlert />
{/if}

<div class="top" />

<RouteTransition>
Expand All @@ -27,7 +32,7 @@
import { onMount } from "svelte"
import { state } from "../stores/state"
// import UpdateAlert from "../components/updateAlert.svelte"
import UpdateAlert from "../components/updateAlert.svelte"
import BuildNumber from "../components/buildNumber.svelte"
import RouteTransition from "../components/routeTransition.svelte"
Expand Down
6 changes: 2 additions & 4 deletions interface/layout/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import "../styles/index.css"
import { os, event, window, invoke } from "@tauri-apps/api"
import { getSettings } from "../stores/settings"
import { navigate } from "../libraries/navigate"
import { checkUpdate, installUpdate } from "@tauri-apps/api/updater"
import { relaunch } from "@tauri-apps/api/process"
import { getState } from "interface/stores/state"
import { dev } from "../../build.json"
import { optionalAnalyticsPayload } from "interface/libraries/analytics"
import { checkForUpdate } from "interface/libraries/update"

const settings = getSettings()
const state = getState()
Expand Down Expand Up @@ -87,8 +86,6 @@ const optionalAnalytics = async () => {
if (settings.settings.optionalAnalytics === true && dev === false) {
const payload = JSON.stringify(await optionalAnalyticsPayload())

console.log(payload)

fetch("https://analytics.levminer.com/api/v1/authme/analytics/post", {
method: "POST",
headers: {
Expand All @@ -101,3 +98,4 @@ const optionalAnalytics = async () => {
}

optionalAnalytics()
checkForUpdate()
1 change: 1 addition & 0 deletions interface/libraries/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ declare global {
interface LibState {
authenticated: boolean
importData: null | string
updateAvailable: boolean
}

interface LibSearchQuery {
Expand Down
42 changes: 42 additions & 0 deletions interface/libraries/update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { updater, event, dialog } from "@tauri-apps/api"
import { relaunch } from "@tauri-apps/api/process"
import { getState, setState } from "interface/stores/state"
import { dev } from "../../build.json"

const state = getState()
let releaseNotes: string

/**
* Check for auto update
*/
export const checkForUpdate = async () => {
if (dev === false) {
try {
const { shouldUpdate, manifest } = await updater.checkUpdate()
if (shouldUpdate) {
releaseNotes = manifest.body

console.log(manifest)

state.updateAvailable = true

setState(state)
}
} catch (error) {
console.log(error)
}
}
}

export const installUpdate = async () => {
await updater.installUpdate()
await relaunch()
}

export const showReleaseNotes = () => {
dialog.message(releaseNotes)
}

event.listen("tauri://update-status", (res) => {
console.log("New status: ", res)
})
1 change: 1 addition & 0 deletions interface/stores/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { writable, get } from "svelte/store"
const defaultState: LibState = {
authenticated: false,
importData: null,
updateAvailable: false,
}

export const state = writable<LibState>(sessionStorage.state ? JSON.parse(sessionStorage.state) : defaultState)
Expand Down

0 comments on commit bad2966

Please sign in to comment.