diff --git a/assets/jsons/translations/en.json b/assets/jsons/translations/en.json index 7c7aaf61..eccb9af9 100644 --- a/assets/jsons/translations/en.json +++ b/assets/jsons/translations/en.json @@ -245,6 +245,7 @@ }, "additional-content":{ "deep-link": { + "select-all": "Select all", "activation":{ "success":{ "title":"OneClick activated!", diff --git a/assets/jsons/translations/es.json b/assets/jsons/translations/es.json index 50f6b63c..8810673e 100644 --- a/assets/jsons/translations/es.json +++ b/assets/jsons/translations/es.json @@ -245,6 +245,7 @@ }, "additional-content":{ "deep-link": { + "select-all": "Seleccionar todo", "activation":{ "success":{ "title":"¡OneClick activado!", diff --git a/assets/jsons/translations/fr.json b/assets/jsons/translations/fr.json index b83e00e8..06b7bcff 100644 --- a/assets/jsons/translations/fr.json +++ b/assets/jsons/translations/fr.json @@ -245,6 +245,7 @@ }, "additional-content":{ "deep-link": { + "select-all": "Tout sélectionner", "activation":{ "success":{ "title":"OneClick activé !", diff --git a/src/renderer/pages/settings-page.component.tsx b/src/renderer/pages/settings-page.component.tsx index 44fe2dc4..e1b86ed4 100644 --- a/src/renderer/pages/settings-page.component.tsx +++ b/src/renderer/pages/settings-page.component.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from "react"; +import { Dispatch, SetStateAction, useEffect, useState } from "react"; import SettingColorChooser from "renderer/components/settings/setting-color-chooser.component"; import { SettingContainer } from "renderer/components/settings/setting-container.component"; import { RadioItem, SettingRadioArray } from "renderer/components/settings/setting-radio-array.component"; @@ -80,6 +80,8 @@ export function SettingsPage() { modelsManager.isDeepLinksEnabled().then(enabled => setModelsDeepLinkEnabled(() => enabled)) }, []); + const allDeepLinkEnabled = mapDeepLinksEnabled && playlistsDeepLinkEnabled && modelsDeepLinkEnabled; + const resetColors = () => { configService.delete("first-color" as DefaultConfigKey); configService.delete("second-color" as DefaultConfigKey); @@ -162,35 +164,26 @@ export function SettingsPage() { notificationService.notifySuccess({title, desc, duration: 3000}); } - const toogleMapDeepLinks = () => { - const isDesactivation = mapDeepLinksEnabled; - mapsManager.toogleDeepLinks().then(res => { - if(res){ return showDeepLinkSuccess(isDesactivation); } - showDeepLinkError(isDesactivation); - }).catch(() => { - showDeepLinkError(isDesactivation); - }).finally(() => mapsManager.isDeepLinksEnabled().then(enabled => setMapDeepLinksEnabled(() => enabled))); + const switchDeepLink = async (manager: MapsManagerService|PlaylistsManagerService|ModelsManagerService, enable: boolean, showNotification: boolean, setter: Dispatch>) => { + const res = await (enable ? manager.enableDeepLink() : manager.disableDeepLink()); + showNotification && (res ? showDeepLinkSuccess(!enable) : showDeepLinkError(!enable)); + const isEnable = await manager.isDeepLinksEnabled() + setter(() => isEnable) + return res; } - const tooglePlaylistsDeepLinks = () => { - const isDesactivation = playlistsDeepLinkEnabled; - playlistsManager.toogleDeepLinks().then(res => { - if(res){ return showDeepLinkSuccess(isDesactivation); } - showDeepLinkError(isDesactivation); - }).catch(() => { - showDeepLinkError(isDesactivation); - }).finally(() => playlistsManager.isDeepLinksEnabled().then(enabled => setPlaylistsDeepLinkEnabled(() => enabled))); - } + const toogleMapDeepLinks = (showNotification = true) => switchDeepLink(mapsManager, !mapDeepLinksEnabled, showNotification, setMapDeepLinksEnabled); + const tooglePlaylistsDeepLinks = (showNotification = true) => switchDeepLink(playlistsManager, !playlistsDeepLinkEnabled, showNotification, setPlaylistsDeepLinkEnabled); + const toogleModelsDeepLinks = (showNotification = true) => switchDeepLink(modelsManager, !modelsDeepLinkEnabled, showNotification, setModelsDeepLinkEnabled); + const toogleAllDeepLinks = async () => { + const res = (await Promise.all([ + switchDeepLink(mapsManager, !allDeepLinkEnabled, false, setMapDeepLinksEnabled), + switchDeepLink(playlistsManager, !allDeepLinkEnabled, false, setPlaylistsDeepLinkEnabled), + switchDeepLink(modelsManager, !allDeepLinkEnabled, false, setModelsDeepLinkEnabled) + ])).every(activation => activation === true); - const toogleModelsDeepLinks = () => { - const isDesactivation = modelsDeepLinkEnabled; - modelsManager.toogleDeepLinks().then(res => { - if(res){ return showDeepLinkSuccess(isDesactivation); } - showDeepLinkError(isDesactivation); - }).catch(() => { - showDeepLinkError(isDesactivation); - }).finally(() => modelsManager.isDeepLinksEnabled().then(enabled => setModelsDeepLinkEnabled(() => enabled))); - } + res ? showDeepLinkSuccess(allDeepLinkEnabled) : showDeepLinkError(allDeepLinkEnabled); + }; return (
@@ -209,8 +202,8 @@ export function SettingsPage() {
- - + setFirstColorSetting}/> + setSecondColorSetting}/>
@@ -230,10 +223,30 @@ export function SettingsPage() { -
    -
  • +
    - + + {t("notifications.settings.additional-content.deep-link.select-all")} +
    +
    + + {e.stopPropagation(); linkOpener.open("https://beatsaver.com/")}}/> + + + {e.stopPropagation(); linkOpener.open("https://bsaber.com/")}}/> + + + {e.stopPropagation(); linkOpener.open("https://scoresaber.com/")}}/> + + + {e.stopPropagation(); linkOpener.open("https://modelsaber.com/")}}/> + +
    +
    +
      +
    • toogleMapDeepLinks()}> +
      + toogleMapDeepLinks()} checked={mapDeepLinksEnabled}/> {t("misc.maps")}
      @@ -248,9 +261,9 @@ export function SettingsPage() {
    • -
    • +
    • tooglePlaylistsDeepLinks()}>
      - + tooglePlaylistsDeepLinks()} checked={playlistsDeepLinkEnabled}/> {t("misc.playlists")}
      @@ -259,9 +272,9 @@ export function SettingsPage() {
    • -
    • +
    • toogleModelsDeepLinks()}>
      - + toogleModelsDeepLinks()} checked={modelsDeepLinkEnabled}/> {t("misc.models")}
      @@ -282,7 +295,7 @@ export function SettingsPage() {
      - + toogleShowSupporters}/>
      diff --git a/src/renderer/services/maps-manager.service.ts b/src/renderer/services/maps-manager.service.ts index 0838458f..a801fa83 100644 --- a/src/renderer/services/maps-manager.service.ts +++ b/src/renderer/services/maps-manager.service.ts @@ -166,24 +166,19 @@ export class MapsManagerService { this.progressBar.hide(true); } - public isDeepLinksEnabled(): Promise{ - - return this.ipcService.send("is-map-deep-links-enabled").then(res => ( - res.success ? res.data : false - )); - + public async isDeepLinksEnabled(): Promise{ + const res = await this.ipcService.send("is-map-deep-links-enabled"); + return res.success ? res.data : false; } - public async toogleDeepLinks(): Promise{ - - const isEnabled = await this.isDeepLinksEnabled(); - - const channel = isEnabled ? "unregister-maps-deep-link" : "register-maps-deep-link"; - - const res = await this.ipcService.send(channel); - + public async enableDeepLink(): Promise{ + const res = await this.ipcService.send("register-maps-deep-link"); return res.success ? res.data : false; + } + public async disableDeepLink(): Promise{ + const res = await this.ipcService.send("unregister-maps-deep-link"); + return res.success ? res.data : false; } public get versionLinked$(): Observable{ diff --git a/src/renderer/services/models-manager.service.ts b/src/renderer/services/models-manager.service.ts index b3802253..d70942f0 100644 --- a/src/renderer/services/models-manager.service.ts +++ b/src/renderer/services/models-manager.service.ts @@ -21,18 +21,14 @@ export class ModelsManagerService { )); } - public async toogleDeepLinks(): Promise{ - - const isEnabled = await this.isDeepLinksEnabled(); - - const channel = isEnabled ? "unregister-models-deep-link" : "register-models-deep-link"; - - const res = await this.ipc.send(channel); - + public async enableDeepLink(): Promise{ + const res = await this.ipc.send("register-models-deep-link"); return res.success ? res.data : false; - } - + public async disableDeepLink(): Promise{ + const res = await this.ipc.send("unregister-models-deep-link"); + return res.success ? res.data : false; + } } \ No newline at end of file diff --git a/src/renderer/services/playlists-manager.service.ts b/src/renderer/services/playlists-manager.service.ts index 598740dd..43bb9d05 100644 --- a/src/renderer/services/playlists-manager.service.ts +++ b/src/renderer/services/playlists-manager.service.ts @@ -21,16 +21,14 @@ export class PlaylistsManagerService { )); } - public async toogleDeepLinks(): Promise{ - - const isEnabled = await this.isDeepLinksEnabled(); - - const channel = isEnabled ? "unregister-playlists-deep-link" : "register-playlists-deep-link"; - - const res = await this.ipc.send(channel); - + public async enableDeepLink(): Promise{ + const res = await this.ipc.send("register-playlists-deep-link"); return res.success ? res.data : false; + } + public async disableDeepLink(): Promise{ + const res = await this.ipc.send("unregister-playlists-deep-link"); + return res.success ? res.data : false; } } \ No newline at end of file