Patch Launcher Reset Scroll on Page Change

From WebOS Internals
Revision as of 14:55, 5 December 2009 by IMGrant (talk | contribs) (A new version of the patch that is compatible with the Wrap Pages patch - it modifies different parts of the file now.)
Jump to navigation Jump to search


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:

<source lang="bash">

sudo rootfs_open -w

</source>

  • Load launcher-assistant.js in vi:

<source lang="bash">

sudo vi /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js

</source>

  • Locate the end of the setup method, around line 98:

<source lang="javascript">

// setup the initial dimensions for launcher/global-search this.adjustLayout(); },

ready: function() { this.globalSearchAssistant.ready(); },

</source>

  • 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:

<source lang="javascript">

// 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(); },

</source>

  • 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):

<source lang="javascript">

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(); } },

</source>

  • Save the file and quit vi.
  • Remount the filesystem as read only - this should reboot your Pre:

<source lang="bash">

sudo rootfs_open -w

</source>


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):

<source lang="bash">

cd / sudo patch -p0 --backup-if-mismatch < ~/patches/reset-scroll.patch

</source>

This is what you should see if it ran properly: <source lang="text"> patching file /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js

</source>

  • Remount the filesystem as read only as described above.


Patch Source (reset-scroll.patch)

<source lang="diff"> --- /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() {


</source>