Difference between revisions of "Patch Messaging Sounds"

From WebOS Internals
Jump to navigation Jump to search
(New page: '''Description:''' This mod will allow you to specify the sound played on an incoming message, distinct from the alert and notification sounds. '''History:''' This is based //heavily// on...)
 
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
'''Description:''' This mod will allow you to specify the sound played on an incoming message, distinct from the alert and notification sounds.
+
{{template:patch}}
 +
==Introduction==
 +
This mod is now available in the Modifications patch repository.  Check out [[Applying_Patches|Applying Patches]] for instructions on applying the patches.  The mod is comprised of two patches, messaging-sounds.patch and message-tone-sounds-and-alerts.patch.
  
'''History:''' This is based //heavily// on the '''[[alerts-from-usb |Sounds and Alerts Program Modification]]''' by Kaerey. The three steps of this mod are replics of the three steps in that mod, adding "messages" to "alerts" and "notifications".  It is recommended, though not necessary, that you do that mod first.  Throughout these instructions, I will refer to that mod as the "Sounds and Alerts Mod".
+
==messaging-sounds.patch==
 +
Those of you using the [http://forums.precentral.net/homebrew-apps/188729-my-notification-v-1-0-3-6-30-a.html MyNotifications homebrew app] will only need this one. It patches the Messaging application to play the specified tone.  It is found in the ''messaging'' directory of the modifications repository.
  
'''Disclaimer:''' This is very involved.  I //highly// recommend that you back up every file before you change it.
+
==message-tone-sounds-and-alerts.patch==
 
+
This patches Palm's Sounds & Ringtones application, allowing you to specify sounds for alerts, notifications and new messages. It has none of the added features in MyNotifications. It's for those that don't need all the extras that MyNotifications provides. It is found in the ''sounds_and_alerts'' directory of the modifications repository.
'''Short Cut:''' If you are using [*http://forums.precentral.net/homebrew-apps/188729-my-notification-no-rooting-needed.html My Notification] then you can skip to step 4. The function under the Advanced Options of the app can be used to select your message sound. And you do not need to edit the Sounds and Alerts Program
 
 
 
= Step One: Modify the Sounds and Alerts Program to add the new fields=
 
 
 
Back up and modify /usr/palm/applications/com.palm.app.soundsandalerts/app/views/soundsalertsconfig/soundsalertsconfig-scene.html
 
 
 
Between lines 50 and 51 (or immediately after the changes made in Step 1 of the Sounds and Alerts Mod)
 
<pre><nowiki>
 
<div id='currentmessagerow' class="palm-row" x-mojo-tap-highlight="momentary">
 
                <div class="palm-row-wrapper">
 
                    <div class="label" x-mojo-loc=''>Message</div>
 
                    <div id='currentmessage' class="title"></div>                   
 
                </div>
 
            </div>
 
</nowiki></pre>
 
 
 
= Step Two: Create the database calls=
 
 
 
Back up and modify /usr/palm/applications/com.palm.app.soundsandalerts/app/models/SystemService.js
 
 
 
Find the Section of Code that deals with getRingtone and setRingtone starting on line 9:
 
<pre><nowiki>
 
SystemService.setRingtone = function(value,callback) {
 
 
 
    var request = new Mojo.Service.Request(SystemService.identifier, {
 
            method: 'setPreferences',
 
            parameters: {"ringtone":value},           
 
        });
 
    return request;
 
}
 
 
 
SystemService.getRingtone = function(callback) {
 
 
 
    var request = new Mojo.Service.Request(SystemService.identifier, {
 
            method: 'getPreferences',
 
            parameters: {"keys":["ringtone"],"subscribe":true},
 
            onSuccess: callback,
 
            onFailure: callback
 
        });
 
    return request;
 
}
 
</nowiki></pre>
 
We are going to create a like section for Messages:
 
<pre><nowiki>
 
SystemService.getMessages = function(callback) {
 
    var request = new Mojo.Service.Request(SystemService.identifier, {
 
            method: 'getPreferences',
 
            parameters: {"keys":["messagetone"]},
 
            onSuccess: callback,
 
            onFailure: callback
 
        });
 
    return request;
 
}
 
 
 
SystemService.setMessages = function(value){
 
    var request = new Mojo.Service.Request(SystemService.identifier, {
 
            method: 'setPreferences',
 
            parameters: {"messagetone":value},
 
        });
 
    return request;
 
}
 
</nowiki></pre>
 
 
 
= Step Three: Create the handlers for the new components=
 
 
 
Back up and modify /usr/palm/applications/com.palm.app.soundsandalerts/app/controllers/soundsalertsconfig-assistant.js
 
 
 
At line 81, you will see:
 
<pre><nowiki>
 
$('currentringtonerow').observe(Mojo.Event.tap, this.showAudioFilePicker.bindAsEventListener(this));
 
</nowiki></pre>
 
 
 
Create an entry for Messages, either after the line above, or after the additions to this section made in Step 3 of the Sounds and Alerts Mod:
 
<pre><nowiki>
 
$('currentmessagerow').observe(Mojo.Event.tap, this.showMessageFilePicker.bindAsEventListener(this));
 
</nowiki></pre>
 
 
 
Below that section you will see:
 
<pre><nowiki>
 
this.getCurrentVolumes();
 
this.getCurrentRingtone();
 
this.getVibrateSettings();   
 
this.getOtherSettings();
 
</nowiki></pre>
 
 
 
Add a line for Messages:
 
<pre><nowiki>
 
this.getCurrentMessage();
 
</nowiki></pre>
 
 
 
Find the Code near line 215:
 
<pre><nowiki>
 
getCurrentRingtone: function() {
 
        this.getCurrentRingtoneReq = SystemService.getRingtone(this.getCurrentRingtoneQuery.bind(this));
 
    },
 
 
 
    getCurrentRingtoneQuery: function(payload) {       
 
        if (payload.ringtone) {
 
            $('currentringtone').innerHTML = payload.ringtone.name;
 
            this.currRingtonePath = payload.ringtone.fullPath;   
 
        }
 
        else
 
            $('currentringtone').innerHTML = $L("Pick a ringtone");
 
 
 
    },
 
 
 
    showAudioFilePicker: function(event) {
 
        var params = {"kinds": ["ringtone"],"filePath":this.currRingtonePath,"onSelect":this.selectedAudioFile.bind(this),actionType:"attach",actionName: $L("Done")};
 
        Mojo.FilePicker.pickFile(params,Mojo.Controller.stageController);
 
    },
 
 
 
    selectedAudioFile: function(file) {       
 
        //var params = {"fullPath": encodeURIComponent(file.fullPath), "name":file.name};
 
        this.setRingtoneReq = SystemService.setRingtone(file);
 
        $('currentringtone').innerHTML = file.name;
 
    },
 
</nowiki></pre>
 
 
 
Add this code for Messages:
 
<pre><nowiki>
 
// Message Picking
 
    getCurrentMessage: function() {
 
        this.getCurrentMessageReq = SystemService.getMessages(this.getCurrentMessageQuery.bind(this));
 
    },
 
 
 
    getCurrentMessageQuery: function(payload) {       
 
        if (payload.messagetone) {
 
            $('currentmessage').innerHTML = payload.messagetone.name;
 
            this.currMessagePath = payload.messagetone.fullPath;   
 
        }
 
        else
 
            $('currentmessage').innerHTML = $L("Pick a message sound");
 
 
 
    },
 
 
 
    showMessageFilePicker: function(event) {
 
        var params = {"kinds": ["ringtone"],"filePath":this.currMessagePath,"onSelect":this.selectedMessageFile.bind(this),actionType:"attach",actionName: $L("Done")};
 
        Mojo.FilePicker.pickFile(params,Mojo.Controller.stageController);
 
    },
 
 
 
    selectedMessageFile: function(file) {       
 
        //var params = {"fullPath": encodeURIComponent(file.fullPath), "name":file.name};
 
        this.setMessageReq = SystemService.setMessages(file);
 
        $('currentmessage').innerHTML = file.name;
 
    },
 
</nowiki></pre>
 
 
 
= Step Four: Add the database call to the Messages Application=
 
 
 
Back up and modify /usr/palm/applications/com.palm.app.messaging/app/models/messaging-luna-service.js
 
 
 
After line 7, add:
 
<pre><nowiki>
 
  getMessagetone:  function(callback) {
 
        var request = new Mojo.Service.Request('palm://com.palm.systemservice', {
 
                method: 'getPreferences',
 
                parameters: {"keys":["messagetone"]},
 
                onSuccess: callback,
 
                onFailure: callback
 
        });
 
        return request;
 
  },
 
</nowiki></pre>
 
 
 
= Step Five: Have the Message Application play the sound from the database=
 
 
 
Back up and modify /usr/palm/applications/com.palm.app.messaging/app/controllers/notification-assistant.js
 
 
 
Below line 44 (just above the <ReminderCode> comment block), add:
 
<pre><nowiki>
 
NotificationAssistant.prototype.getandPlayMessagetone = function(bannerParams,bannerLaunchParams,bannerType){
 
MessagingMojoService.getMessagetone(this.doBanner.bind(this,bannerParams,bannerLaunchParams,bannerType));
 
};
 
 
 
NotificationAssistant.prototype.doBanner = function(bannerParams,bannerLaunchParams,bannerType,payload) {
 
        if (payload.messagetone)
 
                bannerParams.soundFile = payload.messagetone.fullPath;
 
        this.controller.showBanner(bannerParams,bannerLaunchParams,bannerType);
 
};
 
 
 
NotificationAssistant.prototype.playMessagetone = function(payload){
 
        if (payload.messagetone)
 
                this.controller.playSoundNotification('alerts',payload.messagetone.fullPath);
 
        else
 
this.controller.playSoundNotification('alerts','');
 
};
 
</nowiki></pre>
 
 
 
In the next function, '''NotificationAssistant.prototype.sendReminderNotification''', find the block of code:
 
<pre><nowiki>
 
        var bannerLaunchParams =  {
 
                reminderPersonId: resp.personId,
 
                clearBanner: true
 
        };
 
        this.controller.showBanner(bannerParams,bannerLaunchParams,'reminder');
 
</nowiki></pre>
 
Change that to:
 
<pre><nowiki>
 
var bannerLaunchParams =  {
 
                reminderPersonId: resp.personId,
 
                clearBanner: true
 
        };
 
        this.getandPlayMessagetone(bannerParams,bannerLaunchParams,'reminder');
 
</nowiki></pre>
 
 
 
In the function '''NotificationAssistant.prototype.considerForNotification''', find the block of code:
 
<pre><nowiki>
 
        // check if we should only play a sound (when you are already in a chat & a new message comes in)
 
        if(notificationData.get('playSoundOnly') && this.Messaging.messagingPrefs.enableNotificationSound) {
 
                this.controller.playSoundNotification('alerts','');
 
                return; // don't display any visual notification
 
        }
 
</nowiki></pre>
 
Change that to:
 
<pre><nowiki>
 
        // check if we should only play a sound (when you are already in a chat & a new message comes in)
 
        if(notificationData.get('playSoundOnly') && this.Messaging.messagingPrefs.enableNotificationSound) {
 
                MessagingMojoService.getMessagetone(this.playMessagetone.bind(this));
 
                return; // don't display any visual notification
 
        }
 
</nowiki></pre>
 
 
 
In the function '''NotificationAssistant.prototype.sendNewMessageNotificationAndUpdateDashboard''', find the block of code:
 
<pre><nowiki>
 
        var bannerParams = {
 
                messageText: notificationText
 
        };
 
        if (this.Messaging.messagingPrefs.enableNotificationSound)
 
                bannerParams.soundClass = "alerts";
 
        var bannerLaunchParams =  {
 
                chatThreadId: notificationData.get('chatThreadId'),
 
                clearBanner: true
 
        };
 
        this.controller.showBanner(bannerParams,bannerLaunchParams,'chat');
 
</nowiki></pre>
 
Change that to:
 
<pre><nowiki>
 
        var bannerParams = {
 
                messageText: notificationText
 
        };
 
        var bannerLaunchParams =  {
 
                chatThreadId: notificationData.get('chatThreadId'),
 
                clearBanner: true
 
        };
 
        if (this.Messaging.messagingPrefs.enableNotificationSound) {
 
                bannerParams.soundClass = "alerts";
 
this.getandPlayMessagetone(bannerParams,bannerLaunchParams,'chat');
 
} else
 
this.controller.showBanner(bannerParams,bannerLaunchParams,'chat');
 
</nowiki></pre>
 
 
 
Finally, as it looks like the immediate dashboard creation when the screen is off is causing the sound not to be played, in the same function, find this block of code:
 
<pre><nowiki>
 
// delay creating the dashboard window for the case where the banner is clicked on
 
                // to take you to the chat view.  This will likely result in the dashboard data
 
                // being cleared.  If the dashboard data is empty, we do not need to create the dashboard.             
 
                if (this.Messaging.DisplayState.isDisplayOn()) {
 
                        if (!this.isNewMessageDashboardPending) {
 
                                this.isNewMessageDashboardPending = true;
 
                                createDashboard.delay(5);
 
                        }
 
 
 
                } else {
 
                        createDashboard(); // if the screen is off, create the dashboard right away
 
                }
 
</nowiki></pre>
 
Change that to:
 
<pre><nowiki>
 
// delay creating the dashboard window for the case where the banner is clicked on
 
                // to take you to the chat view.  This will likely result in the dashboard data
 
                // being cleared.  If the dashboard data is empty, we do not need to create the dashboard.
 
                // if (this.Messaging.DisplayState.isDisplayOn()) {
 
                        if (!this.isNewMessageDashboardPending) {
 
                                this.isNewMessageDashboardPending = true;
 
                                createDashboard.delay(5);
 
                        }
 
 
 
                // } else {
 
                        // createDashboard(); // if the screen is off, create the dashboard right away
 
                // }
 
</nowiki></pre>
 
 
 
 
 
Copy your desired message sound to the "ringtones" directory in /media/internal/ringtones and it will be visible in the FilePicker.
 
 
 
Reboot the phone for changes to take effect.
 
 
 
= Credits=
 
The changes to the Sounds and Alerts app are slight modifications to the submissions of Kaerey.  The rest is submitted by JackieRipper.
 

Latest revision as of 09:44, 3 August 2009


Introduction

This mod is now available in the Modifications patch repository. Check out Applying Patches for instructions on applying the patches. The mod is comprised of two patches, messaging-sounds.patch and message-tone-sounds-and-alerts.patch.

messaging-sounds.patch

Those of you using the MyNotifications homebrew app will only need this one. It patches the Messaging application to play the specified tone. It is found in the messaging directory of the modifications repository.

message-tone-sounds-and-alerts.patch

This patches Palm's Sounds & Ringtones application, allowing you to specify sounds for alerts, notifications and new messages. It has none of the added features in MyNotifications. It's for those that don't need all the extras that MyNotifications provides. It is found in the sounds_and_alerts directory of the modifications repository.