Pull all setup in preload.js into signal.js. goal: webpackable

This commit is contained in:
Scott Nonnenberg 2018-05-04 18:57:11 -07:00
parent 30cb673405
commit 9d1847a7e5
3 changed files with 161 additions and 126 deletions

View file

@ -15,17 +15,9 @@ export { _ };
export { ConversationContext } from './ConversationContext';
export { BackboneWrapper } from '../components/utility/BackboneWrapper';
// Here we can make things inside Webpack available to Backbone views like preload.js.
import { Quote } from '../components/conversation/Quote';
import { EmbeddedContact } from '../components/conversation/EmbeddedContact';
import * as Contact from '../types/Contact';
import * as HTML from '../html';
import * as Attachment from '../../ts/types/Attachment';
import * as MIME from '../../ts/types/MIME';
import { SignalService } from '../../ts/protobuf';
// @ts-ignore
import * as Signal from '../../js/signal';
import { SignalService } from '../protobuf';
// TypeScript wants two things when you import:
// 1) a normal typescript file
@ -107,14 +99,15 @@ import localeMessages from '../../_locales/en/messages.json';
// @ts-ignore
import { setup } from '../../js/modules/i18n';
import * as Util from '../util';
import filesize from 'filesize';
const i18n = setup(locale, localeMessages);
export { theme, locale, i18n };
parent.filesize = filesize;
parent.i18n = i18n;
parent.React = React;
parent.ReactDOM = ReactDOM;
parent.moment = moment;
parent.moment.updateLocale(locale, {
@ -126,20 +119,26 @@ parent.moment.updateLocale(locale, {
});
parent.moment.locale(locale);
parent.React = React;
parent.ReactDOM = ReactDOM;
export { theme, locale, i18n };
parent.Signal.HTML = HTML;
parent.Signal.Types.MIME = MIME;
parent.Signal.Types.Attachment = Attachment;
parent.Signal.Types.Contact = Contact;
parent.Signal.Components = {
Quote,
EmbeddedContact,
// Used by signal.js to set up code that deals with message attachments/avatars
const Attachments = {
createAbsolutePathGetter: () => () => '/fake/path',
createDeleter: () => async () => undefined,
createReader: () => async () => new ArrayBuffer(10),
createWriterForExisting: () => async () => '/fake/path',
createWriterForNew: () => async () => ({
data: new ArrayBuffer(10),
path: '/fake/path',
}),
getPath: (path: string) => path,
};
parent.Signal.Util = Util;
parent.Signal = Signal.setup({
Attachments,
userDataPath: '/',
});
parent.SignalService = SignalService;
parent.filesize = filesize;
parent.ConversationController._initialFetchComplete = true;
parent.ConversationController._initialPromise = Promise.resolve();