Files
notesnook/packages/core/common.js

110 lines
3.4 KiB
JavaScript
Raw Normal View History

/*
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
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
2020-11-02 09:50:27 +05:00
import EventManager from "./utils/event-manager";
export const EV = new EventManager();
export async function checkIsUserPremium(type) {
2022-03-30 15:52:48 +05:00
// if (process.env.NODE_ENV === "test") return true;
2021-07-12 10:32:35 +05:00
const results = await EV.publishWithResult(EVENTS.userCheckStatus, type);
if (typeof results === "boolean") return results;
return results.some((r) => r.type === type && r.result === true);
}
2020-12-05 13:19:41 +05:00
export async function checkSyncStatus(type) {
const results = await EV.publishWithResult(EVENTS.syncCheckStatus, type);
if (typeof results === "boolean") return results;
else if (typeof results === "undefined") return true;
return results.some((r) => r.type === type && r.result === true);
}
export function sendAttachmentsProgressEvent(type, groupId, total, current) {
EV.publish(EVENTS.attachmentsLoading, {
type,
groupId,
total,
current: current === undefined ? total : current
});
}
2022-03-30 15:52:48 +05:00
export function sendSyncProgressEvent(EV, type, total, current) {
2022-02-08 15:09:39 +05:00
EV.publish(EVENTS.syncProgress, {
type,
total,
current: current === undefined ? total : current
2022-02-08 15:09:39 +05:00
});
}
export function sendMigrationProgressEvent(EV, collection, total, current) {
EV.publish(EVENTS.migrationProgress, {
collection,
total,
current: current === undefined ? total : current
});
}
export const CLIENT_ID = "notesnook";
2020-12-05 13:19:41 +05:00
export const CHECK_IDS = {
noteColor: "note:color",
noteTag: "note:tag",
noteExport: "note:export",
vaultAdd: "vault:add",
notebookAdd: "notebook:add",
backupEncrypt: "backup:encrypt"
2020-12-05 13:19:41 +05:00
};
export const SYNC_CHECK_IDS = {
autoSync: "autoSync",
sync: "sync"
};
export const EVENTS = {
userCheckStatus: "user:checkStatus",
userSubscriptionUpdated: "user:subscriptionUpdated",
userEmailConfirmed: "user:emailConfirmed",
userLoggedIn: "user:loggedIn",
userLoggedOut: "user:loggedOut",
userFetched: "user:fetched",
userSignedUp: "user:signedUp",
2021-05-25 16:19:58 +05:00
userSessionExpired: "user:sessionExpired",
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",
syncItemMerged: "sync:itemMerged",
syncAborted: "sync:aborted",
syncCheckStatus: "sync:checkStatus",
databaseUpdated: "db:updated",
databaseCollectionInitiated: "db:collectionInitiated",
appRefreshRequested: "app:refreshRequested",
migrationProgress: "migration:progress",
noteRemoved: "note:removed",
2021-08-31 12:11:46 +05:00
tokenRefreshed: "token:refreshed",
userUnauthorized: "user:unauthorized",
attachmentsLoading: "attachments:loading",
attachmentDeleted: "attachment:deleted",
mediaAttachmentDownloaded: "attachments:mediaDownloaded",
2021-12-29 09:56:19 +05:00
vaultLocked: "vault:locked",
systemTimeInvalid: "system:invalidTime"
};
2022-10-12 20:33:37 +05:00
export const CURRENT_DATABASE_VERSION = 5.8;