[feat] added auto update option on advance settings for windows (#773)

* [feat] added auto update option on advance settings for windows

* minor fixes + translations

* [feat] added popover for manual bsm update

* [feat] added logic on update and restart

* [feat] fixed sonar issues and added missing translations

* Fix availve update and current app version were the same

* Add a "See changelog"

* Set autoupdate always enabled by default

---------

Co-authored-by: Zagrios <40181755+Zagrios@users.noreply.github.com>
This commit is contained in:
silentrald
2025-06-13 00:58:41 +08:00
committed by GitHub
parent 9d945cdcfb
commit feb6ea3f87
21 changed files with 315 additions and 45 deletions
@@ -12,36 +12,47 @@ import { useService } from "renderer/hooks/use-service.hook";
import { lastValueFrom } from "rxjs";
import { useWindowControls } from "renderer/hooks/use-window-controls.hook";
import { useTranslationV2 } from "renderer/hooks/use-translation.hook";
import Tippy from "@tippyjs/react";
import { StaticConfigurationService } from "renderer/services/static-configuration.service";
import { AutoUpdate } from "shared/models/config";
import { UpdateInfo } from "electron-updater";
function TitleBarTags() {
function useVersion() {
const ipcService = useService(IpcService);
const t = useTranslationV2();
const [previewVersion, setPreviewVersion] = useState("");
const [outdated, setOutdated] = useState(false);
const [currentVersion, setCurrentVersion] = useState("");
const [latestVersion, setLatestVersion] = useState<UpdateInfo | null>(null);
useEffect(() => {
const requests: Promise<any>[] = [
lastValueFrom(ipcService.sendV2("current-version"))
];
if (window.electron.platform === "linux") {
requests.push(lastValueFrom(ipcService.sendV2("check-update")));
}
Promise.all(requests).then(([ currentVersion, outdated ]) => {
handlePrerelease(currentVersion);
setOutdated(outdated);
Promise.all([
lastValueFrom(ipcService.sendV2("current-version")),
lastValueFrom(ipcService.sendV2("get-available-update"))
]).then(([ currentVersion, latestVersion ]) => {
setCurrentVersion(currentVersion);
setLatestVersion(latestVersion);
});
}, []);
const handlePrerelease = (version: string) => {
return { currentVersion, latestVersion };
}
function TitleBarTags({ version, latestVersion }: Readonly<{
version: string;
latestVersion: UpdateInfo | null;
}>) {
const t = useTranslationV2();
const previewVersion = (() => {
if (version.toLowerCase().includes("alpha")) {
return setPreviewVersion("ALPHA");
return "ALPHA";
}
if (version.toLowerCase().includes("beta")) {
return setPreviewVersion("BETA");
return "BETA";
}
}
return "";
})();
return <>
{previewVersion &&
@@ -49,7 +60,7 @@ function TitleBarTags() {
{previewVersion}
</span>
}
{outdated &&
{latestVersion &&
<span className="bg-warning-500 text-black rounded-full ml-1 text-[10px] italic px-1 uppercase h-3.5 font-bold">
{t.text("title-bar.outdated")}
</span>
@@ -57,12 +68,65 @@ function TitleBarTags() {
</>;
}
function AutoUpdateButton({ latestVersion }: Readonly<{
latestVersion: UpdateInfo | null;
}>) {
const configService = useService(StaticConfigurationService);
const ipcService = useService(IpcService);
const { text: t } = useTranslationV2();
const isLinux = window.electron.platform === "linux";
const updateAndRestart = async () => {
await configService.set("auto-update", AutoUpdate.ONCE);
await lastValueFrom(ipcService.sendV2("restart-app"));
};
const renderTippyContent = () => {
return (
<div className="p-2">
<div>{t("title-bar.update-text", { version: latestVersion.version })}</div>
{latestVersion?.version ? (
<a href={`https://github.com/Zagrios/bs-manager/releases/tag/v${latestVersion.version}`} target="_blank" className="cursor-pointer underline text-sm hover:text-gray-300">{t("title-bar.see-changelog")}</a>
) : null}
{!isLinux &&
<BsmButton typeColor="primary"
className="text-center rounded-md px-2 py-1 mt-2"
text={t("title-bar.update-button")}
withBar={false}
onClick={() => updateAndRestart()}
/>
}
</div>
)
}
return latestVersion && (
<Tippy
zIndex={1000}
placement="bottom"
content={renderTippyContent()}
theme="default"
hideOnClick
interactive
>
<BsmButton
className="shrink-0 w-11 h-full aspect-square !bg-transparent flex items-start p-0.5"
icon="download"
withBar={false}
/>
</Tippy>
);
}
export default function TitleBar({ template = "index.html" }: { template: AppWindow }) {
const audio = useService(AudioPlayerService);
const windowControls = useWindowControls();
const volume = useObservable(() => audio.volume$, audio.volume);
const color = useThemeColor("first-color");
const { currentVersion, latestVersion } = useVersion();
const [maximized, setMaximized] = useState(false);
@@ -107,7 +171,7 @@ export default function TitleBar({ template = "index.html" }: { template: AppWin
<div id="drag-region" className="grow basis-0 h-full">
<div id="window-title" className="pl-1">
<span className="text-gray-800 dark:text-gray-100 font-bold text-xs italic">BSManager</span>
<TitleBarTags />
<TitleBarTags version={currentVersion} latestVersion={latestVersion} />
</div>
</div>
<div id="window-controls" className="h-full flex shrink-0 items-center">
@@ -117,6 +181,7 @@ export default function TitleBar({ template = "index.html" }: { template: AppWin
</div>
<BsmButton className="shrink-0 h-[23px] w-[23px] aspect-square !bg-transparent flex items-start" iconClassName={volumeIcon === "volume-down" ? "-translate-x-[1.8px]" : null} icon={volumeIcon} withBar={false} onClick={() => audio.toggleMute()} />
</div>
<AutoUpdateButton latestVersion={latestVersion} />
<button onClick={minimizeWindow} className="text-gray-800 dark:text-gray-200 hover:bg-gray-300 dark:hover:bg-[#4F545C] cursor-pointer w-11 h-full shrink-0 flex justify-center items-center" id="min-button">
<svg aria-hidden="false" width="12" height="12" viewBox="0 0 12 12">
<rect fill="currentColor" width="10" height="1" x="1" y="6" />
+42 -4
View File
@@ -48,6 +48,7 @@ import { InstallationLocationService } from "renderer/services/installation-loca
import { AutoUpdaterService } from "renderer/services/auto-updater.service";
import { OculusDownloaderService } from "renderer/services/bs-version-download/oculus-downloader.service";
import { DISCORD_URL } from "shared/constants";
import { AutoUpdate } from "shared/models/config";
export function SettingsPage() {
@@ -546,11 +547,17 @@ function AdvancedSettings() {
const [hardwareAccelerationEnabled, setHardwareAccelerationEnabled] = useState(true);
const [useSymlink, setUseSymlink] = useState(false);
const [useSystemProxy, setUseSystemProxy] = useState(false);
const [autoUpdate, setAutoUpdate] = useState<AutoUpdate>(AutoUpdate.NEVER);
useEffect(() => {
staticConfig.get("disable-hadware-acceleration").then(disabled =>setHardwareAccelerationEnabled(() => disabled !== true));
staticConfig.get("use-symlinks").then(useSymlinks => setUseSymlink(() => useSymlinks));
staticConfig.get("use-system-proxy").then(useSystemProxy => setUseSystemProxy(() => useSystemProxy));
if (window.electron.platform === "win32") {
staticConfig.get("use-symlinks").then(useSymlinks => setUseSymlink(() => useSymlinks));
staticConfig.get("use-system-proxy").then(useSystemProxy => setUseSystemProxy(() => useSystemProxy));
staticConfig.get("auto-update").then(res => setAutoUpdate(() => res ?? AutoUpdate.ALWAYS));
}
}, []);
const onChangeHardwareAcceleration = async (newHardwareAccelerationEnabled: boolean) => {
@@ -631,12 +638,43 @@ function AdvancedSettings() {
setUseSystemProxy(() => newUseSystemProxy);
}
const advancedItems: Item[] = [{
const onChangeAutoUpdate = async (value: boolean) => {
if (window.electron.platform !== "win32") {
return;
}
const newAutoUpdate = value ? AutoUpdate.ALWAYS : AutoUpdate.NEVER;
const { error } = await tryit(() => staticConfig.set("auto-update", newAutoUpdate));
if (error) {
notification.notifyError({
title: "notifications.types.error",
desc: "pages.settings.advanced.auto-update.error-notification.message",
});
return;
}
setAutoUpdate(() => newAutoUpdate);
}
const advancedItems: Item[] = [];
if (window.electron.platform === "win32") {
advancedItems.push({
checked: autoUpdate === AutoUpdate.ALWAYS,
text: t.text("pages.settings.advanced.auto-update.title"),
desc: t.text("pages.settings.advanced.auto-update.description"),
onChange: onChangeAutoUpdate
});
}
advancedItems.push({
checked: hardwareAccelerationEnabled,
text: t.text("pages.settings.advanced.hardware-acceleration.title"),
desc: t.text("pages.settings.advanced.hardware-acceleration.description"),
onChange: onChangeHardwareAcceleration
}];
});
if (window.electron.platform === "win32") {
advancedItems.push({
checked: useSymlink,