1
0
Fork 0
mirror of https://github.com/anyproto/anytype-ts.git synced 2025-06-08 05:57:02 +09:00
This commit is contained in:
Andrew Simachev 2023-12-13 17:25:20 +01:00
parent 0b1b6d6363
commit 065ccf0834
No known key found for this signature in database
GPG key ID: 49A163D0D14E6FD8
7 changed files with 47 additions and 41 deletions

View file

@ -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) => {

View file

@ -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;

View file

@ -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', {});
});
*/
};
};

View file

@ -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<I.PageComponent, State> {
state = {
@ -27,7 +25,7 @@ const Create = observer(class Create extends React.Component<I.PageComponent, St
render () {
const { isLoading, error } = this.state;
const rootId = ROOT_ID;
const rootId = '';
const childrenIds = blockStore.getChildrenIds(rootId, rootId);
const children = blockStore.getChildren(rootId, rootId);
@ -66,17 +64,6 @@ const Create = observer(class Create extends React.Component<I.PageComponent, St
};
load () {
this.setState({ isLoading: true });
UtilData.createsSubscriptions(() => {
C.ObjectOpen(ROOT_ID, '', commonStore.space, (message: any) => {
if (message.error.code) {
return;
};
this.setState({ isLoading: false });
});
});
};
getWrapperWidth () {

View file

@ -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', {}));
});
};

View file

@ -59,6 +59,9 @@ const Index = observer(class Index extends React.Component<I.PageComponent, Stat
};
init (serverPort: string, gatewayPort: string) {
extensionStore.serverPort = serverPort;
extensionStore.gatewayPort = gatewayPort;
dispatcher.init(`http://127.0.0.1:${serverPort}`);
commonStore.gatewaySet(`http://127.0.0.1:${gatewayPort}`);
};

View file

@ -2,7 +2,8 @@ class ExtensionStore {
public createdObject = null;
public challengeId = '';
public serverPort = '';
public gatewayPort = '';
};