2022-08-31 06:33:37 +05:00
|
|
|
/*
|
|
|
|
|
This file is part of the Notesnook project (https://notesnook.com/)
|
|
|
|
|
|
2023-01-16 13:44:52 +05:00
|
|
|
Copyright (C) 2023 Streetwriters (Private) Limited
|
2022-08-31 06:33:37 +05:00
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2022-08-30 16:13:11 +05:00
|
|
|
|
2024-09-23 15:08:57 +05:00
|
|
|
import EventManager from "./utils/event-manager.js";
|
2020-11-02 09:50:27 +05:00
|
|
|
|
|
|
|
|
export const EV = new EventManager();
|
2020-11-11 15:43:09 +05:00
|
|
|
|
2023-08-29 20:42:45 +05:00
|
|
|
export const SYNC_CHECK_IDS = {
|
|
|
|
|
autoSync: "autoSync",
|
|
|
|
|
sync: "sync"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type SyncStatusEvent = keyof typeof SYNC_CHECK_IDS;
|
|
|
|
|
|
2023-08-21 13:32:06 +05:00
|
|
|
export async function checkSyncStatus(type: string) {
|
2023-08-29 20:42:45 +05:00
|
|
|
const results = await EV.publishWithResult<{ type: string; result: boolean }>(
|
|
|
|
|
EVENTS.syncCheckStatus,
|
|
|
|
|
type
|
|
|
|
|
);
|
2022-12-16 17:14:50 +05:00
|
|
|
if (typeof results === "boolean") return results;
|
|
|
|
|
else if (typeof results === "undefined") return true;
|
|
|
|
|
return results.some((r) => r.type === type && r.result === true);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-29 20:42:45 +05:00
|
|
|
export type SyncProgressEvent = {
|
|
|
|
|
type: "upload" | "download";
|
|
|
|
|
current: number;
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-21 13:32:06 +05:00
|
|
|
export function sendSyncProgressEvent(
|
|
|
|
|
EV: EventManager,
|
|
|
|
|
type: string,
|
|
|
|
|
current: number
|
|
|
|
|
) {
|
2022-02-08 15:09:39 +05:00
|
|
|
EV.publish(EVENTS.syncProgress, {
|
|
|
|
|
type,
|
2023-09-02 11:29:00 +05:00
|
|
|
current
|
2023-08-29 20:42:45 +05:00
|
|
|
} as SyncProgressEvent);
|
2022-02-08 15:09:39 +05:00
|
|
|
}
|
|
|
|
|
|
2023-08-21 13:32:06 +05:00
|
|
|
export function sendMigrationProgressEvent(
|
|
|
|
|
EV: EventManager,
|
|
|
|
|
collection: string,
|
|
|
|
|
total: number,
|
|
|
|
|
current?: number
|
|
|
|
|
) {
|
2022-10-17 22:43:26 +05:00
|
|
|
EV.publish(EVENTS.migrationProgress, {
|
|
|
|
|
collection,
|
|
|
|
|
total,
|
|
|
|
|
current: current === undefined ? total : current
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-24 11:13:41 +05:00
|
|
|
export const CLIENT_ID = "notesnook";
|
|
|
|
|
|
2021-01-23 10:48:21 +05:00
|
|
|
export const EVENTS = {
|
|
|
|
|
userSubscriptionUpdated: "user:subscriptionUpdated",
|
|
|
|
|
userEmailConfirmed: "user:emailConfirmed",
|
|
|
|
|
userLoggedIn: "user:loggedIn",
|
|
|
|
|
userLoggedOut: "user:loggedOut",
|
|
|
|
|
userFetched: "user:fetched",
|
2021-02-26 17:33:46 +05:00
|
|
|
userSignedUp: "user:signedUp",
|
2021-05-25 16:19:58 +05:00
|
|
|
userSessionExpired: "user:sessionExpired",
|
2021-01-23 10:48:21 +05:00
|
|
|
databaseSyncRequested: "db:syncRequested",
|
2022-02-08 15:09:39 +05:00
|
|
|
syncProgress: "sync:progress",
|
2022-03-30 15:52:48 +05:00
|
|
|
syncCompleted: "sync:completed",
|
2022-09-20 18:33:55 +05:00
|
|
|
syncItemMerged: "sync:itemMerged",
|
2023-01-13 14:34:29 +05:00
|
|
|
syncAborted: "sync:aborted",
|
2022-12-16 17:14:50 +05:00
|
|
|
syncCheckStatus: "sync:checkStatus",
|
2021-01-23 10:48:21 +05:00
|
|
|
databaseUpdated: "db:updated",
|
2021-12-15 15:21:32 +05:00
|
|
|
databaseCollectionInitiated: "db:collectionInitiated",
|
2021-01-23 10:48:21 +05:00
|
|
|
appRefreshRequested: "app:refreshRequested",
|
2022-10-17 22:43:26 +05:00
|
|
|
migrationProgress: "migration:progress",
|
2024-11-18 12:32:33 +05:00
|
|
|
migrationStarted: "migration:start",
|
|
|
|
|
migrationFinished: "migration:finished",
|
2021-01-23 10:48:21 +05:00
|
|
|
noteRemoved: "note:removed",
|
2021-08-31 12:11:46 +05:00
|
|
|
tokenRefreshed: "token:refreshed",
|
2022-01-07 13:58:06 +05:00
|
|
|
userUnauthorized: "user:unauthorized",
|
2023-09-20 19:44:04 +05:00
|
|
|
downloadCanceled: "file:downloadCanceled",
|
|
|
|
|
uploadCanceled: "file:uploadCanceled",
|
|
|
|
|
fileDownload: "file:download",
|
|
|
|
|
fileUpload: "file:upload",
|
2023-09-20 15:37:27 +05:00
|
|
|
fileDownloaded: "file:downloaded",
|
|
|
|
|
fileUploaded: "file:uploaded",
|
2021-09-29 09:53:50 +05:00
|
|
|
attachmentDeleted: "attachment:deleted",
|
2021-09-26 11:47:13 +05:00
|
|
|
mediaAttachmentDownloaded: "attachments:mediaDownloaded",
|
2021-12-29 09:56:19 +05:00
|
|
|
vaultLocked: "vault:locked",
|
2024-11-05 15:35:02 +05:00
|
|
|
vaultUnlocked: "vault:unlocked",
|
2022-08-31 06:33:37 +05:00
|
|
|
systemTimeInvalid: "system:invalidTime"
|
2021-01-23 10:48:21 +05:00
|
|
|
};
|
|
|
|
|
|
2024-09-13 15:39:09 +05:00
|
|
|
const separators = ["-", "/", "."];
|
2023-12-21 08:57:30 +05:00
|
|
|
const DD = "DD";
|
|
|
|
|
const MM = "MM";
|
|
|
|
|
const YYYY = "YYYY";
|
2023-06-01 20:56:02 +05:00
|
|
|
export const DATE_FORMATS = [
|
2024-09-13 15:39:09 +05:00
|
|
|
...[
|
|
|
|
|
[DD, MM, YYYY],
|
|
|
|
|
[MM, DD, YYYY],
|
|
|
|
|
[YYYY, MM, DD]
|
|
|
|
|
]
|
|
|
|
|
.map((item) => separators.map((sep) => item.join(sep)))
|
2023-06-08 11:57:10 +05:00
|
|
|
.flat(),
|
2023-06-01 20:56:02 +05:00
|
|
|
"MMM D, YYYY"
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export const TIME_FORMATS = ["12-hour", "24-hour"];
|
|
|
|
|
|
2024-02-28 14:04:14 +05:00
|
|
|
export const CURRENT_DATABASE_VERSION = 6.1;
|
2024-11-06 11:41:21 +05:00
|
|
|
|
|
|
|
|
export const FREE_NOTEBOOKS_LIMIT = 20;
|