Difference between revisions of "Patch Launcher Reset to Middle Page"

From WebOS Internals
Jump to navigation Jump to search
(New page: {{template:patch}} ==Introduction== The Launcher maintains the last page opened when you return to it. If you most frequently use apps on a certain page of the Launcher, you have to swipe...)
 
(Updated patch, now longer relies on Reset Scroll Position patch to reset scroll.)
Line 2: Line 2:
 
==Introduction==
 
==Introduction==
  
The Launcher maintains the last page opened when you return to it. If you most frequently use apps on a certain page of the Launcher, you have to swipe back to that page if the last app you launched was on another page.
+
By default, the Launcher maintains the last page opened when you return to it. If you most frequently use apps on a certain page of the Launcher, you have to swipe back to that page if the last app you launched was on another page.
 
This patch resets the Launcher to the middle page every time it opens. This works best if you have an odd number of pages (like the default 3), then you have the same number of pages to the left, and to the right, thus minimizing the number of swipes required to get to the first or last page.
 
This patch resets the Launcher to the middle page every time it opens. This works best if you have an odd number of pages (like the default 3), then you have the same number of pages to the left, and to the right, thus minimizing the number of swipes required to get to the first or last page.
This also works best in combination with the [[Patch Launcher Reset Scroll on Page Change]] patch to ensure the page is also always scrolled to the top.
+
It also resets the scroll position of all pages, so that when you re-open the Launcher, all pages will be scrolled to the top (previously it only did this if the Reset Scroll Position patch was also installed, I abandoned that idea. Apologies if anyone really wants the reset page behaviour without the reset scroll feature - check out the page history for older versions or adjust the patch accordingly).
  
 
==Editing Process==
 
==Editing Process==
Line 17: Line 17:
 
sudo vi /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js
 
sudo vi /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js
 
</source></blockquote>
 
</source></blockquote>
* Locate the 'Mojo.listen' handlers in the setup method around line 70 (setup begins at line 67 in webOS 1.3.1):
+
* Locate the beginning of the onDeactivate method around line 170:
 
<blockquote><source lang="javascript">
 
