Show reminder to backup styles
This commit is contained in:
parent
5e8550a52c
commit
d0c2baabad
|
@ -92,6 +92,10 @@
|
||||||
"message": "Select a file or drag and drop to this page.",
|
"message": "Select a file or drag and drop to this page.",
|
||||||
"description": "Message for backup"
|
"description": "Message for backup"
|
||||||
},
|
},
|
||||||
|
"backupReminderMessage": {
|
||||||
|
"message": "It's about that time to backup (export) your styles!",
|
||||||
|
"description": "Tooltip shown to remind users to backup their styles"
|
||||||
|
},
|
||||||
"bckpInstStyles": {
|
"bckpInstStyles": {
|
||||||
"message": "Export styles"
|
"message": "Export styles"
|
||||||
},
|
},
|
||||||
|
|
|
@ -373,6 +373,7 @@
|
||||||
<details id="backup" data-pref="manage.backup.expanded">
|
<details id="backup" data-pref="manage.backup.expanded">
|
||||||
<summary><h2 id="backup-title" i18n-text="backupButtons"></h2></summary>
|
<summary><h2 id="backup-title" i18n-text="backupButtons"></h2></summary>
|
||||||
<span id="backup-message" i18n-text="backupMessage"></span>
|
<span id="backup-message" i18n-text="backupMessage"></span>
|
||||||
|
<span id="backup-reminder-tooltip" i18n-text="backupReminderMessage"></span>
|
||||||
<div id="backup-buttons">
|
<div id="backup-buttons">
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<button class="dropbtn">
|
<button class="dropbtn">
|
||||||
|
|
|
@ -11,6 +11,10 @@ onDOMready().then(() => {
|
||||||
$('#unfile-all-styles').onclick = () => {
|
$('#unfile-all-styles').onclick = () => {
|
||||||
importFromFile({fileTypeFilter: STYLUS_BACKUP_FILE_EXT});
|
importFromFile({fileTypeFilter: STYLUS_BACKUP_FILE_EXT});
|
||||||
};
|
};
|
||||||
|
$('#backup-reminder-tooltip').onclick = () => {
|
||||||
|
setLastBackup({ update: false });
|
||||||
|
};
|
||||||
|
isItTimeToBackup();
|
||||||
|
|
||||||
Object.assign(document.body, {
|
Object.assign(document.body, {
|
||||||
ondragover(event) {
|
ondragover(event) {
|
||||||
|
@ -51,6 +55,40 @@ onDOMready().then(() => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function showTimeToBackupTooltip() {
|
||||||
|
const wrap = $('#backup');
|
||||||
|
if (wrap) {
|
||||||
|
$('#backup').open = true;
|
||||||
|
wrap.classList.add('show-reminder');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setLastBackup({ update = true }) {
|
||||||
|
const wrap = $('#backup');
|
||||||
|
if (update) {
|
||||||
|
localStorage['stylus-last-backup'] = Date.now();
|
||||||
|
}
|
||||||
|
if (wrap) {
|
||||||
|
wrap.classList.remove('show-reminder');
|
||||||
|
}
|
||||||
|
if (!prefs.get('manage.backup.expanded')) {
|
||||||
|
$('#backup').removeAttribute('open');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isItTimeToBackup() {
|
||||||
|
// show message every 14 days
|
||||||
|
const timeSinceLastBackup = 14 * (24 * 60 * 60 * 1000);
|
||||||
|
const lastBackup = localStorage['stylus-last-backup'];
|
||||||
|
if (!lastBackup) {
|
||||||
|
// initial setting
|
||||||
|
return setLastBackup();
|
||||||
|
}
|
||||||
|
if (Date.now() > Number(lastBackup) + timeSinceLastBackup) {
|
||||||
|
showTimeToBackupTooltip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function importFromFile({fileTypeFilter, file} = {}) {
|
function importFromFile({fileTypeFilter, file} = {}) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
const fileInput = document.createElement('input');
|
const fileInput = document.createElement('input');
|
||||||
|
@ -92,6 +130,7 @@ function importFromFile({fileTypeFilter, file} = {}) {
|
||||||
})
|
})
|
||||||
).then(numStyles => {
|
).then(numStyles => {
|
||||||
document.body.style.cursor = '';
|
document.body.style.cursor = '';
|
||||||
|
setLastBackup();
|
||||||
resolve(numStyles);
|
resolve(numStyles);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -299,6 +338,7 @@ function exportToFile() {
|
||||||
document.documentElement.appendChild(
|
document.documentElement.appendChild(
|
||||||
$create('iframe', {
|
$create('iframe', {
|
||||||
onload() {
|
onload() {
|
||||||
|
setLastBackup();
|
||||||
const text = JSON.stringify(styles, null, '\t');
|
const text = JSON.stringify(styles, null, '\t');
|
||||||
const type = 'application/json';
|
const type = 'application/json';
|
||||||
this.onload = null;
|
this.onload = null;
|
||||||
|
|
|
@ -1046,6 +1046,15 @@ input[id^="manage.newUI"] {
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#backup.show-reminder[open] summary {
|
||||||
|
padding-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#backup.show-reminder #backup-message,
|
||||||
|
#backup:not(.show-reminder) #backup-reminder-tooltip {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
/* export/import buttons */
|
/* export/import buttons */
|
||||||
#backup-buttons .dropbtn {
|
#backup-buttons .dropbtn {
|
||||||
padding: 3px 7px;
|
padding: 3px 7px;
|
||||||
|
@ -1072,6 +1081,14 @@ input[id^="manage.newUI"] {
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#backup-reminder-tooltip {
|
||||||
|
display: block;
|
||||||
|
padding: 10px;
|
||||||
|
background: #cb4;
|
||||||
|
color: #000;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
#backup-buttons .dropdown-content a {
|
#backup-buttons .dropdown-content a {
|
||||||
color: black;
|
color: black;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user