Skip to content

Commit

Permalink
MozAcitivity DeepLink
Browse files Browse the repository at this point in the history
  • Loading branch information
strukturart committed Nov 14, 2023
1 parent 818a7a7 commit c640e49
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 60 deletions.
21 changes: 12 additions & 9 deletions application/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { validate } from './assets/js/helper.js';
import { get_file } from './assets/js/helper.js';
import {
bottom_bar,
add_sync_alarm,
test_is_background_sync,
remove_sync_alarm,
} from './assets/js/helper.js';
Expand Down Expand Up @@ -672,7 +671,7 @@ export let sync_caldav_callback = function () {
load_caldav().then(() => {
//close app because is background sync
if (!status.visible) {
pushLocalNotification('greg', 'updated');
//pushLocalNotification('greg', 'updated');
window.close();
return false;
}
Expand Down Expand Up @@ -2123,6 +2122,9 @@ export let page_options = {
'data-action': 'delete-subscription',

tabindex: index + 8,
onfocus: function () {
bottom_bar("<img src='assets/image/delete.svg'>", '', '');
},
onblur: function () {
bottom_bar('', '', '');
},
Expand Down Expand Up @@ -2656,11 +2658,6 @@ var page_add_event = {
focused_element = 'event-title';
bottom_bar('', '', '');
},
onkeypress: (e) => {
if (e.key == 'SoftRight') {
get_contact(callback_get_contact);
}
},
}),
]
),
Expand Down Expand Up @@ -4665,8 +4662,6 @@ function shortpress_action(param) {
break;

case '7':
test();

break;

case '8':
Expand All @@ -4684,6 +4679,9 @@ function shortpress_action(param) {
sort_events();
return true;
}
if (m.route.get().startsWith('/page_add_event')) {
get_contact(callback_get_contact);
}

if (
document.activeElement.getAttribute('data-action') ==
Expand Down Expand Up @@ -4978,3 +4976,8 @@ let interval = () => {
}
}, checkMessagesInterval);
};

//MozAcitivty deepLink handler
navigator.mozSetMessageHandler('activity', (e) => {
console.log(e);
});
53 changes: 10 additions & 43 deletions application/assets/js/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@ export async function sort_array_last_mod() {
events.sort(compareDateObjects);
}

export const test = () => {
if ('b2g' in navigator) {
let activity = new WebActivity('pick', { type: 'image/jpeg' });
activity.start().then(
(rv) => {},
(err) => {
alert(err);
}
);
}
};

export let get_contact = (callback) => {
try {
var activity = new MozActivity({
Expand All @@ -76,7 +64,6 @@ export let get_contact = (callback) => {
var contact = this.result;
if (contact && contact.contact) {
var contactName = contact.contact.name[0];
console.log('Contact Name: ' + contactName);
callback(contactName); // Pass the contactName to the callback
}
};
Expand All @@ -92,40 +79,20 @@ export let get_contact = (callback) => {
});

activity.start().then(
(rv) => {},
(rv) => {
var contact = rv;
if (contact && contact.contact) {
var contactName = contact.contact.name[0];
callback(contactName);
}
},
(err) => {
alert(err);
}
);
}
};

export let notification = '';
let notify = function (param_title, param_text, param_silent) {
var options = {
body: param_text,
silent: param_silent,
requireInteraction: false,
//actions: [{ action: "test", title: "test" }],
};

// Let's check whether notification permissions have already been granted
if (Notification.permission === 'granted') {
// If it's okay let's create a notification
notification = new Notification(param_title, options);
}

// Otherwise, we need to ask the user for permission
if (Notification.permission !== 'denied') {
Notification.requestPermission().then(function (permission) {
// If the user accepts, let's create a notification
if (permission === 'granted') {
notification = new Notification(param_title, options);
}
});
}
};

//https://notifications.spec.whatwg.org/#dictdef-notificationaction

export let pushLocalNotification = function (title, body) {
Expand Down Expand Up @@ -485,7 +452,6 @@ function write_file(data, filename) {

request.onsuccess = function () {
var name = this.result;
//toaster('File "' + name + '" successfully wrote on the sdcard storage area', 2000);
};

// An error typically occur if a file with the same name already exist
Expand All @@ -494,6 +460,7 @@ function write_file(data, filename) {
};
}

//background sync
export let test_is_background_sync = () => {
try {
if (localStorage.getItem('background_sync') == 'No') return false;
Expand All @@ -502,8 +469,6 @@ export let test_is_background_sync = () => {

request.onsuccess = function () {
this.result.forEach(function (alarm) {
console.log('test' + alarm.data.note);

if (alarm.data.note == 'keep alive') restart_background_sync();
});
};
Expand Down Expand Up @@ -610,6 +575,8 @@ export let remove_sync_alarm = function () {
}
};

//alarm loop

export let restart_background_sync = () => {
var d = new Date();
d.setMinutes(d.getMinutes() + background_sync_interval);
Expand Down
32 changes: 25 additions & 7 deletions application/manifest.webapp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.2.571",
"version": "2.2.573",
"name": "greg",
"id": "greg",
"categories": ["utilities"],
Expand Down Expand Up @@ -28,15 +28,36 @@
}
},
"default_locale": "en-US",

"deeplinks": {
"regex": "^https?://.*\\.ics$",
"action": "open-deeplink"
},

"activities": {
"open-deeplink": {
"href": "./index.html",
"disposition": "window",
"filters": {
"type": "url",
"url": {
"required": true,
"pattern": "^https?:"
}
},
"returnValue": false
}
},

"messages": [
{
"alarm": "/index.html"
},

{
"notification": "/index.html"
},
{ "serviceworker-notification": "/index.html" },
{ "activity": "/index.html" }
{ "serviceworker-notification": "/index.html" }
],

"redirects": [
Expand All @@ -50,8 +71,6 @@
"script_url": "sw.js"
},



"permissions": {
"serviceworker": {
"description": "Needed for assocating service worker"
Expand Down Expand Up @@ -79,7 +98,6 @@
},
"alarms": {
"description": "Required to schedule alarms"
},
"worker-activity": {}
}
}
}
2 changes: 1 addition & 1 deletion application/manifest.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
],

"b2g_features": {
"version": "3.0.237",
"version": "3.0.241",
"id": "greg",
"subtitle": "easy to use calendar",
"core": true,
Expand Down

0 comments on commit c640e49

Please sign in to comment.