Skip to content

Commit

Permalink
Merge pull request #9 from beebls/dev
Browse files Browse the repository at this point in the history
merge ci
  • Loading branch information
beebls authored May 24, 2023
2 parents feb33e2 + b12273c commit 4c8299a
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 123 deletions.
22 changes: 8 additions & 14 deletions .github/workflows/beta-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,19 @@ jobs:
with:
node-version: 16

- name: Conventional Changelog Action
id: changelog
uses: ./.github/workflows/custom-changelog
with:
github-token: ${{ secrets.github_token }}
- name: Get Version
run: echo "PACKAGE_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV

- name: Create Release
id: create-release
uses: actions/github-script@v6
env:
RELEASE_TAG: ${{ steps.changelog.outputs.tag }}
RELEASE_LOG: ${{ steps.changelog.outputs.clean_changelog }}
with:
script: |
const { data } = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `${process.env.RELEASE_TAG}`,
name: `CSSLoader Desktop BETA ${process.env.RELEASE_TAG}`,
tag_name: `v${process.env.PACKAGE_VERSION}`,
name: `CSSLoader Desktop BETA v${process.env.PACKAGE_VERSION}`,
body: `${process.env.RELEASE_LOG}`,
draft: true,
prerelease: true
Expand All @@ -57,15 +51,15 @@ jobs:
strategy:
fail-fast: false
matrix:
platform: [ubuntu-20.04, windows-latest]
platform: [windows-latest]

runs-on: ${{ matrix.platform }}
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: release
ref: dev

- name: Setup Node
uses: actions/setup-node@v3
Expand Down Expand Up @@ -108,15 +102,15 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: release
ref: dev

- name: Update Release Assets
uses: actions/github-script@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release_id: ${{ needs.create-release.outputs.release_id }}
release_tag: ${{ needs.create-release.outputs.tag }}
git_branch: "release"
git_branch: "dev"
with:
script: |
const fs = require("fs");
Expand Down
60 changes: 0 additions & 60 deletions .github/workflows/nightly-release.yml

This file was deleted.

78 changes: 75 additions & 3 deletions backend.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { fetch, Body } from "@tauri-apps/api/http";
import { Theme } from "./ThemeTypes";
import { Command } from "@tauri-apps/api/shell";

import {
writeTextFile,
readTextFile,
BaseDirectory,
createDir,
exists,
} from "@tauri-apps/api/fs";
import { toast as reactToast } from "react-toastify";
import semver from "semver";

