-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[16.0][IMP] web_notify:t3894 Allow notify with sound #2923
Open
GabbasovDinar
wants to merge
1
commit into
OCA:16.0
Choose a base branch
from
cetmix:16.0-t3894-web_notify-sound-on-notification
base: 16.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ | |
* `Tecnativa <https://www.tecnativa.com>`_: | ||
|
||
* David Vidal | ||
|
||
* Cetmix OÜ <https://cetmix.com/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,10 @@ | |
|
||
/* | ||
:Author: David Goodger ([email protected]) | ||
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ | ||
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ | ||
:Copyright: This stylesheet has been placed in the public domain. | ||
|
||
Default cascading style sheet for the HTML output of Docutils. | ||
Despite the name, some widely supported CSS2 features are used. | ||
|
||
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to | ||
customize this style sheet. | ||
|
@@ -275,7 +274,7 @@ | |
margin-left: 2em ; | ||
margin-right: 2em } | ||
|
||
pre.code .ln { color: gray; } /* line numbers */ | ||
pre.code .ln { color: grey; } /* line numbers */ | ||
pre.code, code { background-color: #eeeeee } | ||
pre.code .comment, code .comment { color: #5C6576 } | ||
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } | ||
|
@@ -301,7 +300,7 @@ | |
span.pre { | ||
white-space: pre } | ||
|
||
span.problematic, pre.problematic { | ||
span.problematic { | ||
color: red } | ||
|
||
span.section-subtitle { | ||
|
@@ -420,6 +419,16 @@ <h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1> | |
<pre class="code python literal-block"> | ||
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">notify_default</span><span class="p">(</span><span class="n">message</span><span class="o">=</span><span class="s1">'My default message'</span><span class="p">)</span> | ||
</pre> | ||
<p>You can also add sound to your notifications by using the sound parameter. The sound parameter expects a string containing the URL path to the audio file that should be played when the notification is displayed.</p> | ||
<p>Example:</p> | ||
<pre class="code python literal-block"> | ||
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">notify_success</span><span class="p">(</span><span class="n">message</span><span class="o">=</span><span class="s1">'My success message'</span><span class="p">,</span> <span class="n">sound</span><span class="o">=</span><span class="s1">'/<YOUR_MODULE>/static/audio/success.mp3'</span> <span class="p">)</span> | ||
</pre> | ||
<p>or</p> | ||
<pre class="code python literal-block"> | ||
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">notify_info</span><span class="p">(</span> <span class="n">message</span><span class="o">=</span><span class="s1">'My information message'</span><span class="p">,</span> <span class="n">sound</span><span class="o">=</span><span class="s1">'/<YOUR_MODULE>/static/audio/info.mp3'</span> <span class="p">)</span> | ||
</pre> | ||
<p>The sound parameter can be used with any notification type (success, danger, warning, info, or default). If the sound parameter is not provided, the notification will be displayed without any sound.</p> | ||
<p>The notifications can bring interactivity with some buttons.</p> | ||
<ul class="simple"> | ||
<li>One allowing to refresh the active view</li> | ||
|
@@ -477,14 +486,13 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2> | |
<li>David Vidal</li> | ||
</ul> | ||
</li> | ||
<li>Cetmix OÜ <<a class="reference external" href="https://cetmix.com/">https://cetmix.com/</a>></li> | ||
</ul> | ||
</div> | ||
<div class="section" id="maintainers"> | ||
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2> | ||
<p>This module is maintained by the OCA.</p> | ||
<a class="reference external image-reference" href="https://odoo-community.org"> | ||
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /> | ||
</a> | ||
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a> | ||
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use.</p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** @odoo-module alias=web_notify.AudioPlayer **/ | ||
|
||
import {Component, useState} from "@odoo/owl"; | ||
|
||
/** | ||
* @typedef AudioPlayerProps | ||
* @property {string} src URL of the audio file to be played | ||
* @property {number} [volume=1.0] Volume level of the audio (from 0.0 to 1.0) | ||
* @property {boolean} [loop=false] Whether the audio should loop | ||
* @property {Function} [onEnded] Callback function to be called when the audio ends | ||
*/ | ||
|
||
/** | ||
* The AudioPlayer component is responsible for playing audio files with | ||
* specified settings like volume and looping. It also provides the ability | ||
* to trigger actions when the audio playback ends. | ||
*/ | ||
export class AudioPlayer extends Component { | ||
setup() { | ||
this.state = useState({isPlaying: false}); | ||
this.audioElement = new Audio(this.props.src); | ||
|
||
// Set audio properties | ||
this.audioElement.volume = this.props.volume || 1.0; | ||
this.audioElement.loop = this.props.loop || false; | ||
|
||
// Start playing the audio | ||
this.audioElement | ||
.play() | ||
.then(() => { | ||
this.state.isPlaying = true; | ||
}) | ||
.catch((error) => { | ||
console.error("Audio playback failed:", error); | ||
}); | ||
|
||
// Listen for the end of the audio playback | ||
this.audioElement.addEventListener("ended", this.onAudioEnded.bind(this)); | ||
} | ||
|
||
/** | ||
* Stops the audio playback and triggers the onEnded callback if provided. | ||
*/ | ||
stopAudio() { | ||
this.audioElement.pause(); | ||
this.audioElement.currentTime = 0; | ||
this.state.isPlaying = false; | ||
|
||
if (this.props.onEnded) { | ||
this.props.onEnded(); | ||
} | ||
} | ||
|
||
/** | ||
* Handler for when the audio playback ends. | ||
*/ | ||
onAudioEnded() { | ||
if (!this.props.loop) { | ||
this.stopAudio(); | ||
} | ||
} | ||
|
||
willUnmount() { | ||
// Clean up the audio element and listeners | ||
this.audioElement.removeEventListener("ended", this.onAudioEnded); | ||
this.audioElement.pause(); | ||
} | ||
} | ||
|
||
AudioPlayer.template = "web_notify.AudioPlayer"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- Copyright 2024 Cetmix OÜ | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="web_notify.AudioPlayer" owl="1"> | ||
<!-- No visual elements needed, audio is controlled programmatically --> | ||
</t> | ||
|
||
</templates> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using a service like SoundEffects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chienandalu
this service is limited to predefined sound effect settings and does not allow you to specify a link to any sound. In my case, only the sound effect link is passed for playback, which allows any sound to be dynamically played back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I mean, you can take inspiration in that code to implement your own sound service, resulting in a simpler impletation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chienandalu I was already inspired by this effect to write the current solution :-)