Skip to content

Commit

Permalink
backup before updating
Browse files Browse the repository at this point in the history
  • Loading branch information
strukturart committed Feb 13, 2024
1 parent e93e1ea commit 21cb669
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 1 deletion.
25 changes: 24 additions & 1 deletion application/assets/js/ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import { bottom_bar } from './helper.js';
import { settings } from '../../app.js';
import { export_ical_versionChangment } from './eximport.js';
import localforage from 'localforage';

export let load_ads = function () {
var js = document.createElement('script');
Expand Down Expand Up @@ -83,14 +85,35 @@ export function manifest(a) {
if (navigator.mozApps) {
self = a.origin;
document.querySelector('#version kbd').innerText = a.manifest.version;

if (a.manifest.version < '2.2.627') {
alert('update');

localforage
.getItem('events')
.then((e) => {
export_ical_versionChangment('greg-backup.ics', e);
})
.catch((e) => {});
}
if (a.installOrigin == 'app://kaios-plus.kaiostech.com') {
settings.ads = true;
} else {
settings.ads = true;
settings.ads = false;
}
}
if ('b2g' in navigator) {
document.querySelector('#version kbd').innerText = a.version;
if (a.version < '3.0.650') {
alert('update');
localforage
.getItem('events')
.then((e) => {
export_ical_versionChangment('greg-backup.ics', e);
})
.catch((e) => {});
}

settings.ads = true;
}
}
118 changes: 118 additions & 0 deletions application/assets/js/eximport.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,124 @@ export let export_ical = function (filename, data, callback) {
}, 2000);
};

//export events

export let export_ical_versionChangment = function (filename, event_data) {
try {
var sdcard = navigator.getDeviceStorage('sdcard');

var request_del = sdcard.delete(filename);
request_del.onsuccess = function () {
console.log('file deleted');
};
} catch (e) {
// alert(e);
}
if ('b2g' in Navigator) {
try {
var sdcard = navigator.b2g.getDeviceStorage('sdcard');
var request_del = sdcard.delete(filename);
} catch (e) {}
}

setTimeout(function () {
let result = '';

result += 'BEGIN:VCALENDAR' + '\r\n';
result += 'VERSION:2.0' + '\r\n';
result += 'PRODID:GREG' + '\r\n';
result += 'METHOD:PUBLISHED' + '\r\n';
console.log(event_data);
event_data.forEach((e, i) => {
let index = -1;
for (let key in e) {
index++;

//clean data
if (e[key] == null || typeof e[key] == 'object') {
console.log(e.RRULE);

e.RRULE = '';
}

if (index == 0) result += 'BEGIN:VEVENT' + '\r\n';

if (
key != 'BEGIN' &&
key != 'END' &&
key != 'date' &&
key != 'time_start' &&
key != 'time_end' &&
key != 'dateStart' &&
key != 'dateEnd' &&
key != 'alarm' &&
key != 'isSubscription' &&
key != 'multidayevent' &&
key != 'alarmTrigger' &&
key != 'isCalDav' &&
key != 'id' &&
key != 'allDay' &&
key != 'isCaldav' &&
key != 'tzid' &&
key != 'rrule_json' &&
key != 'etag' &&
key != 'url' &&
key != 'id' &&
key != 'dateStartUnix' &&
key != 'dateEndUnix'
) {
result += `${key}:${e[key]}` + '\r\n';
}
if (index == Object.keys(e).length - 1) result += 'END:VEVENT' + '\r\n';
}
});

result += 'END:VCALENDAR' + '\r\n';

result = result.replace(/:;TZID/g, ';TZID');
result = result.replace(/RRULE:FREQ=null/g, 'RRULE:');
result = result.replace(/: undefined/g, 'RRULE:');

//remove empty lines
let regex = /^\s*$(?:\r\n?|\n)/gm;
result = result.replace(regex, '');

var file = new Blob([result], { type: 'text/calendar' });
try {
var sdcard = navigator.getDeviceStorage('sdcard');

var request = sdcard.addNamed(file, filename);
request.onsuccess = function () {
side_toaster("<img src='assets/image/E25C.svg'>", 2500);
};

request.onerror = function () {
toaster('Unable to write the file', 2000);
};
} catch (e) {
console.log(e);
}

//KaiOS 3.x
if ('b2g' in Navigator) {
try {
var sdcard = navigator.b2g.getDeviceStorage('sdcard');
var request = sdcard.addNamed(file, filename);

request.onsuccess = function () {
side_toaster("<img src='assets/image/E25C.svg'>", 2500);
};

request.onerror = function () {
toaster('Unable to write the file', 2000);
};
} catch (e) {
console.log(e);
}
}
}, 2000);
};

/////////////
///FETCH ICS
///////////
Expand Down

0 comments on commit 21cb669

Please sign in to comment.