notifications fully translated

This commit is contained in:
MathieuG-P
2022-07-14 18:37:40 +02:00
parent ded026e9bd
commit 3f9b79bf36
13 changed files with 447 additions and 71 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ ipcMain.on('bs-download.set-installation-folder', (event, request: IpcRequest<st
UtilsService.getInstance().newIpcSenc(request.responceChannel, {success: true, data: res});
}).catch(err => {
console.log(err);
UtilsService.getInstance().newIpcSenc(request.responceChannel, {success: false, error: err});
UtilsService.getInstance().newIpcSenc(request.responceChannel, {success: false, error: {title: err, type: 'error'}});
});
})
+4 -4
View File
@@ -25,13 +25,13 @@ export default function App() {
else { document.documentElement.classList.remove('dark'); }
});
bsDownloadService.downloadWarning$.pipe(filter(v => !!v), distinctUntilChanged(), debounceTime(100)).subscribe(() => {
notificationService.notifyWarning({title: "Warning", desc: "Your connection seems unstable"});
bsDownloadService.downloadWarning$.pipe(filter(v => !!v), distinctUntilChanged(), debounceTime(100)).subscribe((warning) => {
notificationService.notifyWarning({title: "notifications.types.warning", desc: `notifications.bs-download.warnings.msg.${warning}`});
});
bsDownloadService.downloadError$.pipe(filter(v => !!v), distinctUntilChanged(), debounceTime(100)).subscribe(err => {
notificationService.notifyError({title: "Error", desc: err});
})
notificationService.notifyError({title: "notifications.types.error", desc: `notifications.bs-download.errors.msg.${err}`});
});
}, [])
@@ -8,6 +8,7 @@ import defaultImage from '../../../../assets/images/default-version-img.jpg'
import dateFormat from "dateformat";
import { BsmImage } from "../shared/bsm-image.component";
import { IpcService } from "renderer/services/ipc.service";
import { useTranslation } from "renderer/hooks/use-translation.hook";
export const AvailableVersionItem = memo(function AvailableVersionItem(props: {version: BSVersion}) {
@@ -15,6 +16,7 @@ export const AvailableVersionItem = memo(function AvailableVersionItem(props: {v
const ipcService = IpcService.getInstance();
const [selected, setSelected] = useState(false);
const t = useTranslation();
const formatedDate = (() => { return dateFormat(+props.version.ReleaseDate*1000, "ddd. dS mmm yyyy"); })()
@@ -50,7 +52,7 @@ export const AvailableVersionItem = memo(function AvailableVersionItem(props: {v
{ props.version.ReleaseURL && (
<a onClickCapture={e => { e.stopPropagation(); openReleasePage(); }} className="relative flex flex-row justify-between items-center rounded-full bg-black bg-opacity-30 text-white pb-[1px] hover:bg-opacity-50">
<SteamIcon className="w-[25px] h-[25px] transition-transform group-hover:rotate-[-360deg] duration-300"/>
<span className="relative -left-[2px] text-sm w-0 text-center overflow-hidden h-full whitespace-nowrap pb-[3px] transition-all group-hover:w-24 duration-300">Release Page</span>
<span className="relative -left-[2px] text-sm w-fit max-w-0 text-center overflow-hidden h-full whitespace-nowrap pb-[3px] transition-all group-hover:max-w-[200px] group-hover:px-1 duration-300">{t("pages.available-versions.steam-release")}</span>
</a>
)}
</div>
@@ -6,41 +6,44 @@ import BeatConflictImg from "../../../../assets/images/apngs/beat-conflict.png";
import BeatWaitingImg from "../../../../assets/images/apngs/beat-waiting.png";
import BeatImpatientImg from "../../../../assets/images/apngs/beat-impatient.png";
import { BsmButton } from "../shared/bsm-button.component";
import { useTranslation } from "renderer/hooks/use-translation.hook";
export function NotificationItem({resolver, notification}: {resolver?: (value: NotificationResult|string) => void, notification: Notification}) {
const renderImage = () => {
if(notification.type === NotificationType.SUCCESS){ return BeatRunningImg; }
if(notification.type === NotificationType.WARNING){ return BeatWaitingImg; }
if(notification.type === NotificationType.ERROR){ return BeatConflictImg; }
return BeatImpatientImg;
}
const t = useTranslation();
const renderNeonColors = () => {
if(notification.type === NotificationType.SUCCESS){ return "bg-green-400 shadow-green-400"; }
if(notification.type === NotificationType.WARNING){ return "bg-yellow-400 shadow-yellow-400"; }
if(notification.type === NotificationType.ERROR){ return "bg-red-500 shadow-red-500"; }
return "bg-gray-800 shadow-gray-800 dark:bg-white dark:shadow-white";
}
const renderImage = () => {
if(notification.type === NotificationType.SUCCESS){ return BeatRunningImg; }
if(notification.type === NotificationType.WARNING){ return BeatWaitingImg; }
if(notification.type === NotificationType.ERROR){ return BeatConflictImg; }
return BeatImpatientImg;
}
const renderNeonColors = () => {
if(notification.type === NotificationType.SUCCESS){ return "bg-green-400 shadow-green-400"; }
if(notification.type === NotificationType.WARNING){ return "bg-yellow-400 shadow-yellow-400"; }
if(notification.type === NotificationType.ERROR){ return "bg-red-500 shadow-red-500"; }
return "bg-gray-800 shadow-gray-800 dark:bg-white dark:shadow-white";
}
return (
<motion.div layout initial={{x: "110%"}} animate={{x: "0%"}} exit={{x:"110%"}} className="relative w-[270px] rounded-md overflow-hidden -left-[285px] mb-4 shadow-md shadow-black bg-gradient-to-br from-light-main-color-2 to-light-main-color-2 dark:from-main-color-2 dark:to-main-color-2 text-gray-800 dark:text-white">
<div className="w-full flex flex-col">
<div className="flex items-center justify-start pl-1">
<BsmImage className="h-14 mr-1" image={renderImage()}/>
<div className="flex flex-col py-2">
<h1 className="font-bold leading-4 tracking-wide pr-5 my-1">{notification.title}</h1>
{notification.desc && <p className="text-xs">{notification.desc}</p>}
</div>
<motion.div layout initial={{x: "110%"}} animate={{x: "0%"}} exit={{x:"110%"}} className="relative w-[270px] rounded-md overflow-hidden -left-[285px] mb-4 shadow-md shadow-black bg-gradient-to-br from-light-main-color-2 to-light-main-color-2 dark:from-main-color-2 dark:to-main-color-2 text-gray-800 dark:text-white">
<div className="w-full flex flex-col">
<div className="flex items-center justify-start pl-1">
<BsmImage className="h-14 mr-1" image={renderImage()}/>
<div className="flex flex-col py-2">
<h1 className="font-bold leading-4 tracking-wide pr-5 my-1">{t(notification.title)}</h1>
{notification.desc && <p className="text-xs">{t(notification.desc)}</p>}
</div>
{notification.actions && (
<div className="flex pb-1 w-full flex-wrap px-[2px]">
{notification.actions.map(a => <span onClick={() => resolver(a.id)} className={`px-1 cursor-pointer flex-1 grow rounded-md text-center bg-blue-500 hover:brightness-110 transition-all text-gray-200 whitespace-nowrap m-[3px] ${a.cancel && "!bg-gray-500"}`}>{a.title}</span>)}
</div>
)}
</div>
<span className={`absolute w-full h-1 shadow-center left-0 top-0 ${renderNeonColors()}`}/>
<BsmButton icon="cross" className="absolute top-2 right-2" withBar={false} onClick={() => resolver(NotificationResult.CLOSE)}/>
</motion.div>
</div>
{notification.actions && (
<div className="flex pb-1 w-full flex-wrap px-[2px]">
{notification.actions.map(a => <span onClick={() => resolver(a.id)} className={`px-1 cursor-pointer flex-1 grow rounded-md text-center bg-blue-500 hover:brightness-110 transition-all text-gray-200 whitespace-nowrap m-[3px] ${a.cancel && "!bg-gray-500"}`}>{t(a.title)}</span>)}
</div>
)}
</div>
<span className={`absolute w-full h-1 shadow-center left-0 top-0 ${renderNeonColors()}`}/>
<BsmButton icon="cross" className="absolute top-2 right-2" withBar={false} onClick={() => resolver(NotificationResult.CLOSE)}/>
</motion.div>
)
}
@@ -5,6 +5,7 @@ export function useTranslation(): (translationKey: string) => string{
const i18nService = I18nService.getInstance();
return (key: string) => {
if(!key){ return ""; }
const tranlatables = key.split(" ");
return tranlatables.map((key) => i18nService.translate(key)).join(" ");
}
@@ -38,7 +38,7 @@ export function AvailableVersionsList() {
progressBarService.hide(true);
if(res.success){
notificationService.notifySuccess({title: 'Download Complete', duration: 3000});
notificationService.notifySuccess({title: "notifications.bs-download.success.titles.download-success", duration: 3000});
}
});
}
+22 -19
View File
@@ -75,31 +75,34 @@ export function SettingsPage() {
}
const setDefaultInstallationFolder = () => {
modalService.openModal(ModalType.INSTALLATION_FOLDER).then(async res => {
if(res.exitCode !== ModalExitCode.COMPLETED){ return; }
const fileChooserRes = await ipcService.send<{canceled: boolean, filePaths: string[]}>("choose-folder");
modalService.openModal(ModalType.INSTALLATION_FOLDER).then(async res => {
if(res.exitCode !== ModalExitCode.COMPLETED){ return; }
const fileChooserRes = await ipcService.send<{canceled: boolean, filePaths: string[]}>("choose-folder");
if(fileChooserRes.success && !fileChooserRes.data.canceled && fileChooserRes.data.filePaths?.length){
progressBarService.showFake(.008);
downloaderService.setInstallationFolder(fileChooserRes.data.filePaths[0]).then(res => {
setTimeout(() => {
progressBarService.complete();
setTimeout(() => progressBarService.hide(true), 1000);
}, 1000);
if(res.success){
setInstallationFolder(res.data);
notificationService.notifySuccess({title: "Transfer completed", duration: 3000});
}
});
}
if(fileChooserRes.success && !fileChooserRes.data.canceled && fileChooserRes.data.filePaths?.length){
progressBarService.showFake(.008);
downloaderService.setInstallationFolder(fileChooserRes.data.filePaths[0]).then(res => {
setTimeout(() => {
progressBarService.complete();
setTimeout(() => progressBarService.hide(true), 1000);
}, 1000);
if(res.success){
setInstallationFolder(res.data);
notificationService.notifySuccess({title: "notifications.settings.move-folder.success.titles.transfer-finished", duration: 3000});
}
else{
notificationService.notifyError({title: "notifications.settings.move-folder.errors.titles.transfer-failed", desc: res?.error?.title});
}
});
}
})
}
});
}
const deleteSteamSession = () => {
if(!sessionExist){ return; }
authService.deleteSteamSession();
notificationService.notifySuccess({title: "Disconnected from Steam", duration: 3000});
notificationService.notifySuccess({title: "notifications.settings.steam.success.titles.logout", duration: 3000});
};
return (
@@ -73,6 +73,9 @@ export function VersionViewer() {
.catch((e) => {console.log("*** ", e)})
}
}
else if(id === 2){
verifyFiles();
}
else if(id === 1){
window.electron.ipcRenderer.sendMessage("bs-version.open-folder", state);
}
@@ -82,23 +85,23 @@ export function VersionViewer() {
progressService.show(bsDownloaderService.downloadProgress$);
bsDownloaderService.download(state).then(res => {
progressService.hide(true);
if(!res.success){ notificationService.notifyError({title: "Unable to verify", desc: "Unable to verify, please try later"}); }
else(notificationService.notifySuccess({title: "Verification complete"}));
if(!res.success){ notificationService.notifyError({title: "notifications.bs-download.errors.titles.verification-failed", desc: "notifications.bs-download.errors.msg.verification-failed"}); }
else(notificationService.notifySuccess({title: "notifications.bs-download.success.titles.verification-finished"}));
})
}
const launchBs = () => {
bsLauncherService.launch(state, oculusMode, desktopMode, debugMode).then(res => {
if(!res.success){ notificationService.notifyError({title: 'Unable to launch', desc: res.error.title}); }
else if(res.data === "STEAM_NOT_RUNNING"){ notificationService.notifyWarning({title: "Steam not running", desc: "Steam must be running to launch Beat Saber."}); }
else if(res.data === "BS_ALREADY_RUNNING"){ notificationService.notifyWarning({title: "Beat Saber already running", desc: "Please close Beat Saber to launch."}); }
if(!res.success){ notificationService.notifyError({title: "notifications.bs-launch.errors.titles.UNABLE_TO_LAUNCH", desc: res.error.title}); }
else if(res.data === "STEAM_NOT_RUNNING"){ notificationService.notifyError({title: "notifications.bs-launch.errors.titles.STEAM_NOT_RUNNING", desc: "notifications.bs-launch.errors.msg.STEAM_NOT_RUNNING"}); }
else if(res.data === "BS_ALREADY_RUNNING"){ notificationService.notifyError({title: "notifications.bs-launch.errors.titles.UNABLE_TO_LAUNCH", desc: "notifications.bs-launch.errors.msg.UNABLE_TO_LAUNCH"}); }
else if(res.data === "EXE_NOT_FINDED"){
notificationService.notifyError({title: "Files missing", desc: "Some files are missing, please verify the download", actions: [{id: "0", title:"Verfiy"}]}).then(res => {
notificationService.notifyError({title: "notifications.bs-launch.errors.titles.EXE_NOT_FINDED", desc: "notifications.bs-launch.errors.msg.EXE_NOT_FINDED", actions: [{id: "0", title:"misc.verify"}]}).then(res => {
if(res !== "0"){ return; }
verifyFiles();
});
}
else if(res.data === "LAUNCHED"){ notificationService.notifySuccess({title: "Launching..."}) }
else if(res.data === "LAUNCHED"){ notificationService.notifySuccess({title: "notifications.bs-launch.success.titles.launching"}) }
else(notificationService.notifyError({title: res.data || res.error.title}));
});
}
-1
View File
@@ -47,7 +47,6 @@ export class I18nService {
public translate(translationKey: string): string{
const cachedTranlation = this.cache.get(translationKey);
if(!!cachedTranlation){ return cachedTranlation; }
console.log(translationKey);
const tranlated = getProperty(this.dictionary, translationKey);
tranlated && this.cache.set(translationKey, tranlated);
return tranlated || translationKey;