mirror of
https://github.com/zadam/trilium.git
synced 2024-12-27 01:34:05 +08:00
74 lines
No EOL
1.5 KiB
JavaScript
74 lines
No EOL
1.5 KiB
JavaScript
"use strict";
|
|
|
|
function reloadApp() {
|
|
window.location.reload(true);
|
|
}
|
|
|
|
function showMessage(message) {
|
|
console.log(now(), "message: ", message);
|
|
|
|
$.notify({
|
|
// options
|
|
message: message
|
|
},{
|
|
// settings
|
|
type: 'success',
|
|
delay: 3000
|
|
});
|
|
}
|
|
|
|
function showError(message, delay = 10000) {
|
|
console.log(now(), "error: ", message);
|
|
|
|
$.notify({
|
|
// options
|
|
message: message
|
|
},{
|
|
// settings
|
|
type: 'danger',
|
|
delay: delay
|
|
});
|
|
}
|
|
|
|
function throwError(message) {
|
|
messaging.logError(message);
|
|
|
|
throw new Error(message);
|
|
}
|
|
|
|
function parseDate(str) {
|
|
try {
|
|
return new Date(Date.parse(str));
|
|
}
|
|
catch (e) {
|
|
throw new Error("Can't parse date from " + str + ": " + e.stack);
|
|
}
|
|
}
|
|
|
|
function padNum(num) {
|
|
return (num <= 9 ? "0" : "") + num;
|
|
}
|
|
|
|
function formatTime(date) {
|
|
return padNum(date.getHours()) + ":" + padNum(date.getMinutes());
|
|
}
|
|
|
|
function formatTimeWithSeconds(date) {
|
|
return padNum(date.getHours()) + ":" + padNum(date.getMinutes()) + ":" + padNum(date.getSeconds());
|
|
}
|
|
|
|
function formatDate(date) {
|
|
return padNum(date.getDate()) + ". " + padNum(date.getMonth() + 1) + ". " + date.getFullYear();
|
|
}
|
|
|
|
function formatDateTime(date) {
|
|
return formatDate(date) + " " + formatTime(date);
|
|
}
|
|
|
|
function now() {
|
|
return formatTimeWithSeconds(new Date());
|
|
}
|
|
|
|
function isElectron() {
|
|
return window && window.process && window.process.type;
|
|
} |