mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-20 23:36:21 +08:00
Remove separate activation phase from stores not inside plugins
This commit is contained in:
parent
f99c5175d3
commit
a15278261f
|
@ -8,11 +8,20 @@ const CACHE_SIZE = 100
|
|||
const contactCacheKeyIndex = []
|
||||
|
||||
class ParticipantProfileStore extends NylasStore {
|
||||
activate() {
|
||||
constructor() {
|
||||
super();
|
||||
this.cacheExpiry = 1000 * 60 * 60 * 24 // 1 day
|
||||
this.dataSource = new ClearbitDataSource()
|
||||
}
|
||||
|
||||
activate() {
|
||||
|
||||
}
|
||||
|
||||
deactivate() {
|
||||
// no op
|
||||
}
|
||||
|
||||
dataForContact(contact) {
|
||||
if (!contact) {
|
||||
return {}
|
||||
|
@ -79,10 +88,6 @@ class ParticipantProfileStore extends NylasStore {
|
|||
return t.persistModel(contact)
|
||||
})
|
||||
}
|
||||
|
||||
deactivate() {
|
||||
// no op
|
||||
}
|
||||
}
|
||||
const store = new ParticipantProfileStore()
|
||||
export default store
|
||||
|
||||
export default new ParticipantProfileStore()
|
||||
|
|
|
@ -20,11 +20,13 @@ class SystemTrayIconStore {
|
|||
|
||||
constructor() {
|
||||
this._windowBlurred = false;
|
||||
this._unsubscribers = [];
|
||||
}
|
||||
|
||||
activate() {
|
||||
this._updateIcon();
|
||||
setTimeout(() => {
|
||||
this._updateIcon();
|
||||
}, 2000);
|
||||
this._unsubscribers = [];
|
||||
this._unsubscribers.push(BadgeStore.listen(this._updateIcon));
|
||||
|
||||
window.addEventListener('browser-window-blur', this._onWindowBlur);
|
||||
|
@ -33,6 +35,10 @@ class SystemTrayIconStore {
|
|||
this._unsubscribers.push(() => window.removeEventListener('browser-window-focus', this._onWindowFocus))
|
||||
}
|
||||
|
||||
deactivate() {
|
||||
this._unsubscribers.forEach(unsub => unsub())
|
||||
}
|
||||
|
||||
_getIconImageData(isInboxZero, isWindowBlurred) {
|
||||
if (isInboxZero) {
|
||||
return {iconPath: INBOX_ZERO_ICON, isTemplateImg: true};
|
||||
|
@ -61,10 +67,6 @@ class SystemTrayIconStore {
|
|||
const {iconPath, isTemplateImg} = this._getIconImageData(isInboxZero, this._windowBlurred);
|
||||
ipcRenderer.send('update-system-tray', iconPath, unreadString, isTemplateImg);
|
||||
};
|
||||
|
||||
deactivate() {
|
||||
this._unsubscribers.forEach(unsub => unsub())
|
||||
}
|
||||
}
|
||||
|
||||
export default SystemTrayIconStore;
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import _ from 'underscore';
|
||||
import NylasStore from 'nylas-store';
|
||||
|
||||
import {
|
||||
FeatureUsageStore,
|
||||
SyncbackMetadataTask,
|
||||
|
@ -13,11 +15,13 @@ import SnoozeUtils from './snooze-utils'
|
|||
import {PLUGIN_ID, PLUGIN_NAME} from './snooze-constants';
|
||||
import SnoozeActions from './snooze-actions';
|
||||
|
||||
class SnoozeStore {
|
||||
class SnoozeStore extends NylasStore {
|
||||
|
||||
constructor(pluginId = PLUGIN_ID, pluginName = PLUGIN_NAME) {
|
||||
this.pluginId = pluginId
|
||||
this.pluginName = pluginName
|
||||
super();
|
||||
|
||||
this.pluginId = pluginId;
|
||||
this.pluginName = pluginName;
|
||||
this.accountIds = AccountStore.accounts().map(a => a.id)
|
||||
this.snoozeCategoriesPromise = SnoozeUtils.getSnoozeCategoriesByAccount(AccountStore.accounts())
|
||||
}
|
||||
|
@ -26,7 +30,11 @@ class SnoozeStore {
|
|||
this.unsubscribers = [
|
||||
AccountStore.listen(this.onAccountsChanged),
|
||||
SnoozeActions.snoozeThreads.listen(this.onSnoozeThreads),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
deactivate() {
|
||||
this.unsubscribers.forEach(unsub => unsub())
|
||||
}
|
||||
|
||||
recordSnoozeEvent(threads, snoozeDate, label) {
|
||||
|
@ -44,8 +52,6 @@ class SnoozeStore {
|
|||
}
|
||||
|
||||
groupUpdatedThreads = (threads, snoozeCategoriesByAccount) => {
|
||||
const getSnoozeCategory = (accId) => snoozeCategoriesByAccount[accId]
|
||||
const {getInboxCategory} = CategoryStore
|
||||
const threadsByAccountId = {}
|
||||
|
||||
threads.forEach((thread) => {
|
||||
|
@ -53,8 +59,8 @@ class SnoozeStore {
|
|||
if (!threadsByAccountId[accId]) {
|
||||
threadsByAccountId[accId] = {
|
||||
threads: [thread],
|
||||
snoozeCategoryId: getSnoozeCategory(accId).id,
|
||||
returnCategoryId: getInboxCategory(accId).id,
|
||||
snoozeCategoryId: () => snoozeCategoriesByAccount[accId].id,
|
||||
returnCategoryId: () => CategoryStore.getInboxCategory(accId).id,
|
||||
}
|
||||
} else {
|
||||
threadsByAccountId[accId].threads.push(thread);
|
||||
|
@ -121,10 +127,6 @@ class SnoozeStore {
|
|||
return
|
||||
});
|
||||
};
|
||||
|
||||
deactivate() {
|
||||
this.unsubscribers.forEach(unsub => unsub())
|
||||
}
|
||||
}
|
||||
|
||||
export default SnoozeStore;
|
||||
|
|
|
@ -4,9 +4,13 @@ import {Actions} from 'nylas-exports'
|
|||
|
||||
class UndoSendStore extends NylasStore {
|
||||
|
||||
activate() {
|
||||
constructor() {
|
||||
super();
|
||||
this._showUndoSend = false
|
||||
this._sendActionTaskId = null
|
||||
}
|
||||
|
||||
activate() {
|
||||
this._unlisteners = [
|
||||
Actions.willPerformSendAction.listen(this._onWillPerformSendAction),
|
||||
Actions.didPerformSendAction.listen(this._onDidPerformSendAction),
|
||||
|
@ -14,6 +18,10 @@ class UndoSendStore extends NylasStore {
|
|||
]
|
||||
}
|
||||
|
||||
deactivate() {
|
||||
this._unlisteners.forEach((unsub) => unsub())
|
||||
}
|
||||
|
||||
shouldShowUndoSend() {
|
||||
return this._showUndoSend
|
||||
}
|
||||
|
@ -39,10 +47,6 @@ class UndoSendStore extends NylasStore {
|
|||
this._sendActionTaskId = null
|
||||
this.trigger()
|
||||
}
|
||||
|
||||
deactivate() {
|
||||
this._unlisteners.forEach((unsub) => unsub())
|
||||
}
|
||||
}
|
||||
|
||||
export default new UndoSendStore()
|
||||
|
|
|
@ -29,9 +29,7 @@ class FolderSyncProgressStore extends NylasStore {
|
|||
super()
|
||||
this._statesByAccount = {}
|
||||
this._triggerDebounced = _.debounce(this.trigger, 100)
|
||||
}
|
||||
|
||||
activate() {
|
||||
this.listenTo(AccountStore, () => this._onRefresh())
|
||||
this.listenTo(CategoryStore, () => this._onRefresh())
|
||||
this._onRefresh()
|
||||
|
|
|
@ -15,13 +15,14 @@ class IdentityStore extends NylasStore {
|
|||
constructor() {
|
||||
super();
|
||||
this._identity = null;
|
||||
}
|
||||
|
||||
async activate() {
|
||||
if (NylasEnv.isEmptyWindow()) {
|
||||
/*
|
||||
Hot windows don't receive any action-bridge-messages, which include DB updates.
|
||||
Since the hot window loads first, it may have a stale verison of the Identity.
|
||||
*/
|
||||
NylasEnv.onWindowPropsReceived(() => {
|
||||
this.deactivate();
|
||||
this.activate();
|
||||
this._onIdentityChanged();
|
||||
})
|
||||
return
|
||||
}
|
||||
|
@ -56,16 +57,8 @@ class IdentityStore extends NylasStore {
|
|||
|
||||
_fetchAndPollRemoteIdentity() {
|
||||
if (!NylasEnv.isMainWindow()) return;
|
||||
/**
|
||||
* We only need to re-fetch the identity to synchronize ourselves
|
||||
* with any changes a user did on a separate computer. Any updates
|
||||
* they do on their primary computer will be optimistically updated.
|
||||
* We also update from the server's version every
|
||||
* `SendFeatureUsageEventTask`
|
||||
*/
|
||||
setInterval(this.fetchIdentity.bind(this), 1000 * 60 * 10); // 10 minutes
|
||||
// Don't await for this!
|
||||
this.fetchIdentity();
|
||||
setTimeout(() => { this.fetchIdentity(); }, 1000);
|
||||
setInterval(() => { this.fetchIdentity(); }, 1000 * 60 * 10); // 10 minutes
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,23 +6,9 @@ const DefaultSignatureText = "Sent from <a href=\"https://nylas.com?ref=n1\">Nyl
|
|||
|
||||
class SignatureStore extends NylasStore {
|
||||
|
||||
activate() {
|
||||
this.unsubscribers = [
|
||||
Actions.addSignature.listen(this._onAddSignature),
|
||||
Actions.removeSignature.listen(this._onRemoveSignature),
|
||||
Actions.updateSignature.listen(this._onEditSignature),
|
||||
Actions.selectSignature.listen(this._onSelectSignature),
|
||||
Actions.toggleAccount.listen(this._onToggleAccount),
|
||||
];
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
NylasEnv.config.onDidChange(`nylas.signatures`, () => {
|
||||
this.signatures = NylasEnv.config.get(`nylas.signatures`)
|
||||
this.trigger()
|
||||
});
|
||||
NylasEnv.config.onDidChange(`nylas.defaultSignatures`, () => {
|
||||
this.defaultSignatures = NylasEnv.config.get(`nylas.defaultSignatures`)
|
||||
this.trigger()
|
||||
});
|
||||
this.signatures = NylasEnv.config.get(`nylas.signatures`) || {}
|
||||
this.defaultSignatures = NylasEnv.config.get(`nylas.defaultSignatures`) || {}
|
||||
|
||||
|
@ -44,8 +30,25 @@ class SignatureStore extends NylasStore {
|
|||
}
|
||||
|
||||
this.selectedSignatureId = this._setSelectedSignatureId()
|
||||
}
|
||||
|
||||
this.trigger()
|
||||
activate() {
|
||||
this.unsubscribers = [
|
||||
Actions.addSignature.listen(this._onAddSignature),
|
||||
Actions.removeSignature.listen(this._onRemoveSignature),
|
||||
Actions.updateSignature.listen(this._onEditSignature),
|
||||
Actions.selectSignature.listen(this._onSelectSignature),
|
||||
Actions.toggleAccount.listen(this._onToggleAccount),
|
||||
];
|
||||
|
||||
NylasEnv.config.onDidChange(`nylas.signatures`, () => {
|
||||
this.signatures = NylasEnv.config.get(`nylas.signatures`)
|
||||
this.trigger()
|
||||
});
|
||||
NylasEnv.config.onDidChange(`nylas.defaultSignatures`, () => {
|
||||
this.defaultSignatures = NylasEnv.config.get(`nylas.defaultSignatures`)
|
||||
this.trigger()
|
||||
});
|
||||
}
|
||||
|
||||
deactivate() {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* eslint global-require: 0 */
|
||||
/* eslint import/no-dynamic-require: 0 */
|
||||
import StoreRegistry from '../registries/store-registry'
|
||||
import DatabaseObjectRegistry from '../registries/database-object-registry'
|
||||
|
||||
// This module exports an empty object, with a ton of defined properties that
|
||||
|
@ -32,9 +31,10 @@ const lazyLoad = (prop, path) => {
|
|||
lazyLoadWithGetter(prop, () => resolveExport(require(`../${path}`)));
|
||||
};
|
||||
|
||||
const lazyLoadAndRegisterStore = (klassName, path) => {
|
||||
lazyLoad(klassName, `flux/stores/${path}`);
|
||||
StoreRegistry.register(klassName, () => exports[klassName]);
|
||||
const _resolveNow = [];
|
||||
const load = (klassName, path) => {
|
||||
lazyLoad(klassName, path);
|
||||
_resolveNow.push(klassName);
|
||||
}
|
||||
|
||||
const lazyLoadAndRegisterModel = (klassName, path) => {
|
||||
|
@ -113,34 +113,34 @@ lazyLoadAndRegisterTask(`SendFeatureUsageEventTask`, 'send-feature-usage-event-t
|
|||
// These need to be required immediately since some Stores are
|
||||
// listen-only and not explicitly required from anywhere. Stores
|
||||
// currently set themselves up on require.
|
||||
lazyLoadAndRegisterStore(`TaskQueue`, 'task-queue');
|
||||
lazyLoadAndRegisterStore(`BadgeStore`, 'badge-store');
|
||||
lazyLoadAndRegisterStore(`DraftStore`, 'draft-store');
|
||||
lazyLoadAndRegisterStore(`ModalStore`, 'modal-store');
|
||||
lazyLoadAndRegisterStore(`OutboxStore`, 'outbox-store');
|
||||
lazyLoadAndRegisterStore(`PopoverStore`, 'popover-store');
|
||||
lazyLoadAndRegisterStore(`AccountStore`, 'account-store');
|
||||
lazyLoadAndRegisterStore(`SignatureStore`, 'signature-store');
|
||||
lazyLoadAndRegisterStore(`MessageStore`, 'message-store');
|
||||
lazyLoadAndRegisterStore(`ContactStore`, 'contact-store');
|
||||
lazyLoadAndRegisterStore(`IdentityStore`, 'identity-store');
|
||||
lazyLoadAndRegisterStore(`CategoryStore`, 'category-store');
|
||||
lazyLoadAndRegisterStore(`UndoRedoStore`, 'undo-redo-store');
|
||||
lazyLoadAndRegisterStore(`WorkspaceStore`, 'workspace-store');
|
||||
lazyLoadAndRegisterStore(`MailRulesStore`, 'mail-rules-store');
|
||||
lazyLoadAndRegisterStore(`SendActionsStore`, 'send-actions-store');
|
||||
lazyLoadAndRegisterStore(`FeatureUsageStore`, 'feature-usage-store');
|
||||
lazyLoadAndRegisterStore(`ThreadCountsStore`, 'thread-counts-store');
|
||||
lazyLoadAndRegisterStore(`AttachmentStore`, 'attachment-store');
|
||||
lazyLoadAndRegisterStore(`OnlineStatusStore`, 'online-status-store');
|
||||
lazyLoadAndRegisterStore(`UpdateChannelStore`, 'update-channel-store');
|
||||
lazyLoadAndRegisterStore(`PreferencesUIStore`, 'preferences-ui-store');
|
||||
lazyLoadAndRegisterStore(`FocusedContentStore`, 'focused-content-store');
|
||||
lazyLoadAndRegisterStore(`MessageBodyProcessor`, 'message-body-processor');
|
||||
lazyLoadAndRegisterStore(`FocusedContactsStore`, 'focused-contacts-store');
|
||||
lazyLoadAndRegisterStore(`FolderSyncProgressStore`, 'folder-sync-progress-store');
|
||||
lazyLoadAndRegisterStore(`FocusedPerspectiveStore`, 'focused-perspective-store');
|
||||
lazyLoadAndRegisterStore(`SearchableComponentStore`, 'searchable-component-store');
|
||||
load(`TaskQueue`, 'flux/stores/task-queue');
|
||||
load(`BadgeStore`, 'flux/stores/badge-store');
|
||||
load(`DraftStore`, 'flux/stores/draft-store');
|
||||
load(`ModalStore`, 'flux/stores/modal-store');
|
||||
load(`OutboxStore`, 'flux/stores/outbox-store');
|
||||
load(`PopoverStore`, 'flux/stores/popover-store');
|
||||
load(`AccountStore`, 'flux/stores/account-store');
|
||||
load(`SignatureStore`, 'flux/stores/signature-store');
|
||||
load(`MessageStore`, 'flux/stores/message-store');
|
||||
load(`ContactStore`, 'flux/stores/contact-store');
|
||||
load(`IdentityStore`, 'flux/stores/identity-store');
|
||||
load(`CategoryStore`, 'flux/stores/category-store');
|
||||
load(`UndoRedoStore`, 'flux/stores/undo-redo-store');
|
||||
load(`WorkspaceStore`, 'flux/stores/workspace-store');
|
||||
load(`MailRulesStore`, 'flux/stores/mail-rules-store');
|
||||
load(`SendActionsStore`, 'flux/stores/send-actions-store');
|
||||
load(`FeatureUsageStore`, 'flux/stores/feature-usage-store');
|
||||
load(`ThreadCountsStore`, 'flux/stores/thread-counts-store');
|
||||
load(`AttachmentStore`, 'flux/stores/attachment-store');
|
||||
load(`OnlineStatusStore`, 'flux/stores/online-status-store');
|
||||
load(`UpdateChannelStore`, 'flux/stores/update-channel-store');
|
||||
load(`PreferencesUIStore`, 'flux/stores/preferences-ui-store');
|
||||
load(`FocusedContentStore`, 'flux/stores/focused-content-store');
|
||||
load(`MessageBodyProcessor`, 'flux/stores/message-body-processor');
|
||||
load(`FocusedContactsStore`, 'flux/stores/focused-contacts-store');
|
||||
load(`FolderSyncProgressStore`, 'flux/stores/folder-sync-progress-store');
|
||||
load(`FocusedPerspectiveStore`, 'flux/stores/focused-perspective-store');
|
||||
load(`SearchableComponentStore`, 'flux/stores/searchable-component-store');
|
||||
lazyLoad(`CustomContenteditableComponents`, 'components/overlaid-components/custom-contenteditable-components');
|
||||
|
||||
lazyLoad(`ServiceRegistry`, `registries/service-registry`);
|
||||
|
@ -199,3 +199,11 @@ lazyLoad(`SystemStartService`, 'system-start-service');
|
|||
|
||||
// Testing
|
||||
lazyLoadWithGetter(`NylasTestUtils`, () => require('../../spec/nylas-test-utils'));
|
||||
|
||||
process.nextTick(() => {
|
||||
let c = 0;
|
||||
for (const key of _resolveNow) {
|
||||
c += exports[key] ? 1 : 0
|
||||
}
|
||||
return c;
|
||||
});
|
||||
|
|
|
@ -6,6 +6,7 @@ class BatteryStatusManager {
|
|||
this._callbacks = [];
|
||||
this._battery = null;
|
||||
this._lastChangeTime = Date.now();
|
||||
this.activate();
|
||||
}
|
||||
|
||||
async activate() {
|
||||
|
@ -46,6 +47,4 @@ class BatteryStatusManager {
|
|||
}
|
||||
}
|
||||
|
||||
const manager = new BatteryStatusManager();
|
||||
manager.activate();
|
||||
export default manager;
|
||||
export default new BatteryStatusManager();
|
||||
|
|
Loading…
Reference in a new issue