Skip to content

Commit

Permalink
Merge pull request #251 from #250
Browse files Browse the repository at this point in the history
feat: add protocol handler for mailto
  • Loading branch information
ThorstenSuckow committed Nov 14, 2022
2 parents 11c9640 + 801da10 commit 0e7e478
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 11 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"creator": "Thorsten Suckow-Homberg <thorsten@suckow-homberg.de>",
"summary": "JavaScript Sencha ExtJS Webmail client.",
"detailedDescription": "This package contains an email client to be used with the conjoon project.",
"version": "0.2.1",
"compatVersion": "0.2.1",
"version": "0.3.0",
"compatVersion": "0.3.0",
"format": "1",
"slicer": {
"js": [
Expand Down Expand Up @@ -73,7 +73,7 @@
"@coon-js/extjs-app-user": "^0.1.7",
"@coon-js/extjs-comp-navport": "^0.2.4",
"@coon-js/extjs-lib-comp": "^0.2.8",
"@coon-js/extjs-lib-core": "^0.8.1",
"@coon-js/extjs-lib-core": "^0.8.3",
"@l8js/l8": "^0.7.2"
},
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions resources/extjs-app-webmail.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
}
],
"controller": [
{
"xclass": "conjoon.cn_mail.app.plugin.MailtoProtocolHandlerPlugin"
},
{
"xclass": "conjoon.cn_mail.app.plugin.NewMessagesNotificationPlugin",
"args": [
Expand Down
51 changes: 51 additions & 0 deletions src/app/plugin/MailtoProtocolHandlerPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* coon.js
* extjs-app-webmail
* Copyright (C) 2022 Thorsten Suckow-Homberg https://github.com/conjoon/extjs-app-webmail
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

/**
* ControllerPlugin for registering mailto-links with extjs-app-webmail.
*
*/
Ext.define("conjoon.cn_mail.app.plugin.MailtoProtocolHandlerPlugin", {

extend: "coon.core.app.plugin.ControllerPlugin",

/**
* @inheritdoc
*/
run (controller) {
"use strict";

const origin = window.location.origin;

navigator.registerProtocolHandler(
"mailto",
origin + "/#cn_mail/message/compose/%s",
"mailto handler"
);

return true;
}

});
3 changes: 2 additions & 1 deletion tests/groups.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ export default [{
{
group: "plugin",
items: [
"src/app/plugin/NewMessagesNotificationPluginTest.js"
"src/app/plugin/NewMessagesNotificationPluginTest.js",
"src/app/plugin/MailtoProtocolHandlerPluginTest.js"
]
}
]
Expand Down
83 changes: 83 additions & 0 deletions tests/src/app/plugin/MailtoProtocolHandlerPluginTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* conjoon
* extjs-app-webmail
* Copyright (C) 2022 Thorsten Suckow-Homberg https://github.com/conjoon/extjs-app-webmail
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

StartTest(t => {

let plugin;


const create = (cfg) => {
let plugin = Ext.create("conjoon.cn_mail.app.plugin.MailtoProtocolHandlerPlugin", cfg || {});

return plugin;
};


t.beforeEach(() => {
plugin = create();


});

t.afterEach(() => {
if (plugin) {
plugin.destroy();
plugin = null;
}
});

// +-------------------------------------------
// | Tests
// +-------------------------------------------

t.it("constructor()", t => {
t.isInstanceOf(plugin, "coon.core.app.plugin.ControllerPlugin");
});


t.it("run()", t => {

const
ctrl = Ext.create("conjoon.cn_mail.app.PackageController");


let registerProtocolHandler = function (){};

navigator.registerProtocolHandler = registerProtocolHandler;

let registerSpy = t.spyOn(navigator, "registerProtocolHandler").and.callFake(() => {});

t.expect(plugin.run(ctrl)).toBe(true);

t.expect(registerSpy.calls.mostRecent().args).toEqual([
"mailto",
window.location.origin + "/#cn_mail/message/compose/%s",
"mailto handler"
]);

registerSpy.remove();
});

});

0 comments on commit 0e7e478

Please sign in to comment.