Bootbox dialog improvements (#1192)

* Translate bootbox dialog buttons

This also isolates the bootbox dependency.

* Migrate delete playlist dialog from window.confirm to bootbox.confirm
This commit is contained in:
Pedro Galhardo 2022-06-23 02:27:58 +01:00 committed by GitHub
parent 0ca0b34ff0
commit 569f6c279a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 80 additions and 55 deletions

View file

@ -24,7 +24,7 @@ const Events = {
// CTRL + R // CTRL + R
if (event.keyCode === 82 && event.ctrlKey) { if (event.keyCode === 82 && event.ctrlKey) {
event.preventDefault() event.preventDefault()
bootbox.confirm(app.getLz('term.reload'), (res)=>{ app.confirm(app.getLz('term.reload'), (res)=>{
if (res) { if (res) {
window.location.reload() window.location.reload()
} }
@ -69,8 +69,8 @@ const Events = {
// Prevent Scrolling on spacebar // Prevent Scrolling on spacebar
if (event.keyCode === 32 && event.target === document.body) { if (event.keyCode === 32 && event.target === document.body) {
event.preventDefault() event.preventDefault()
app.SpacePause() app.SpacePause()
} }
}); });

View file

@ -952,22 +952,22 @@ const app = new Vue({
} }
} catch (e) { } catch (e) {
localStorage.setItem("playingBitrate", "256") localStorage.setItem("playingBitrate", "256")
} }
if (!app.cfg.audio.normalization) {CiderAudio.hierarchical_loading();} if (!app.cfg.audio.normalization) {CiderAudio.hierarchical_loading();}
} }
if (app.cfg.audio.normalization) { if (app.cfg.audio.normalization) {
// get unencrypted audio previews to get SoundCheck's normalization tag // get unencrypted audio previews to get SoundCheck's normalization tag
try { try {
let previewURL = null let previewURL = null
try { try {
previewURL = app.mk.nowPlayingItem.previewURL previewURL = app.mk.nowPlayingItem.previewURL
} catch (e) { } catch (e) {
} }
if (previewURL == null && ((app.mk.nowPlayingItem?._songId ?? (app.mk.nowPlayingItem["songId"] ?? app.mk.nowPlayingItem.relationships.catalog.data[0].id)) != -1)) { if (previewURL == null && ((app.mk.nowPlayingItem?._songId ?? (app.mk.nowPlayingItem["songId"] ?? app.mk.nowPlayingItem.relationships.catalog.data[0].id)) != -1)) {
app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/songs/${app.mk.nowPlayingItem?._songId ?? (app.mk.nowPlayingItem["songId"] ?? app.mk.nowPlayingItem.relationships.catalog.data[0].id)}`).then((response) => { app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/songs/${app.mk.nowPlayingItem?._songId ?? (app.mk.nowPlayingItem["songId"] ?? app.mk.nowPlayingItem.relationships.catalog.data[0].id)}`).then((response) => {
previewURL = response.data.data[0].attributes.previews[0].url previewURL = response.data.data[0].attributes.previews[0].url
if (previewURL) if (previewURL)
console.debug("[Cider][MaikiwiSoundCheck] previewURL response.data.data[0].attributes.previews[0].url: " + previewURL) console.debug("[Cider][MaikiwiSoundCheck] previewURL response.data.data[0].attributes.previews[0].url: " + previewURL)
ipcRenderer.send('getPreviewURL', previewURL) ipcRenderer.send('getPreviewURL', previewURL)
@ -1173,7 +1173,7 @@ const app = new Vue({
} }
}, },
unauthorize() { unauthorize() {
bootbox.confirm(app.getLz('term.confirmLogout'), function (result) { this.confirm(app.getLz('term.confirmLogout'), function (result) {
if (result) { if (result) {
app.mk.unauthorize() app.mk.unauthorize()
document.location.reload() document.location.reload()
@ -1554,22 +1554,24 @@ const app = new Vue({
}, },
deletePlaylist(id) { deletePlaylist(id) {
let self = this let self = this
if (confirm(app.getLz('term.deletePlaylist'))) { this.confirm(app.getLz('term.deletePlaylist'), (ok) => {
app.mk.api.v3.music(`/v1/me/library/playlists/${id}`, {}, { if (ok) {
fetchOptions: { app.mk.api.v3.music(`/v1/me/library/playlists/${id}`, {}, {
method: "DELETE" fetchOptions: {
} method: "DELETE"
}).then(res => { }
// remove this playlist from playlists.listing if it exists }).then(res => {
let found = self.playlists.listing.find(item => item.id == id) // remove this playlist from playlists.listing if it exists
if (found) { let found = self.playlists.listing.find(item => item.id == id)
self.playlists.listing.splice(self.playlists.listing.indexOf(found), 1) if (found) {
} self.playlists.listing.splice(self.playlists.listing.indexOf(found), 1)
setTimeout(() => { }
app.refreshPlaylists(false, false); setTimeout(() => {
}, 8000); app.refreshPlaylists(false, false);
}) }, 8000);
} })
}
});
}, },
/** /**
* @param {string} url, href for the initial request * @param {string} url, href for the initial request
@ -4624,6 +4626,29 @@ const app = new Vue({
app.mk._services.mediaItemPlayback._currentPlayer._playAssetURL(src, false) app.mk._services.mediaItemPlayback._currentPlayer._playAssetURL(src, false)
} }
} }
},
confirm(message, callback) {
bootbox.confirm(this.getBootboxParams(null, message, callback));
},
prompt(title, callback) {
bootbox.prompt(this.getBootboxParams(title, null, callback));
},
getBootboxParams(title, message, callback) {
return {
title: title,
message: message,
buttons: {
confirm: {
label: app.getLz('dialog.ok'),
},
cancel: {
label: app.getLz('dialog.cancel'),
},
},
callback: function (result) {
if (callback) callback(result);
},
}
} }
} }
}) })

View file

@ -280,7 +280,7 @@
}, },
deletePreset() { deletePreset() {
let presets = this.$root.cfg.audio.equalizer.presets let presets = this.$root.cfg.audio.equalizer.presets
bootbox.confirm(app.getLz('term.deletepreset.warn'), (result) => { app.confirm(app.getLz('term.deletepreset.warn'), (result) => {
if (result) { if (result) {
this.changePreset("default") this.changePreset("default")
// find the preset by id (preset) and remove it // find the preset by id (preset) and remove it
@ -351,7 +351,7 @@
}, },
addPreset() { addPreset() {
let self = this let self = this
bootbox.prompt(app.getLz('term.newpreset.name'), (res) => { app.prompt(app.getLz('term.newpreset.name'), (res) => {
if (res) { if (res) {
let eqSettings = Clone(app.cfg.audio.equalizer) let eqSettings = Clone(app.cfg.audio.equalizer)
let newPreset = new self.eqPreset() let newPreset = new self.eqPreset()
@ -386,7 +386,7 @@
}, },
importPreset() { importPreset() {
let self = this let self = this
bootbox.prompt("Enter preset share code", (res) => { app.prompt("Enter preset share code", (res) => {
if (res) { if (res) {
let preset = JSON.parse(atob(res)) let preset = JSON.parse(atob(res))
if (preset.frequencies && preset.gain && preset.Q && preset.mix && preset.vibrantBass) { if (preset.frequencies && preset.gain && preset.Q && preset.mix && preset.vibrantBass) {

View file

@ -4,7 +4,7 @@
<div class="row"> <div class="row">
<div class="col nopadding"> <div class="col nopadding">
<h1 class="header-text"> <h1 class="header-text">
{{ $root.getLz("settings.option.visual.theme.manageStyles") }} {{ $root.getLz("settings.option.visual.theme.manageStyles") }}
</h1> </h1>
</div> </div>
<div class="col-auto nopadding flex-center"> <div class="col-auto nopadding flex-center">
@ -32,11 +32,11 @@
</div> </div>
<ul class="list-group list-group-flush"> <ul class="list-group list-group-flush">
<template v-for="theme in themes"> <template v-for="theme in themes">
<li @click="addStyle(theme.file)" <li @click="addStyle(theme.file)"
@contextmenu="contextMenu($event, theme)" @contextmenu="contextMenu($event, theme)"
class="list-group-item list-group-item-dark" class="list-group-item list-group-item-dark"
:class="{'applied': $root.cfg.visual.styles.includes(theme.file)}"> :class="{'applied': $root.cfg.visual.styles.includes(theme.file)}">
<b-row> <b-row>
<b-col class="themeLabel">{{theme.name}}</b-col> <b-col class="themeLabel">{{theme.name}}</b-col>
<template v-if="$root.cfg.visual.styles.includes(theme.file)"> <template v-if="$root.cfg.visual.styles.includes(theme.file)">
@ -58,13 +58,13 @@
</b-row> </b-row>
</li> </li>
<li @click="addStyle(packEntry.file)" <li @click="addStyle(packEntry.file)"
@contextmenu="contextMenu($event, theme)" @contextmenu="contextMenu($event, theme)"
class="list-group-item list-group-item-dark addon" class="list-group-item list-group-item-dark addon"
v-for="packEntry in theme.pack" v-for="packEntry in theme.pack"
:class="{'applied': $root.cfg.visual.styles.includes(packEntry.file)}" :class="{'applied': $root.cfg.visual.styles.includes(packEntry.file)}"
v-if="theme.pack"> v-if="theme.pack">
<b-row> <b-row>
<b-col class="themeLabel">{{packEntry.name}}</b-col> <b-col class="themeLabel">{{packEntry.name}}</b-col>
<template v-if="$root.cfg.visual.styles.includes(packEntry.file)"> <template v-if="$root.cfg.visual.styles.includes(packEntry.file)">
@ -111,7 +111,7 @@
</b-col> </b-col>
</b-row> </b-row>
</b-list-group-item> </b-list-group-item>
</draggable> </draggable>
</div> </div>
`, `,
props: { props: {
@ -244,7 +244,7 @@
name: app.getLz("settings.option.visual.theme.uninstall"), name: app.getLz("settings.option.visual.theme.uninstall"),
disabled: true, disabled: true,
action: () => { action: () => {
bootbox.confirm(app.stringTemplateParser(app.getLz("settings.prompt.visual.theme.uninstallTheme"), { app.confirm(app.stringTemplateParser(app.getLz("settings.prompt.visual.theme.uninstallTheme"), {
theme: theme.name ?? theme.file theme: theme.name ?? theme.file
}), (res) => { }), (res) => {
if (res) { if (res) {
@ -317,7 +317,7 @@
let msg = app.stringTemplateParser(app.getLz('settings.option.visual.theme.github.install.confirm'), { let msg = app.stringTemplateParser(app.getLz('settings.option.visual.theme.github.install.confirm'), {
repo: repo.full_name repo: repo.full_name
}); });
bootbox.confirm(msg, (res) => { app.confirm(msg, (res) => {
if (res) { if (res) {
ipcRenderer.once("theme-installed", (event, arg) => { ipcRenderer.once("theme-installed", (event, arg) => {
if (arg.success) { if (arg.success) {
@ -334,7 +334,7 @@
}, },
installThemeURL() { installThemeURL() {
let self = this let self = this
bootbox.prompt(app.getLz('settings.prompt.visual.theme.github.URL'), (result) => { app.prompt(app.getLz('settings.prompt.visual.theme.github.URL'), (result) => {
if (result) { if (result) {
ipcRenderer.once("theme-installed", (event, arg) => { ipcRenderer.once("theme-installed", (event, arg) => {
if (arg.success) { if (arg.success) {

View file

@ -2,11 +2,11 @@
<div class="content-inner keybinds-page"> <div class="content-inner keybinds-page">
<div class="md-option-header"> <div class="md-option-header">
<span>{{$root.getLz('settings.option.general.keybindings')}}</span> <span>{{$root.getLz('settings.option.general.keybindings')}}</span>
</div> </div>
<div class="settings-option-body"> <div class="settings-option-body">
<div class="md-option-header-sub"> <div class="md-option-header-sub">
<span>{{$root.getLz('settings.option.general.keybindings.library')}}</span> <span>{{$root.getLz('settings.option.general.keybindings.library')}}</span>
</div> </div>
<div class="md-option-line"> <div class="md-option-line">
<div class="md-option-segment"> <div class="md-option-segment">
{{$root.getLz('settings.description.search')}} {{$root.getLz('settings.description.search')}}
@ -86,7 +86,7 @@
</div> </div>
<div class="md-option-header-sub"> <div class="md-option-header-sub">
<span>{{$root.getLz('settings.option.general.keybindings.session')}}</span> <span>{{$root.getLz('settings.option.general.keybindings.session')}}</span>
</div> </div>
<div class="md-option-line"> <div class="md-option-line">
<div class="md-option-segment"> <div class="md-option-segment">
{{$root.getLz('settings.description.private')}} {{$root.getLz('settings.description.private')}}
@ -100,7 +100,7 @@
</div> </div>
<div class="md-option-header-sub"> <div class="md-option-header-sub">
<span>{{$root.getLz('settings.option.general.keybindings.control')}}</span> <span>{{$root.getLz('settings.option.general.keybindings.control')}}</span>
</div> </div>
<div class="md-option-line"> <div class="md-option-line">
<div class="md-option-segment"> <div class="md-option-segment">
{{$root.getLz('settings.description.remote')}} {{$root.getLz('settings.description.remote')}}
@ -158,7 +158,7 @@
</div> </div>
<div class="md-option-header-sub" v-if="app.platform !== 'darwin'"> <div class="md-option-header-sub" v-if="app.platform !== 'darwin'">
<span>{{$root.getLz('settings.option.general.keybindings.interface')}}</span> <span>{{$root.getLz('settings.option.general.keybindings.interface')}}</span>
</div> </div>
<div class="md-option-line" v-if="app.platform !== 'darwin'"> <div class="md-option-line" v-if="app.platform !== 'darwin'">
<div class="md-option-segment"> <div class="md-option-segment">
{{$root.getLz('term.zoomin')}} {{$root.getLz('term.zoomin')}}
@ -194,7 +194,7 @@
</div> </div>
<div class="md-option-header-sub"> <div class="md-option-header-sub">
<span>{{$root.getLz('settings.option.general.keybindings.advanced')}}</span> <span>{{$root.getLz('settings.option.general.keybindings.advanced')}}</span>
</div> </div>
<div class="md-option-line"> <div class="md-option-line">
<div class="md-option-segment"> <div class="md-option-segment">
{{$root.getLz('settings.description.developer')}} {{$root.getLz('settings.description.developer')}}
@ -210,7 +210,7 @@
{{$root.getLz('term.reset')}} {{$root.getLz('term.reset')}}
</button> </button>
</div> </div>
</div> </div>
</script> </script>
@ -265,7 +265,7 @@
document.body.removeChild(blur); document.body.removeChild(blur);
clearTimeout(keyBindTimeout); clearTimeout(keyBindTimeout);
notyf.success(app.getLz('settings.notyf.general.keybindings.update.success')); notyf.success(app.getLz('settings.notyf.general.keybindings.update.success'));
bootbox.confirm(app.getLz("settings.prompt.general.keybindings.update.success"), (ok) => { app.confirm(app.getLz("settings.prompt.general.keybindings.update.success"), (ok) => {
if (ok) ipcRenderer.invoke("relaunchApp") if (ok) ipcRenderer.invoke("relaunchApp")
}) })
} else { } else {
@ -296,7 +296,7 @@
app.cfg.general.keybindings.zoomrst = [app.platform == "darwin" ? "Command" : "Control", "num0"]; app.cfg.general.keybindings.zoomrst = [app.platform == "darwin" ? "Command" : "Control", "num0"];
app.cfg.general.keybindings.openDeveloperTools = [app.platform == "darwin" ? "Command" : "Control", app.platform == "darwin" ? "Option" : "Shift", "I"]; app.cfg.general.keybindings.openDeveloperTools = [app.platform == "darwin" ? "Command" : "Control", app.platform == "darwin" ? "Option" : "Shift", "I"];
notyf.success(app.getLz('settings.notyf.general.keybindings.update.success')); notyf.success(app.getLz('settings.notyf.general.keybindings.update.success'));
bootbox.confirm(app.getLz("settings.prompt.general.keybindings.update.success"), (ok) => { app.confirm(app.getLz("settings.prompt.general.keybindings.update.success"), (ok) => {
if (ok) ipcRenderer.invoke("relaunchApp") if (ok) ipcRenderer.invoke("relaunchApp")
}) })
}, },

View file

@ -125,13 +125,13 @@
let msg = app.stringTemplateParser(app.getLz('settings.option.visual.plugin.github.install.confirm'), { let msg = app.stringTemplateParser(app.getLz('settings.option.visual.plugin.github.install.confirm'), {
repo: repo.full_name repo: repo.full_name
}); });
bootbox.confirm(msg, (res) => { app.confirm(msg, (res) => {
if (res) { if (res) {
ipcRenderer.once("plugin-installed", (event, arg) => { ipcRenderer.once("plugin-installed", (event, arg) => {
if (arg.success) { if (arg.success) {
self.themes = [] self.themes = []
notyf.success(app.getLz('settings.notyf.visual.plugin.install.success')); notyf.success(app.getLz('settings.notyf.visual.plugin.install.success'));
bootbox.confirm(app.getLz("settings.prompt.visual.plugin.github.success"), (ok)=>{ app.confirm(app.getLz("settings.prompt.visual.plugin.github.success"), (ok)=>{
if (ok) { if (ok) {
ipcRenderer.invoke("relaunchApp") ipcRenderer.invoke("relaunchApp")
} else { } else {
@ -148,12 +148,12 @@
}, },
installThemeURL() { installThemeURL() {
let self = this let self = this
bootbox.prompt(app.getLz('settings.prompt.visual.plugin.github.URL'), (result) => { app.prompt(app.getLz('settings.prompt.visual.plugin.github.URL'), (result) => {
if (result) { if (result) {
ipcRenderer.once("plugin-installed", (event, arg) => { ipcRenderer.once("plugin-installed", (event, arg) => {
if (arg.success) { if (arg.success) {
self.themes = ipcRenderer.sendSync("get-themes") self.themes = ipcRenderer.sendSync("get-themes")
bootbox.confirm(app.getLz("settings.prompt.visual.plugin.github.success"), (ok)=>{ app.confirm(app.getLz("settings.prompt.visual.plugin.github.success"), (ok)=>{
if (ok) { if (ok) {
ipcRenderer.invoke("relaunchApp") ipcRenderer.invoke("relaunchApp")
} else { } else {

View file

@ -1407,7 +1407,7 @@
} }
}, },
reinstallWidevineCDM() { reinstallWidevineCDM() {
bootbox.confirm(app.getLz("settings.option.experimental.reinstallwidevine.confirm"), (ok) => { app.confirm(app.getLz("settings.option.experimental.reinstallwidevine.confirm"), (ok) => {
if (ok) { if (ok) {
ipcRenderer.invoke("reinstall-widevine-cdm"); ipcRenderer.invoke("reinstall-widevine-cdm");
} }
@ -1450,7 +1450,7 @@
toggleAudioContext: function () { toggleAudioContext: function () {
if (app.cfg.advanced.AudioContext === true) { if (app.cfg.advanced.AudioContext === true) {
if (navigator.hardwareConcurrency < 6) { if (navigator.hardwareConcurrency < 6) {
bootbox.confirm(app.getLz("settings.warn.audio.enableAdvancedFunctionality.lowcores"), function (result) { app.confirm(app.getLz("settings.warn.audio.enableAdvancedFunctionality.lowcores"), function (result) {
if (result) { if (result) {
CiderAudio.init(); CiderAudio.init();
if (app.cfg.audio.normalization === true) { if (app.cfg.audio.normalization === true) {
@ -1497,7 +1497,7 @@
}, },
promptForRelaunch() { promptForRelaunch() {
bootbox.confirm(app.getLz('action.relaunch.confirm'), function (result) { app.confirm(app.getLz('action.relaunch.confirm'), function (result) {
if (result) { if (result) {
ipcRenderer.send('relaunchApp', ''); ipcRenderer.send('relaunchApp', '');
} }

View file

@ -146,7 +146,7 @@
let msg = app.stringTemplateParser(app.getLz('settings.option.visual.theme.github.install.confirm'), { let msg = app.stringTemplateParser(app.getLz('settings.option.visual.theme.github.install.confirm'), {
repo: repo.full_name repo: repo.full_name
}); });
bootbox.confirm(msg, (res) => { app.confirm(msg, (res) => {
if (res) { if (res) {
ipcRenderer.once("theme-installed", (event, arg) => { ipcRenderer.once("theme-installed", (event, arg) => {
if (arg.success) { if (arg.success) {
@ -163,7 +163,7 @@
}, },
installThemeURL() { installThemeURL() {
let self = this let self = this
bootbox.prompt(app.getLz('settings.prompt.visual.theme.github.URL'), (result) => { app.prompt(app.getLz('settings.prompt.visual.theme.github.URL'), (result) => {
if (result) { if (result) {
ipcRenderer.once("theme-installed", (event, arg) => { ipcRenderer.once("theme-installed", (event, arg) => {
if (arg.success) { if (arg.success) {