-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
78 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import React from "react"; | ||
|
||
export const Indicator = React.createElement("img", { | ||
src: "https://cdn-icons-png.flaticon.com/32/3064/3064130.png", | ||
width: "20", | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { createWriteStream } from "fs"; | ||
import { get } from "https"; | ||
import { plugins } from "replugged"; | ||
import { CONFIG_PATHS } from "replugged/dist/util"; | ||
import { join } from "path"; | ||
|
||
const GITAPI_LINK = "https://api.github.com/repos/SammCheese/invisible-chat/releases/latest"; | ||
const FILENAME = "dev.sammcheese.InvisibleChat.asar"; | ||
|
||
async function fetchGithub(): Promise<JSON> { | ||
return new Promise((resolve, reject) => { | ||
fetch(GITAPI_LINK) | ||
.then((resp) => resolve(resp.json())) | ||
.catch((rej) => { | ||
console.log(rej); | ||
reject(rej); | ||
}); | ||
}); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type | ||
const downloadFile = (url: string, path: string) => { | ||
const file = createWriteStream(path); | ||
get(url, (res) => { | ||
res.pipe(file); | ||
|
||
file.on("finish", () => { | ||
file.close(); | ||
}); | ||
}); | ||
}; | ||
|
||
export async function checkUpdate(): Promise<void> { | ||
const gitResult = await fetchGithub(); | ||
// @ts-expect-error response type not declared | ||
const localVersion = await plugins.get("dev.sammcheese.InvisibleChat")?.manifest?.version; | ||
|
||
// @ts-expect-error type not declared | ||
if (isNewAvailable(localVersion, gitResult.tag_name)) { | ||
// @ts-expect-error type not declared | ||
downloadFile(gitResult.assets.browser_download_url, join(CONFIG_PATHS.plugins, FILENAME)); | ||
/*rename(join(CONFIG_PATHS.plugins, FILENAME), `${FILENAME}.update`, (e) => { | ||
// @ts-expect-error type not declared | ||
if (e) unlinkSync(file); | ||
});*/ | ||
} | ||
} | ||
|
||
function isNewAvailable(localVersion: string, remoteVersion: string): boolean { | ||
if (!localVersion || !remoteVersion) return false; | ||
|
||
localVersion.replaceAll(".", "").replace("v", ""); | ||
remoteVersion.replaceAll(".", "").replace("v", ""); | ||
|
||
return parseInt(remoteVersion, 10) > parseInt(localVersion, 10); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters