Skip to content

Commit 4c8299a

Browse files
authored
Merge pull request #9 from beebls/dev
merge ci
2 parents feb33e2 + b12273c commit 4c8299a

File tree

13 files changed

+234
-123
lines changed

13 files changed

+234
-123
lines changed

.github/workflows/beta-release.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,19 @@ jobs:
2525
with:
2626
node-version: 16
2727

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

3431
- name: Create Release
3532
id: create-release
3633
uses: actions/github-script@v6
37-
env:
38-
RELEASE_TAG: ${{ steps.changelog.outputs.tag }}
39-
RELEASE_LOG: ${{ steps.changelog.outputs.clean_changelog }}
4034
with:
4135
script: |
4236
const { data } = await github.rest.repos.createRelease({
4337
owner: context.repo.owner,
4438
repo: context.repo.repo,
45-
tag_name: `${process.env.RELEASE_TAG}`,
46-
name: `CSSLoader Desktop BETA ${process.env.RELEASE_TAG}`,
39+
tag_name: `v${process.env.PACKAGE_VERSION}`,
40+
name: `CSSLoader Desktop BETA v${process.env.PACKAGE_VERSION}`,
4741
body: `${process.env.RELEASE_LOG}`,
4842
draft: true,
4943
prerelease: true
@@ -57,15 +51,15 @@ jobs:
5751
strategy:
5852
fail-fast: false
5953
matrix:
60-
platform: [ubuntu-20.04, windows-latest]
54+
platform: [windows-latest]
6155

6256
runs-on: ${{ matrix.platform }}
6357
steps:
6458
- name: Checkout Repository
6559
uses: actions/checkout@v3
6660
with:
6761
fetch-depth: 0
68-
ref: release
62+
ref: dev
6963

7064
- name: Setup Node
7165
uses: actions/setup-node@v3
@@ -108,15 +102,15 @@ jobs:
108102
uses: actions/checkout@v3
109103
with:
110104
fetch-depth: 0
111-
ref: release
105+
ref: dev
112106

113107
- name: Update Release Assets
114108
uses: actions/github-script@v6
115109
env:
116110
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
117111
release_id: ${{ needs.create-release.outputs.release_id }}
118112
release_tag: ${{ needs.create-release.outputs.tag }}
119-
git_branch: "release"
113+
git_branch: "dev"
120114
with:
121115
script: |
122116
const fs = require("fs");

.github/workflows/nightly-release.yml

Lines changed: 0 additions & 60 deletions
This file was deleted.

backend.ts

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import { fetch, Body } from "@tauri-apps/api/http";
22
import { Theme } from "./ThemeTypes";
33
import { Command } from "@tauri-apps/api/shell";
4-
4+
import {
5+
writeTextFile,
6+
readTextFile,
7+
BaseDirectory,
8+
createDir,
9+
exists,
10+
} from "@tauri-apps/api/fs";
511
import { toast as reactToast } from "react-toastify";
12+
import semver from "semver";
613

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

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

65+
export async function getStandaloneVersion() {
66+
return await readTextFile("standaloneVersion.txt", {
67+
dir: BaseDirectory.AppData,
68+
});
69+
}
70+
71+
export async function setStandaloneVersion(value: string) {
72+
const appDataExists = await exists("", { dir: BaseDirectory.AppData });
73+
if (!appDataExists) {
74+
console.log("AppData dir does not exist! Creating.");
75+
await createDir("", { dir: BaseDirectory.AppData });
76+
}
77+
writeTextFile("standaloneVersion.txt", value, { dir: BaseDirectory.AppData });
78+
}
79+
80+
export async function fetchNewest() {
81+
return await fetch<any>(
82+
"https://api.github.com/repos/suchmememanyskill/SDH-CssLoader/releases/latest"
83+
)
84+
.then((res) => {
85+
console.log(res);
86+
return res.data;
87+
})
88+
.then((json) => {
89+
if (json) {
90+
return json;
91+
}
92+
return;
93+
})
94+
.catch((err) => {
95+
console.error("Error Fetching Latest Backend From Github!", err);
96+
return;
97+
});
98+
}
99+
100+
export async function checkForNewStandalone(): Promise<boolean | string> {
101+
const current = await getStandaloneVersion();
102+
const remote = await fetchNewest();
103+
if (!remote) return false;
104+
const remoteVersion = remote.tag_name;
105+
console.log(current, remoteVersion);
106+
// This returns true because if it's not valid, it means your current install borked
107+
if (!semver.valid(current)) return remoteVersion;
108+
if (!semver.valid(remoteVersion)) return false;
109+
if (semver.gt(remoteVersion, current)) {
110+
return remoteVersion;
111+
}
112+
return false;
113+
}
114+
115+
export async function checkIfBackendExists() {
116+
const backendExists = await exists(
117+
"Microsoft\\Windows\\Start Menu\\Programs\\Startup\\CssLoader-Standalone-Headless.exe",
118+
{
119+
dir: BaseDirectory.Config,
120+
}
121+
);
122+
return backendExists;
123+
}
124+
59125
export async function downloadBackend(onClose: any = () => {}) {
126+
const release = await fetchNewest();
127+
const url = release.assets.find((e: any) =>
128+
e.name.includes("Standalone-Headless.exe")
129+
).url;
130+
const version = semver.clean(release.tag) || "v1.6.0";
131+
setStandaloneVersion(version);
60132
const command = new Command("downloadBackend", [
61133
"Invoke-WebRequest",
62134
"-Uri",
63-
"https://github.com/suchmememanyskill/SDH-CssLoader/releases/latest/download/CssLoader-Standalone-Headless.exe",
135+
url,
64136
"-OutFile",
65137
"([Environment]::GetFolderPath('Startup')",
66138
"+",
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { ImSpinner5 } from "react-icons/im";
33
import { themeContext } from "../pages/_app";
44
import { downloadBackend, startBackend } from "../backend";
55

6-
export function OnboardingPage() {
6+
export function DownloadBackendPage({
7+
onboarding = false,
8+
}: {
9+
onboarding?: boolean;
10+
}) {
711
const { refreshThemes } = useContext(themeContext);
812
const [installProg, setInstallProg] = useState<number>(0);
913
const [installText, setInstallText] = useState<string>("");
@@ -22,11 +26,12 @@ export function OnboardingPage() {
2226
});
2327
});
2428
}
29+
2530
return (
2631
<>
2732
<main className="flex flex-col w-full h-full items-center justify-center flex-grow gap-4">
2833
<h1 className="fancy-font text-5xl font-semibold">
29-
Welcome To CSSLoader
34+
{onboarding ? "Welcome To CSSLoader" : "Backend Update Available"}
3035
</h1>
3136
<button
3237
onClick={() => installProg <= 0 && installBackend()}
@@ -39,7 +44,7 @@ export function OnboardingPage() {
3944
<span className="fancy-font text-2xl">{installText}</span>
4045
</div>
4146
) : (
42-
<h2 className="fancy-font text-3xl">Install CSSLoader's Backend</h2>
47+
<h2 className="fancy-font text-3xl">Install Backend</h2>
4348
)}
4449
</button>
4550
</main>

components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ export * from "./ThemeToggle";
22
export * from "./ThemePatch";
33
export * from "./PatchComponent";
44
export * from "./Nav";
5-
export * from "./OnboardingPage";
5+
export * from "./DownloadBackendPage";
66
export * from "./BackendFailedPage";

hooks/usePlatform.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Platform } from "@tauri-apps/api/os";
2+
import { useEffect, useState } from "react";
3+
4+
export function usePlatform() {
5+
const [platform, setPlatform] = useState<Platform>("linux");
6+
7+
useEffect(() => {
8+
const getPlatform = async () => {
9+
const { platform: tauriPlatform } = await import("@tauri-apps/api/os");
10+
tauriPlatform().then((value) => {
11+
console.log("platform: ", value);
12+
setPlatform(value);
13+
});
14+
};
15+
getPlatform();
16+
}, []);
17+
return platform;
18+
}

latest.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": "0.3.8",
3+
"notes": "Check Github for the release notes!",
4+
"pub_date": "2023-05-23T22:23:54.695Z",
5+
"platforms": {
6+
"windows-x86_64": {
7+
"signature": "dW50cnVzdGVkIGNvbW1lbnQ6IHNpZ25hdHVyZSBmcm9tIHRhdXJpIHNlY3JldCBrZXkKUlVUR25UdTJ0dzN1MXVPQ09zK3JUQ09TUWFTV2dEOURrcWRVYW5BdVpCdjAycGljSCtncEpncVZhQW4vVTlybXVJeEtTT1Vxc2pLYUxqNXJjcVlYNnh0VVVOWnprYlJHSkE4PQp0cnVzdGVkIGNvbW1lbnQ6IHRpbWVzdGFtcDoxNjg0ODgwNjMyCWZpbGU6Q1NTTG9hZGVyIERlc2t0b3BfMC4zLjhfeDY0X2VuLVVTLm1zaS56aXAKUmJLNmJIMjg1SmI3VEdmS2FLQ0c4R0RBQUlsdU1vVDRQamhQaG1COEtpUDdqRlp3eFIrQlFvRlJkNU5sQW1TNUdSSm4zb1NaREdSRExEbnJFUVFBQmc9PQo=",
8+
"url": "https://github.com/beebls/CSSLoader-Desktop/releases/latest/download/CSSLoader.Desktop_0.3.8_x64_en-US.msi.zip"
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)