2016-04-05 06:05:48 +08:00
|
|
|
import {
|
|
|
|
Actions,
|
|
|
|
ComponentRegistry,
|
|
|
|
ExtensionRegistry,
|
|
|
|
RegisterDraftForPluginTask,
|
|
|
|
} from 'nylas-exports';
|
2016-02-20 04:30:24 +08:00
|
|
|
import LinkTrackingButton from './link-tracking-button';
|
|
|
|
import LinkTrackingComposerExtension from './link-tracking-composer-extension';
|
2016-02-24 10:20:26 +08:00
|
|
|
import LinkTrackingMessageExtension from './link-tracking-message-extension';
|
2016-04-05 06:05:48 +08:00
|
|
|
import {PLUGIN_ID, PLUGIN_URL} from './link-tracking-constants'
|
2016-02-20 04:30:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
export function activate() {
|
2016-04-05 06:05:48 +08:00
|
|
|
ComponentRegistry.register(LinkTrackingButton,
|
|
|
|
{role: 'Composer:ActionButton'});
|
|
|
|
|
2016-02-20 04:30:24 +08:00
|
|
|
ExtensionRegistry.Composer.register(LinkTrackingComposerExtension);
|
2016-04-05 06:05:48 +08:00
|
|
|
|
2016-02-24 10:20:26 +08:00
|
|
|
ExtensionRegistry.MessageView.register(LinkTrackingMessageExtension);
|
2016-04-05 06:05:48 +08:00
|
|
|
|
|
|
|
const errorMessage = `There was a problem saving your link tracking \
|
|
|
|
settings. This message will not have link tracking.`
|
|
|
|
|
|
|
|
this._usub = Actions.sendDraftSuccess.listen(({message, draftClientId}) => {
|
|
|
|
if (!NylasEnv.isMainWindow()) return;
|
|
|
|
if (message.metadataForPluginId(PLUGIN_ID)) {
|
|
|
|
const task = new RegisterDraftForPluginTask({
|
|
|
|
errorMessage,
|
|
|
|
draftClientId,
|
|
|
|
messageId: message.id,
|
|
|
|
pluginServerUrl: `${PLUGIN_URL}/plugins/register-message`,
|
|
|
|
});
|
|
|
|
Actions.queueTask(task);
|
|
|
|
}
|
|
|
|
})
|
2016-02-20 04:30:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export function serialize() {}
|
|
|
|
|
|
|
|
export function deactivate() {
|
|
|
|
ComponentRegistry.unregister(LinkTrackingButton);
|
|
|
|
ExtensionRegistry.Composer.unregister(LinkTrackingComposerExtension);
|
2016-02-24 10:20:26 +08:00
|
|
|
ExtensionRegistry.MessageView.unregister(LinkTrackingMessageExtension);
|
2016-04-05 06:05:48 +08:00
|
|
|
this._usub()
|
2016-02-20 04:30:24 +08:00
|
|
|
}
|