diff --git a/dist/extension/js/background.js b/dist/extension/js/background.js index 12537fb5d8..7d74f20b34 100644 --- a/dist/extension/js/background.js +++ b/dist/extension/js/background.js @@ -1,6 +1,7 @@ (() => { let ports = []; + let isInitMenu = false; const native = chrome.runtime.connectNative('com.anytype.desktop'); @@ -47,44 +48,51 @@ }; chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { - getActiveTab((currentTab) => { - if (!currentTab) { - return; - }; - - if (currentTab && (tabId == currentTab.id) && (undefined !== changeInfo.url)) { - sendToTab(currentTab, { type: 'hide' }); + getActiveTab(tab => { + if (tab && (tabId == tab.id) && (undefined !== changeInfo.url)) { + sendToTab(tab, { type: 'hide' }); }; }); }); - - initMenu(); }); chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { + let res = {}; + + console.log('[Background]', msg); switch (msg.type) { case 'getPorts': { - console.log('PORTS', ports); - - sendResponse({ ports }); + res = { ports }; break; }; + + case 'init': { + initMenu(); + sendToActiveTab(msg); + break; + }; + }; + sendResponse(res); return true; }); initMenu = () => { + if (isInitMenu) { + return; + }; + chrome.contextMenus.create({ id: 'webclipper', title: 'Anytype Web Clipper', contexts: [ 'selection' ] }); - chrome.contextMenus.onClicked.addListener(() => { - sendToActiveTab({ type: 'clickMenu' }); - }); + chrome.contextMenus.onClicked.addListener(() => sendToActiveTab({ type: 'clickMenu' })); + + isInitMenu = true; }; getActiveTab = (callBack) => { diff --git a/dist/extension/js/foreground.js b/dist/extension/js/foreground.js index 1eef5b7ad0..3af06c891f 100644 --- a/dist/extension/js/foreground.js +++ b/dist/extension/js/foreground.js @@ -8,11 +8,11 @@ body.appendChild(iframe); }; - iframe.id = 'anytypeWebclipper-iframe'; + iframe.id = [ 'anytypeWebclipper', 'iframe', extensionId ].join('-'); iframe.src = chrome.runtime.getURL('iframe/index.html'); chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { - console.log('Foreground message', msg, sender); + console.log('[Foreground]', msg, sender); if (sender.id != extensionId) { return; diff --git a/extension/iframe.tsx b/extension/iframe.tsx index f83456e3fa..1580beb0e0 100644 --- a/extension/iframe.tsx +++ b/extension/iframe.tsx @@ -60,7 +60,6 @@ window.Anytype = { UtilCommon, dispatcher, Storage, - Animation, }, }; @@ -102,10 +101,7 @@ class Iframe extends React.Component { }; componentDidMount () { - console.log('isIframe', Util.isIframe()); - UtilRouter.init(history); - commonStore.configSet({ debug: { mw: true } }, false); /* @ts-ignore */ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { @@ -119,6 +115,7 @@ class Iframe extends React.Component { return true; }); + /* Util.sendMessage({ type: 'getPorts' }, (response) => { if (!response.ports || !response.ports.length) { return; @@ -130,6 +127,7 @@ class Iframe extends React.Component { UtilRouter.go('/create', {}); }); + */ }; }; diff --git a/extension/iframe/create.tsx b/extension/iframe/create.tsx index 33db807334..6e3a0815af 100644 --- a/extension/iframe/create.tsx +++ b/extension/iframe/create.tsx @@ -2,16 +2,14 @@ import * as React from 'react'; import $ from 'jquery'; import { observer } from 'mobx-react'; import { Button, Block, Loader } from 'Component'; -import { I, C, UtilData } from 'Lib'; -import { blockStore, commonStore } from 'Store'; +import { I } from 'Lib'; +import { blockStore } from 'Store'; interface State { isLoading: boolean; error: string; }; -const ROOT_ID = 'bafyreihwzu7hzccsbalfe4ttkd6dr3usp2qlc3hc4xiv6ytbpdp2dqj4d4'; - const Create = observer(class Create extends React.Component { state = { @@ -27,7 +25,7 @@ const Create = observer(class Create extends React.Component { - C.ObjectOpen(ROOT_ID, '', commonStore.space, (message: any) => { - if (message.error.code) { - return; - }; - - this.setState({ isLoading: false }); - }); - }); }; getWrapperWidth () { diff --git a/extension/lib/util.ts b/extension/lib/util.ts index 9fb77a0708..e553b5c6d7 100644 --- a/extension/lib/util.ts +++ b/extension/lib/util.ts @@ -1,5 +1,5 @@ -import { UtilData, UtilRouter, dispatcher } from 'Lib'; -import { authStore } from 'Store'; +import { UtilData, UtilRouter } from 'Lib'; +import { authStore, extensionStore } from 'Store'; import Extension from 'json/extension.json'; class Util { @@ -29,7 +29,7 @@ class Util { ); }; - sendMessage (msg: any, callBack: (response) => void){ + sendMessage (msg: any, callBack: (response) => void) { /* @ts-ignore */ chrome.runtime.sendMessage(msg, callBack); }; @@ -40,6 +40,8 @@ class Util { }; initWithKey (appKey: string, onError?: (error) => void) { + const { serverPort, gatewayPort } = extensionStore + authStore.appKeySet(appKey); UtilData.createSession((message: any) => { if (message.error.code) { @@ -49,6 +51,13 @@ class Util { return; }; + this.sendMessage({ + type: 'init', + appKey, + serverPort, + gatewayPort, + }, () => {}); + UtilData.createsSubscriptions(() => UtilRouter.go('/create', {})); }); }; diff --git a/extension/popup/index.tsx b/extension/popup/index.tsx index 891b9a9d6d..20951a49d3 100644 --- a/extension/popup/index.tsx +++ b/extension/popup/index.tsx @@ -59,6 +59,9 @@ const Index = observer(class Index extends React.Component