<blockquote><source lang="javascript">
setup: function() {
+
/* clean and hide global search */
+
onDeactivate: function(event) {
Mojo.listen(this.controller.document, Mojo.Event.deactivate, this.onDeactivate.bindAsEventListener(this));
+
Mojo.listen(this.controller.window, 'resize', this.onResize.bindAsEventListener(this));
+
this.globalSearchAssistant.deactivate();
 +
 +
this.reorderController.cancel();
 +
 +
if (this.appDialog) {
 +
this.appDialog.mojo.close();
 +
}
 +
 +
SystemManagerService.showQuickLaunch(true);
 +
 +
delete this.launchRequest;
 +
 +
this.removeLaunchFeedback();
 +
},
 
</source></blockquote>
 
</source></blockquote>
* Insert a new listener in between the existing two so that it now looks like this:
+
* Add the following lines at the bottom of the onDeactivate method so that is now looks like this:
<blockquote><source lang="javascript">
 
setup: function() {
 
 
Mojo.listen(this.controller.document, Mojo.Event.deactivate, this.onDeactivate.bindAsEventListener(this));
 
Mojo.listen(this.controller.document, Mojo.Event.activate, this.onActivate.bindAsEventListener(this));
 
Mojo.listen(this.controller.window, 'resize', this.onResize.bindAsEventListener(this));
 
</source></blockquote>
 
* Locate the beginning of the onDeactivate method around line 170 (onDeactivate begins at line 171 in webOS 1.3.1):
 
 
<blockquote><source lang="javascript">
 
<blockquote><source lang="javascript">
 
/* clean and hide global search */
 
/* clean and hide global search */
 
onDeactivate: function(event) {
 
onDeactivate: function(event) {
</source></blockquote>
+
* Add the following lines before onDeactivate so that is now looks like this:
+
this.globalSearchAssistant.deactivate();
<blockquote><source lang="javascript">
+
/* set launcher page to override last used page */
+
this.reorderController.cancel();
onActivate: function(event) {
+
 +
if (this.appDialog) {
 +
this.appDialog.mojo.close();
 +
}
 +
 +
SystemManagerService.showQuickLaunch(true);
 +
 +
delete this.launchRequest;
 +
 +
this.removeLaunchFeedback();
 +
 
 
/**
 
/**
 
* Calculate middle page. For an even number of pages,
 
* Calculate middle page. For an even number of pages,
Line 48: Line 63:
 
var middlePage = (numPages % 2) ? (numPages - 1) / 2: numPages / 2 - 1;
 
var middlePage = (numPages % 2) ? (numPages - 1) / 2: numPages / 2 - 1;
 
 
// set launcher to middle page
+
/* Reset launcher to middle page */
 
$('launcher_root').mojo.setSnapIndex(middlePage, false);
 
$('launcher_root').mojo.setSnapIndex(middlePage, false);
 
 
/**  
+
/* Jump scroll position back to top for all pages */
* If Bsiegel's 'Reset Scroll Position' patch is installed
+
for (var i=0; i<numPages; i++) {
* then this does what it says on the tin for the middle page.
+
var scroller = this.getPageScroller(i);
 +
if (scroller && scroller.mojo) { scroller.mojo.revealTop(); }
 +
}
 +
},
 +
</source></blockquote>
 +
* Locate the buildPages method that begins around line 510:
 +
<blockquote><source lang="javascript">
 +
/* build out the pages for all applications */
 +
buildPages: function() {
 +
 +
this.globalSearchAssistant.enable(false);
 +
 +
this.deleteAllPages();
 +
 +
var location = {page: 0, position: 0};
 +
for (var i=0, numPages=this.pagesModel.getNumPages(); i<numPages; i++) {
 +
// create a new page
 +
this.insertPage(i);
 +
 +
// insert all the applications for this page into the page container
 +
var page = this.pagesModel.getPage(i);
 +
location.page = i;
 +
for (var j=0; j<page.length; j++) {
 +
location.position = j;
 +
this.insertApp(location, this.pagesModel.getAppInfo(page[j]));
 +
}
 +
}
 +
 +
this.globalSearchAssistant.enable(true);
 +
},
 +
</source></blockquote>
 +
* Add the following lines to the bottom of the buildPages method so that it now looks like this:
 +
<blockquote><source lang="javascript">
 +
/* build out the pages for all applications */
 +
buildPages: function() {
 +
 +
this.globalSearchAssistant.enable(false);
 +
 +
this.deleteAllPages();
 +
 +
var location = {page: 0, position: 0};
 +
for (var i=0, numPages=this.pagesModel.getNumPages(); i<numPages; i++) {
 +
// create a new page
 +
this.insertPage(i);
 +
 +
// insert all the applications for this page into the page container
 +
var page = this.pagesModel.getPage(i);
 +
location.page = i;
 +
for (var j=0; j<page.length; j++) {
 +
location.position = j;
 +
this.insertApp(location, this.pagesModel.getAppInfo(page[j]));
 +
}
 +
}
 +
 +
this.globalSearchAssistant.enable(true);
 +
 +
/**
 +
* Calculate middle page. For an even number of pages,
 +
* this will be the lower side of the mid-point.
 
*/
 
*/
event.value = middlePage; /* Fudge this because onPageChange expects a
+
var middlePage = (numPages % 2) ? (numPages - 1) / 2: numPages / 2 - 1;
* mojo-property-change event but it's actually
+
* getting mojo-event-deactivate.
+
/* Set launcher to middle page */
*/
+
$('launcher_root').mojo.setSnapIndex(middlePage, false);
this.onPageChange(event);
 
 
},
 
},
 
/* clean and hide global search */
 
onDeactivate: function(event) {
 
 
</source></blockquote>
 
</source></blockquote>
 
* Save the file and quit vi.
 
* Save the file and quit vi.
Line 92: Line 161:
  
 
<source lang="diff">
 
<source lang="diff">
--- /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js.webosinternals.orig Sat Nov 28 01:54:57 2009
+
--- /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 Mon Nov 30 03:14:42 2009
+
+++ /usr/lib/luna/system/luna-applauncher/app/controllers/launcher-assistant.js Thu Dec  3 19:42:03 2009
@@ -67,6 +67,7 @@
+
@@ -183,6 +183,22 @@
setup: function() {
+
  delete this.launchRequest;
 
  Mojo.listen(this.controller.document, Mojo.Event.deactivate, this.onDeactivate.bindAsEventListener(this));
 
+ Mojo.listen(this.controller.document, Mojo.Event.activate, this.onActivate.bindAsEventListener(this));
 
Mojo.listen(this.controller.window, 'resize', this.onResize.bindAsEventListener(this));
 
 
 
 
 
  this.pagesModel = new LauncherPages({
+
  this.removeLaunchFeedback();
@@ -167,6 +168,29 @@
+
+
this.updatePageIndicators();
 
},
 
 
+ /* set launcher page to override last used page */
 
+ onActivate: function(event) {
 
 
+ /**
 
+ /**
 
+ * Calculate middle page. For an even number of pages,
 
+ * Calculate middle page. For an even number of pages,
Line 115: Line 175:
 
+ var middlePage = (numPages % 2) ? (numPages - 1) / 2: numPages / 2 - 1;
 
+ var middlePage = (numPages % 2) ? (numPages - 1) / 2: numPages / 2 - 1;
 
+
 
+
+ // set launcher to middle page
+
+ /* Reset launcher to middle page */
 
+ $('launcher_root').mojo.setSnapIndex(middlePage, false);
 
+ $('launcher_root').mojo.setSnapIndex(middlePage, false);
 
+
 
+
+ /**  
+
+ /* Jump scroll position back to top for all pages */
+ * If Bsiegel's 'Reset Scroll Position' patch is installed
+
+ for (var i=0; i<numPages; i++) {
+ * then this does what it says on the tin for the middle page.
+
+ var scroller = this.getPageScroller(i);
 +
+ if (scroller && scroller.mojo) { scroller.mojo.revealTop(); }
 +
+ }
 +
},
 +
 +
onResize: function(event) {
 +
@@ -529,6 +545,15 @@
 +
}
 +
 +
this.globalSearchAssistant.enable(true);
 +
+
 +
+ /**
 +
+ * Calculate middle page. For an even number of pages,
 +
+ * this will be the lower side of the mid-point.
 
+ */
 
+ */
+ event.value = middlePage; /* Fudge this because onPageChange expects a
+
+ var middlePage = (numPages % 2) ? (numPages - 1) / 2: numPages / 2 - 1;
+ * mojo-property-change event but it's actually
+
+
+ * getting mojo-event-deactivate.
+
+ /* Set launcher to middle page */
+ */
+
+ $('launcher_root').mojo.setSnapIndex(middlePage, false);
+ this.onPageChange(event);
+
},
+ },
 
+
 
/* clean and hide global search */
 
onDeactivate: function(event) {
 
 
 
 
 
 +
/* re-acquires the set of page elements the scroller needs to snap */
  
 
</source>
 
</source>

Revision as of 14:42, 5 December 2009


Introduction

By default, the Launcher maintains the last page opened when you return to it. If you most frequently use apps on a certain page of the Launcher, you have to swipe back to that page if the last app you launched was on another page. This patch resets the Launcher to the middle page every time it opens. This works best if you have an odd number of pages (like the default 3), then you have the same number of pages to the left, and to the right, thus minimizing the number of swipes required to get to the first or last page. It also resets the scroll position of all pages, so that when you re-open the Launcher, all pages will be scrolled to the top (previously it only did this if the Reset Scroll Position patch was also installed, I abandoned that idea. Apologies if anyone really wants the reset page behaviour without the reset scroll feature - check out the page history for older versions or adjust the patch accordingly).

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 beginning of the onDeactivate method around line 170:

<source lang="javascript">

/* clean and hide global search */ onDeactivate: function(event) {

this.globalSearchAssistant.deactivate();

this.reorderController.cancel();

if (this.appDialog) { this.appDialog.mojo.close(); }

SystemManagerService.showQuickLaunch(true);

delete this.launchRequest;

this.removeLaunchFeedback(); },

</source>

  • Add the following lines at the bottom of the onDeactivate method so that is now looks like this:

<source lang="javascript">

/* clean and hide global search */ onDeactivate: function(event) {

this.globalSearchAssistant.deactivate();

this.reorderController.cancel();

if (this.appDialog) { this.appDialog.mojo.close(); }

SystemManagerService.showQuickLaunch(true);

delete this.launchRequest;

this.removeLaunchFeedback();

/** * Calculate middle page. For an even number of pages, * this will be the lower side of the mid-point. */ var numPages=this.pagesModel.getNumPages(); var middlePage = (numPages % 2) ? (numPages - 1) / 2: numPages / 2 - 1;

/* Reset launcher to middle page */ $('launcher_root').mojo.setSnapIndex(middlePage, false);

/* Jump scroll position back to top for all pages */ for (var i=0; i<numPages; i++) { var scroller = this.getPageScroller(i); if (scroller && scroller.mojo) { scroller.mojo.revealTop(); } } },

</source>

  • Locate the buildPages method that begins around line 510:

<source lang="javascript">

/* build out the pages for all applications */ buildPages: function() {

this.globalSearchAssistant.enable(false);

this.deleteAllPages();

var location = {page: 0, position: 0}; for (var i=0, numPages=this.pagesModel.getNumPages(); i<numPages; i++) { // create a new page this.insertPage(i);

// insert all the applications for this page into the page container var page = this.pagesModel.getPage(i); location.page = i; for (var j=0; j<page.length; j++) { location.position = j; this.insertApp(location, this.pagesModel.getAppInfo(page[j])); } }

this.globalSearchAssistant.enable(true); },

</source>

  • Add the following lines to the bottom of the buildPages method so that it now looks like this:

<source lang="javascript">

/* build out the pages for all applications */ buildPages: function() {

this.globalSearchAssistant.enable(false);

this.deleteAllPages();

var location = {page: 0, position: 0}; for (var i=0, numPages=this.pagesModel.getNumPages(); i<numPages; i++) { // create a new page this.insertPage(i);

// insert all the applications for this page into the page container var page = this.pagesModel.getPage(i); location.page = i; for (var j=0; j<page.length; j++) { location.position = j; this.insertApp(location, this.pagesModel.getAppInfo(page[j])); } }

this.globalSearchAssistant.enable(true);

/** * Calculate middle page. For an even number of pages, * this will be the lower side of the mid-point. */ var middlePage = (numPages % 2) ? (numPages - 1) / 2: numPages / 2 - 1;

/* Set launcher to middle page */ $('launcher_root').mojo.setSnapIndex(middlePage, false); },

</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

The patch is not in the webos-internals gitorious repository yet, but is has been submitted. 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-to-middle-page.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-to-midle-page.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 @@ -183,6 +183,22 @@

		delete this.launchRequest;
		
		this.removeLaunchFeedback();

+ + /** + * Calculate middle page. For an even number of pages, + * this will be the lower side of the mid-point. + */ + var numPages=this.pagesModel.getNumPages(); + var middlePage = (numPages % 2) ? (numPages - 1) / 2: numPages / 2 - 1; + + /* Reset launcher to middle page */ + $('launcher_root').mojo.setSnapIndex(middlePage, false); + + /* Jump scroll position back to top for all pages */ + for (var i=0; i<numPages; i++) { + var scroller = this.getPageScroller(i); + if (scroller && scroller.mojo) { scroller.mojo.revealTop(); } + }

	},
	
	onResize: function(event) {

@@ -529,6 +545,15 @@

		}
		
		this.globalSearchAssistant.enable(true);

+ + /** + * Calculate middle page. For an even number of pages, + * this will be the lower side of the mid-point. + */ + var middlePage = (numPages % 2) ? (numPages - 1) / 2: numPages / 2 - 1; + + /* Set launcher to middle page */ + $('launcher_root').mojo.setSnapIndex(middlePage, false);

	},
	
	/* re-acquires the set of page elements the scroller needs to snap */

</source>