Patch Launcher Reset Scroll on Page Change

From WebOS Internals

Revision as of 00:42, 22 August 2011 by Jakeeeee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


This is only for webOS 1.4.5 or lower. webOS 2.x and higher have a different launcher implementation that will not work with this patch.

Contents

Introduction

If you have many apps on a page, you may have to scroll to see some of those. The launcher maintains the scroll state (the amount you have scrolled) on each page, which means when you return to a page, you are still at the location that you last scrolled to. This can be annoying. For example, it can make it difficult to train your muscle memory because, when repeating the same steps, the app you want is not always at the same location on the screen. This patch resets the scroll of each page back to the top when it goes out of view.

Update Dec '09: I've changed the way the patch is implemented, this new version is now compatible with the Wrap Pages patch.

Editing Process

  • SSH in.
  • Remount the filesystem as read/write:
sudo rootfs_open -w
  • Load launcher-assistant.js in vi:
sudo vi /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js
  • Locate the end of the setup method, around line 98:
		// setup the initial dimensions for launcher/global-search
		this.adjustLayout();
	},
 
	ready: function() {		
		this.globalSearchAssistant.ready();
	},
  • Add the lines below to the end of the setup method (that is, make sure they're inside the '},' before the ready method on line 102), so that it now looks like this:
		// setup the initial dimensions for launcher/global-search
		this.adjustLayout();
 
		// add a separate listener for resetting the scroll position on page changes, and also on deactivate
		Mojo.listen($('launcher_root'), Mojo.Event.propertyChange, this.resetScrollPosition.bindAsEventListener(this));
		Mojo.listen(this.controller.document, Mojo.Event.deactivate, this.resetScrollPosition.bindAsEventListener(this));
	},
 
	ready: function() {		
		this.globalSearchAssistant.ready();
	},
  • Add the following method somewhere else in the file, I suggest just below the ready method and before the deleteAllPages method, around line 105 (don't forget the comma after the closing brace, unless you add it right at the end of the class, as the last method):
	resetScrollPosition: function(event) {
		var pageIndex = (event.type === 'mojo-event-deactivate') ? this.activePageIndex : event.value;
		var scroller = this.getPageScroller(pageIndex);
		if (scroller && scroller.mojo) { scroller.mojo.revealTop(); }
	},
  • Save the file and quit vi.
  • Remount the filesystem as read only - this should reboot your Pre:
sudo rootfs_open -w


Patch Process

An older version of the patch is in the git/Preware repository, hopefully this version will be submitted soon. Until then, you can copy and paste the source below. Visit Applying Patches for info on how to use it. You can also apply it using webOS Quick Install. To apply the patch, follow the instructions above, and after remounting the filesystem as read/write, do the following:

  • Apply the patch (In this example, I have the patch file located in my home directory under patches):
cd /
sudo patch -p0 --backup-if-mismatch < ~/patches/reset-scroll.patch
This is what you should see if it ran properly:
patching file /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js
  • Remount the filesystem as read only as described above.


Patch Source (reset-scroll.patch)

--- /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js.orig	Sat Dec  5 11:48:12 2009
+++ /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js	Thu Dec  3 19:42:03 2009
@@ -98,5 +98,9 @@
 		// setup the initial dimensions for launcher/global-search
 		this.adjustLayout();
+		
+		// add a separate listener for resetting the scroll position on page changes, and also on deactivate
+		Mojo.listen($('launcher_root'), Mojo.Event.propertyChange, this.resetScrollPosition.bindAsEventListener(this));
+		Mojo.listen(this.controller.document, Mojo.Event.deactivate, this.resetScrollPosition.bindAsEventListener(this));
 	},
 
 	ready: function() {	
@@ -188,6 +188,12 @@
 	onResize: function(event) {
 		this.adjustLayout();
 	},
 
+	resetScrollPosition: function(event) {
+		var pageIndex = (event.type === 'mojo-event-deactivate') ? this.activePageIndex : event.value;
+		var scroller = this.getPageScroller(pageIndex);
+		if (scroller && scroller.mojo) { scroller.mojo.revealTop(); }
+	},
+
 	/* remove page data and their corresponding HTML */
 	deleteAllPages: function() {
Personal tools
Google AdSense