Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
Change launch method to allow cross-app launch. Needed for data transfer
Browse files Browse the repository at this point in the history
between different versions of Keyring on the same phone (beta, catalog
and homebrew).  
	* app/models/keyring.js: Move global Keyring object from stage-assistant
	to a clearer location.

    * app/assistants/app-assistant.js: The app assistant rises from the grave.

    * app/assistants/stage-assistant.js: Pull application-scope and startup
    code into app-assistant.  Move Keyring global to its own file.  Pull
    PasswordDialogAssisant out into its own file.
    
    * app/assistants/password-dialog-assistant.js: Given its own file for
    clarity.
    
    * sources.json: Add new assistants & model.
    
    * appinfo.json: Add nowindow: true for new startup behavior.  Change
    version to 0.4.0, since the next release won't be in the catalog.
    
	* app/views/help/help-scene.html: Adjust changelog.
  • Loading branch information
Dirk Bergstrom committed May 5, 2010
1 parent ef57e3a commit 379cfda
Show file tree
Hide file tree
Showing 8 changed files with 345 additions and 214 deletions.
24 changes: 24 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
2010-05-05 Dirk Bergstrom <[email protected]>

Change launch method to allow cross-app launch. Needed for data transfer
between different versions of Keyring on the same phone (beta, catalog
and homebrew).
* app/models/keyring.js: Move global Keyring object from stage-assistant
to a clearer location.

* app/assistants/app-assistant.js: The app assistant rises from the grave.

* app/assistants/stage-assistant.js: Pull application-scope and startup
code into app-assistant. Move Keyring global to its own file. Pull
PasswordDialogAssisant out into its own file.

* app/assistants/password-dialog-assistant.js: Given its own file for
clarity.

* sources.json: Add new assistants & model.

* appinfo.json: Add nowindow: true for new startup behavior. Change
version to 0.4.0, since the next release won't be in the catalog.

* app/views/help/help-scene.html: Adjust changelog.

2010-04-23 Dirk Bergstrom <[email protected]>

* app/assistants/stage-assistant.js (Keyring.log): Wrapper around
Expand Down
106 changes: 106 additions & 0 deletions app/assistants/app-assistant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* @author Dirk Bergstrom
*
* Keyring for webOS - Easy password management on your phone.
* Copyright (C) 2009-2010, Dirk Bergstrom, [email protected]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

function AppAssistant() {
}

AppAssistant.prototype.setup = function() {
this.ring = new Ring();
Keyring.version = Mojo.appInfo.version;
};

AppAssistant.prototype.handleLaunch = function(launchParams) {
Keyring.log("handleLaunch");
var mainStageController = this.controller.getStageController(Keyring.MainStageName);

if (launchParams) {
Mojo.Log.error("Keyring was passed launch params, but doesn't use them. params=%j",
launchParams);
}
/* Call to bring up the main UI. See if this is the initial launch or
* a re-launch. */
if (mainStageController) {
// Stage already exists, bring it to the front by focusing its window.
Keyring.log("Main Stage Exists");
mainStageController.popScenesTo("locked");
mainStageController.activate();
} else {
Keyring.log("Creating Main Stage");
this.controller.createStageWithCallback(
{name: Keyring.MainStageName, assistantName: "StageAssistant", lightweight: true},
this.pushOpeningScene.bind(this),
"card");
}
};

AppAssistant.prototype.pushOpeningScene = function(stageController) {
Keyring.log("pushOpeningScene");
/* FIXME this is a somewhat dirty way of making ring available to
* the stage assistant. */
stageController.ring = this.ring;
stageController.pushScene('locked', this.ring);
};