export interface Server {
callPluginMethod<TArgs = {}, TRes = {}>(
Expand All @@ -24,7 +31,6 @@ interface ServerResponseError {

const server: Server = {
async callPluginMethod(methodName: string, args: any): Promise<any> {
console.log("FETCHING", methodName);
return fetch("http://127.0.0.1:35821/req", {
method: "POST",
body: Body.json({
Expand Down Expand Up @@ -56,11 +62,77 @@ export async function startBackend(onClose: any = () => {}) {
await command.spawn();
}

export async function getStandaloneVersion() {
return await readTextFile("standaloneVersion.txt", {
dir: BaseDirectory.AppData,
});
}

export async function setStandaloneVersion(value: string) {
const appDataExists = await exists("", { dir: BaseDirectory.AppData });
if (!appDataExists) {
console.log("AppData dir does not exist! Creating.");
await createDir("", { dir: BaseDirectory.AppData });
}
writeTextFile("standaloneVersion.txt", value, { dir: BaseDirectory.AppData });
}

export async function fetchNewest() {
return await fetch<any>(
"https://api.github.com/repos/suchmememanyskill/SDH-CssLoader/releases/latest"
)
.then((res) => {
console.log(res);
return res.data;
})
.then((json) => {
if (json) {
return json;
}
return;
})
.catch((err) => {
console.error("Error Fetching Latest Backend From Github!", err);
return;
});
}

export async function checkForNewStandalone(): Promise<boolean | string> {
const current = await getStandaloneVersion();
const remote = await fetchNewest();
if (!remote) return false;
const remoteVersion = remote.tag_name;
console.log(current, remoteVersion);
// This returns true because if it's not valid, it means your current install borked
if (!semver.valid(current)) return remoteVersion;
if (!semver.valid(remoteVersion)) return false;
if (semver.gt(remoteVersion, current)) {
return remoteVersion;
}
return false;
}

export async function checkIfBackendExists() {
const backendExists = await exists(
"Microsoft\\Windows\\Start Menu\\Programs\\Startup\\CssLoader-Standalone-Headless.exe",
{
dir: BaseDirectory.Config,
}
);
return backendExists;
}

export async function downloadBackend(onClose: any = () => {}) {
const release = await fetchNewest();
const url = release.assets.find((e: any) =>
e.name.includes("Standalone-Headless.exe")
).url;
const version = semver.clean(release.tag) || "v1.6.0";
setStandaloneVersion(version);
const command = new Command("downloadBackend", [
"Invoke-WebRequest",
"-Uri",
"https://github.com/suchmememanyskill/SDH-CssLoader/releases/latest/download/CssLoader-Standalone-Headless.exe",
url,
"-OutFile",
"([Environment]::GetFolderPath('Startup')",
"+",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { ImSpinner5 } from "react-icons/im";
import { themeContext } from "../pages/_app";
import { downloadBackend, startBackend } from "../backend";

export function OnboardingPage() {
export function DownloadBackendPage({
onboarding = false,
}: {
onboarding?: boolean;
}) {
const { refreshThemes } = useContext(themeContext);
const [installProg, setInstallProg] = useState<number>(0);
const [installText, setInstallText] = useState<string>("");
Expand All @@ -22,11 +26,12 @@ export function OnboardingPage() {
});
});
}

return (
<>
<main className="flex flex-col w-full h-full items-center justify-center flex-grow gap-4">
<h1 className="fancy-font text-5xl font-semibold">
Welcome To CSSLoader
{onboarding ? "Welcome To CSSLoader" : "Backend Update Available"}
</h1>
<button
onClick={() => installProg <= 0 && installBackend()}
Expand All @@ -39,7 +44,7 @@ export function OnboardingPage() {
<span className="fancy-font text-2xl">{installText}</span>
</div>
) : (
<h2 className="fancy-font text-3xl">Install CSSLoader's Backend</h2>
<h2 className="fancy-font text-3xl">Install Backend</h2>
)}
</button>
</main>
Expand Down
2 changes: 1 addition & 1 deletion components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export * from "./ThemeToggle";
export * from "./ThemePatch";
export * from "./PatchComponent";
export * from "./Nav";
export * from "./OnboardingPage";
export * from "./DownloadBackendPage";
export * from "./BackendFailedPage";
18 changes: 18 additions & 0 deletions hooks/usePlatform.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Platform } from "@tauri-apps/api/os";
import { useEffect, useState } from "react";

export function usePlatform() {
const [platform, setPlatform] = useState<Platform>("linux");

useEffect(() => {
const getPlatform = async () => {
const { platform: tauriPlatform } = await import("@tauri-apps/api/os");
tauriPlatform().then((value) => {
console.log("platform: ", value);
setPlatform(value);
});
};
getPlatform();
}, []);
return platform;
}
11 changes: 11 additions & 0 deletions latest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.3.8",
"notes": "Check Github for the release notes!",
"pub_date": "2023-05-23T22:23:54.695Z",
"platforms": {
"windows-x86_64": {
"signature": "dW50cnVzdGVkIGNvbW1lbnQ6IHNpZ25hdHVyZSBmcm9tIHRhdXJpIHNlY3JldCBrZXkKUlVUR25UdTJ0dzN1MXVPQ09zK3JUQ09TUWFTV2dEOURrcWRVYW5BdVpCdjAycGljSCtncEpncVZhQW4vVTlybXVJeEtTT1Vxc2pLYUxqNXJjcVlYNnh0VVVOWnprYlJHSkE4PQp0cnVzdGVkIGNvbW1lbnQ6IHRpbWVzdGFtcDoxNjg0ODgwNjMyCWZpbGU6Q1NTTG9hZGVyIERlc2t0b3BfMC4zLjhfeDY0X2VuLVVTLm1zaS56aXAKUmJLNmJIMjg1SmI3VEdmS2FLQ0c4R0RBQUlsdU1vVDRQamhQaG1COEtpUDdqRlp3eFIrQlFvRlJkNU5sQW1TNUdSSm4zb1NaREdSRExEbnJFUVFBQmc9PQo=",
"url": "https://github.com/beebls/CSSLoader-Desktop/releases/latest/download/CSSLoader.Desktop_0.3.8_x64_en-US.msi.zip"
}
}
}
Loading

0 comments on commit 4c8299a

Please sign in to comment.