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

Commit

Permalink
Optional analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Sep 11, 2022
1 parent b09f958 commit 166e7bf
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
21 changes: 21 additions & 0 deletions interface/layout/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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"

const settings = getSettings()
const state = getState()
Expand Down Expand Up @@ -80,3 +82,22 @@ const launchOptions = async () => {

launchOptions()

// Optional analytics
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: {
Accept: "application/json",
"Content-Type": "application/json",
},
body: payload,
})
}
}

optionalAnalytics()
16 changes: 16 additions & 0 deletions interface/libraries/analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import build from "../../build.json"
import { os } from "@tauri-apps/api"

export const optionalAnalyticsPayload = async () => {
const osType = await os.type()
const osArch = await os.arch()
const osVersion = await os.version()

return {
version: build.version,
build: build.number,
os: `${osType} ${osArch.replace("x86_64", "x64")} ${osVersion}`,
lang: navigator.language.slice(0, 2),
date: new Date(),
}
}
2 changes: 1 addition & 1 deletion interface/stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const defaultSettings: LibSettings = {
},
}

const dev = build.dev === "true"
const dev = build.dev

if (dev === false && localStorage.settings === undefined) {
invoke("auto_launch")
Expand Down
8 changes: 5 additions & 3 deletions scripts/buildNumber.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { existsSync, mkdirSync, writeFileSync } = require("fs")
const package = require("../package.json")
const { version: appVersion } = require("../package.json")

const build = new Date().toISOString().replace("T", "X").replaceAll(":", ".").substring(0, 19).replaceAll("-", ".").slice(2).replaceAll(".", "").replace("X", ".")

Expand All @@ -12,12 +12,14 @@ const day = date.toISOString().substring(8, 10)
const buildNumber = `${process.argv[2]}.${build}`
const releaseDate = `${year}. ${month} ${day}.`

const mode = process.argv[3] === "true"

const file = {
number: buildNumber,
date: releaseDate,
version: package.version,
version: appVersion,
arch: process.arch,
dev: process.argv[3],
dev: mode,
}

if (!existsSync("core/target/release")) {
Expand Down

0 comments on commit 166e7bf

Please sign in to comment.