/**
* handleCommand - called to handle app menu selections
*/
AppAssistant.prototype.handleCommand = function(event) {
var stageController = this.controller.getActiveStageController();
var currentScene = stageController.activeScene();
if(event.type === Mojo.Event.command) {
switch(event.command) {
case "do-aboutKeyring":
this.ring.updateTimeout();
currentScene.showAlertDialog({
onChoose: function(value) {},
title: $L("Keyring — Easy password management"),
message: $L("Version #{version} Copyright 2009-2010, Dirk Bergstrom. Released under the GPLv3.").interpolate({version: Keyring.version}),
choices:[{label:$L("OK"), value:""}]
});
break;

case "do-keyRingPrefs":
Keyring.doIfPasswordValid(currentScene, this.ring,
stageController.pushScene.
bind(this.controller, "preferences", this.ring)
);
break;

case "do-keyRingActions":
Keyring.doIfPasswordValid(currentScene, this.ring,
stageController.pushScene.
bind(stageController, "actions", this.ring)
);
break;

case "do-keyRingCategories":
Keyring.doIfPasswordValid(currentScene, this.ring,
stageController.pushScene.
bind(stageController, "categories", this.ring)
);
break;

case "do-keyRingHelp":
this.ring.updateTimeout();
stageController.pushScene("help", this.ring);
break;
}
}
};
99 changes: 99 additions & 0 deletions app/assistants/password-dialog-assistant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* @author Dirk Bergstrom
*
* Keyring for webOS - Easy password management on your phone.
* Copyright (C) 2009-2010, Dirk Bergstrom, [email protected]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* The "Enter your password" dialog, used throughout the application.
*/
var PasswordDialogAssistant = Class.create ({
initialize: function(controller, ring, callback, noCancel) {
this.controller = controller;
this.ring = ring;
this.callbackOnSuccess = callback;
this.noCancel = noCancel ? true : false;
},
setup: function(widget) {
this.widget = widget;

this.controller.get("password-title").update($L("Enter Password to Unlock"));

this.controller.setupWidget(
"password",
{
hintText: $L("Password"),
autoFocus: true,
changeOnKeyPress: true,
limitResize: true,
autoReplace: false,
textCase: Mojo.Widget.steModeLowerCase,
enterSubmits: true,
requiresEnterKey: true
},
this.passwordModel = {value: ''});

this.controller.listen("password", Mojo.Event.propertyChange,
this.keyPressHandler.bind(this));

this.unlockButtonModel = {label: $L("Unlock"), disabled: false};
this.controller.setupWidget("unlockButton", {type: Mojo.Widget.defaultButton},
this.unlockButtonModel);
this.unlockHandler = this.unlock.bindAsEventListener(this);
this.controller.listen("unlockButton", Mojo.Event.tap,
this.unlockHandler);

if (! this.noCancel) {
this.cancelButtonModel = {label: $L("Cancel"), disabled: false};
this.controller.setupWidget("cancelButton", {type: Mojo.Widget.defaultButton},
this.cancelButtonModel);
this.controller.listen("cancelButton", Mojo.Event.tap,
this.widget.mojo.close);
}
},

keyPressHandler: function(event) {
if (Mojo.Char.isEnterKey(event.originalEvent.keyCode)) {
this.unlock();
}
},
unlock: function() {
Keyring.log("unlock");
if (this.ring.validatePassword(this.passwordModel.value)) {
Keyring.log("Password accepted");
this.widget.mojo.close();
this.callbackOnSuccess();
} else {
Keyring.log("Bad Password");
// TODO select random insult from the sudo list
// FIXME apply some decent styling to the error message
this.controller.get("errmsg").update($L("Invalid Password"));
this.controller.get("password").mojo.focus.delay(0.25);
}
},
//cleanup - remove listeners
cleanup: function() {
this.controller.stopListening("unlockButton", Mojo.Event.tap,
this.unlockHandler);
if (! this.noCancel) {
this.controller.stopListening("cancelButton", Mojo.Event.tap,
this.widget.mojo.close);
}
this.controller.stopListening("password", Mojo.Event.propertyChange,
this.keyPressHandler.bind(this));
}
});
Loading

0 comments on commit 379cfda

Please sign in to comment.