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-08-17 22:00:56 +02:00
parent 8192aad903
commit 6a3af6d891
No known key found for this signature in database
GPG key ID: 49A163D0D14E6FD8
21 changed files with 132 additions and 45 deletions

BIN
dist/extension/img/icon32x32.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 785 B

View file

@ -1,3 +1,57 @@
const a = 1;
(() => {
console.log('This is worker script');
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
switch (msg.type) {
case 'initNative': {
initNative(sendResponse);
break;
};
};
return true;
});
const initNative = (callBack) => {
const client = chrome.runtime.connectNative('com.anytype.desktop');
client.onMessage.addListener((msg) => {
console.log('Received', msg);
if (msg.error) {
console.error(msg.error);
return;
};
switch (msg.type) {
case 'NMHGetOpenPorts': {
let port = '';
for (let pid in msg.response) {
port = msg.response[pid][1];
break;
};
callBack({ type: 'NMHGetOpenPorts', port });
break;
};
};
});
client.onDisconnect.addListener(() => {
console.log('Disconnected');
});
client.postMessage({ type: 'NMHGetOpenPorts' });
};
chrome.contextMenus.create({
id: 'workTime',
title: 'WorkTime',
contexts: [ 'selection' ]
});
chrome.contextMenus.onClicked.addListener((data) => {
console.log('Click');
});
})();

View file

@ -1 +0,0 @@
const a = 1;

View file

@ -12,7 +12,10 @@
"default_title": "Chrome Addon v3 Starter",
"default_popup": "popup/index.html"
},
"permissions": [],
"permissions": [
"contextMenus",
"nativeMessaging"
],
"host_permissions": [
"*://*/*"
],
@ -21,7 +24,7 @@
},
"content_scripts": [
{
"js": [ "js/foreground.js" ],
"js": [ "js/main.js" ],
"matches": [ "<all_urls>" ]
}
]

View file

@ -16,9 +16,9 @@ const path = require('path');
const util = require('../util.js');
const { fixPathForAsarUnpack, is } = require('electron-util');
const APP_NAME = 'com.anytype.anytype_desktop';
const APP_NAME = 'com.anytype.desktop';
const MANIFEST_FILENAME = `${APP_NAME}.json`;
const EXTENSION_ID = 'ahaggknnnohbcdmckanhelcmlfcopjoa';
const EXTENSION_ID = 'jkmhmgghdjjbafmkgjmplhemjjnkligf';
const USER_PATH = app.getPath('userData');
const EXE_PATH = app.getPath('exe');

View file

@ -3,6 +3,7 @@ import * as hs from 'history';
import { Router, Route, Switch } from 'react-router-dom';
import { Provider } from 'mobx-react';
import { configure } from 'mobx';
import { dispatcher, C } from 'Lib';
import { commonStore, authStore, blockStore, detailStore, dbStore, menuStore, popupStore } from 'Store';
import Index from './page/index';
@ -55,6 +56,22 @@ class App extends React.Component {
};
componentDidMount () {
commonStore.configSet({ debug: { mw: true } }, false);
// @ts-ignore: saying 'chrome' is not found
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
console.log(msg);
return true;
});
// @ts-ignore: saying 'chrome' is not found
chrome.runtime.sendMessage({ type: 'initNative' }, (response) => {
dispatcher.init(`http://127.0.0.1:${response.port}`);
C.AppGetVersion((message: any) => {
console.log(message);
});
});
};
componentDidUpdate () {

View file

@ -2,4 +2,13 @@ import * as React from 'react';
import * as ReactDOM from 'react-dom';
import App from './app';
ReactDOM.render(<App />, document.getElementById('anytypeWebclipperRoot'));
const body = document.querySelector('body');
const root = document.createElement('div');
root.id = 'anytypeWebclipperRoot';
if (body) {
body.appendChild(root);
};
ReactDOM.render(<App />, root);

View file

@ -177,7 +177,7 @@ func startApplication() (int, error) {
} else if platform == "darwin" {
appPath = filepath.Join(appPath, "MacOS", "Anytype")
} else if platform == "linux" {
appPath = filepath.Join(appPath, "anytype2")
appPath = filepath.Join(appPath, "anytype")
} else {
return 0, errors.New("unsupported platform")
}

View file

@ -262,8 +262,8 @@ enableLogging({
*/
Sentry.init({
release: window.Electron.version.app,
environment: window.Electron.isPackaged ? 'production' : 'development',
release: UtilCommon.getElectron().version.app,
environment: UtilCommon.getElectron().isPackaged ? 'production' : 'development',
dsn: Constant.sentry,
maxBreadcrumbs: 0,
beforeSend: (e: any) => {
@ -327,7 +327,7 @@ class App extends React.Component<object, State> {
<div id="root-loader" className="loaderWrapper">
<div className="inner">
<div className="logo anim from" />
<div className="version anim from">{window.Electron.version.app}</div>
<div className="version anim from">{UtilCommon.getElectron().version.app}</div>
</div>
</div>
) : ''}
@ -362,14 +362,14 @@ class App extends React.Component<object, State> {
init () {
UtilCommon.init(history);
dispatcher.init(window.Electron.getGlobal('serverAddress'));
dispatcher.init(UtilCommon.getElectron().getGlobal('serverAddress'));
keyboard.init();
this.registerIpcEvents();
Renderer.send('appOnLoad');
console.log('[Process] os version:', window.Electron.version.system, 'arch:', window.Electron.arch);
console.log('[App] version:', window.Electron.version.app, 'isPackaged', window.Electron.isPackaged);
console.log('[Process] os version:', UtilCommon.getElectron().version.system, 'arch:', UtilCommon.getElectron().arch);
console.log('[App] version:', UtilCommon.getElectron().version.app, 'isPackaged', UtilCommon.getElectron().isPackaged);
};
initStorage () {
@ -592,7 +592,7 @@ class App extends React.Component<object, State> {
popupStore.open('confirm', {
data: {
title: translate('popupConfirmUpdateDoneTitle'),
text: UtilCommon.sprintf(translate('popupConfirmUpdateDoneText'), window.Electron.version.app),
text: UtilCommon.sprintf(translate('popupConfirmUpdateDoneText'), UtilCommon.getElectron().version.app),
textConfirm: translate('popupConfirmUpdateDoneOk'),
canCancel: false,
},

View file

@ -183,7 +183,7 @@ const BlockPdf = observer(class BlockPdf extends React.Component<I.BlockComponen
const { content } = block;
const { hash } = content;
C.FileDownload(hash, window.Electron.tmpPath, (message: any) => {
C.FileDownload(hash, UtilCommon.getElectron().tmpPath, (message: any) => {
if (message.path) {
Renderer.send('pathOpen', message.path);
};

View file

@ -65,7 +65,7 @@ class MenuHelp extends React.Component<I.Menu> {
};
getItems () {
const btn = <Button className="c16" text={window.Electron.version.app} />;
const btn = <Button className="c16" text={UtilCommon.getElectron().version.app} />;
return [
{ id: 'whatsNew', document: 'whatsNew', caption: btn },

View file

@ -251,7 +251,7 @@ const PageMainMedia = observer(class PageMainMedia extends React.Component<I.Pag
const block = blocks.find(it => it.isFile());
const { content } = block;
C.FileDownload(content.hash, window.Electron.tmpPath, (message: any) => {
C.FileDownload(content.hash, UtilCommon.getElectron().tmpPath, (message: any) => {
if (message.path) {
Renderer.send('pathOpen', message.path);
};

View file

@ -110,7 +110,7 @@ const PopupSettingsPageAccount = observer(class PopupSettingsPageAccount extends
properties: [ 'openDirectory' ],
};
window.Electron.showOpenDialog(options).then((result: any) => {
UtilCommon.getElectron().showOpenDialog(options).then((result: any) => {
const files = result.filePaths;
if ((files == undefined) || !files.length) {
return;

View file

@ -110,7 +110,7 @@ const PopupSettingsPageDataManagement = observer(class PopupSettingsPageStorageI
properties: [ 'openDirectory' ],
};
window.Electron.showOpenDialog(options).then((result: any) => {
UtilCommon.getElectron().showOpenDialog(options).then((result: any) => {
const files = result.filePaths;
if ((files == undefined) || !files.length) {
return;

View file

@ -185,7 +185,7 @@ class Action {
];
};
window.Electron.showOpenDialog(options).then(({ filePaths }) => {
UtilCommon.getElectron().showOpenDialog(options).then(({ filePaths }) => {
if ((typeof filePaths === 'undefined') || !filePaths.length) {
return;
};
@ -203,7 +203,7 @@ class Action {
properties: [ 'openDirectory' ],
});
window.Electron.showOpenDialog(options).then(({ filePaths }) => {
UtilCommon.getElectron().showOpenDialog(options).then(({ filePaths }) => {
if ((filePaths == undefined) || !filePaths.length) {
return;
};
@ -412,7 +412,7 @@ class Action {
analytics.event('ClickImport', { type });
window.Electron.showOpenDialog(fileOptions).then((result: any) => {
UtilCommon.getElectron().showOpenDialog(fileOptions).then((result: any) => {
const paths = result.filePaths;
if ((paths == undefined) || !paths.length) {
return;

View file

@ -24,7 +24,7 @@ class Analytics {
isAllowed (): boolean {
const { config } = commonStore;
return !(config.sudo || [ 'alpha', 'beta' ].includes(config.channel) || !window.Electron.isPackaged) || this.debug();
return !(config.sudo || [ 'alpha', 'beta' ].includes(config.channel) || !UtilCommon.getElectron().isPackaged) || this.debug();
};
init () {
@ -35,11 +35,11 @@ class Analytics {
const { config, interfaceLang } = commonStore;
const platform = UtilCommon.getPlatform();
let version = String(window.Electron.version.app || '').split('-');
let version = String(UtilCommon.getElectron().version.app || '').split('-');
if (version.length) {
version = [ version[0] ];
};
if (config.sudo || !window.Electron.isPackaged || [ 'alpha' ].includes(config.channel)) {
if (config.sudo || !UtilCommon.getElectron().isPackaged || [ 'alpha' ].includes(config.channel)) {
version.push('dev');
} else
if ([ 'beta' ].includes(config.channel)) {
@ -58,11 +58,11 @@ class Analytics {
platform,
});
this.instance.setVersionName(window.Electron.version.app);
this.instance.setVersionName(UtilCommon.getElectron().version.app);
this.instance.setUserProperties({
deviceType: 'Desktop',
platform,
osVersion: window.Electron.version.os,
osVersion: UtilCommon.getElectron().version.os,
interfaceLang,
});

View file

@ -451,8 +451,8 @@ class Keyboard {
};
const rootId = keyboard.getRootId();
const logPath = window.Electron.logPath;
const tmpPath = window.Electron.tmpPath;
const logPath = UtilCommon.getElectron().logPath;
const tmpPath = UtilCommon.getElectron().tmpPath;
switch (cmd) {
case 'search': {
@ -544,7 +544,7 @@ class Keyboard {
case 'debugSpace': {
C.DebugSpaceSummary((message: any) => {
if (!message.error.code) {
window.Electron.fileWrite('debug-space-summary.json', JSON.stringify(message, null, 5), 'utf8');
UtilCommon.getElectron().fileWrite('debug-space-summary.json', JSON.stringify(message, null, 5), 'utf8');
Renderer.send('pathOpen', tmpPath);
};
@ -578,9 +578,9 @@ class Keyboard {
C.AppGetVersion((message: any) => {
let url = Url.contact;
url = url.replace(/\%25device\%25/g, window.Electron.version.device);
url = url.replace(/\%25os\%25/g, window.Electron.version.os);
url = url.replace(/\%25version\%25/g, window.Electron.version.app);
url = url.replace(/\%25device\%25/g, UtilCommon.getElectron().version.device);
url = url.replace(/\%25os\%25/g, UtilCommon.getElectron().version.os);
url = url.replace(/\%25version\%25/g, UtilCommon.getElectron().version.app);
url = url.replace(/\%25build\%25/g, message.details);
url = url.replace(/\%25middleware\%25/g, message.version);
url = url.replace(/\%25accountId\%25/g, account.id);
@ -599,9 +599,9 @@ class Keyboard {
C.AppGetVersion((message: any) => {
const data = [
[ translate('libKeyboardDevice'), window.Electron.version.device ],
[ translate('libKeyboardOSVersion'), window.Electron.version.os ],
[ translate('libKeyboardAppVersion'), window.Electron.version.app ],
[ translate('libKeyboardDevice'), UtilCommon.getElectron().version.device ],
[ translate('libKeyboardOSVersion'), UtilCommon.getElectron().version.os ],
[ translate('libKeyboardAppVersion'), UtilCommon.getElectron().version.app ],
[ translate('libKeyboardBuildNumber'), message.details ],
[ translate('libKeyboardLibraryVersion'), message.version ],
[ translate('libKeyboardAccountID'), account.id ],

View file

@ -6,22 +6,22 @@ class Renderer {
args = args || [];
const cmd = args[0];
const winId = Number(window.Electron.currentWindow().windowId) || 0;
const winId = Number(UtilCommon.getElectron().currentWindow().windowId) || 0;
args.shift();
window.Electron.Api(winId, cmd, UtilCommon.objectCopy(args));
UtilCommon.getElectron().Api(winId, cmd, UtilCommon.objectCopy(args));
};
on (event: string, callBack: any) {
this.remove(event);
window.Electron.on(event, (...args: any[]) => {
UtilCommon.getElectron().on(event, (...args: any[]) => {
callBack.apply(this, args);
});
};
remove (event: string) {
window.Electron.removeAllListeners(event);
UtilCommon.getElectron().removeAllListeners(event);
};
};

View file

@ -9,6 +9,10 @@ class UtilCommon {
history: any = null;
getElectron () {
return window.Electron || {};
};
init (history: any) {
this.history = history;
};
@ -732,7 +736,7 @@ class UtilCommon {
};
getPlatform () {
return Constant.platforms[window.Electron.platform];
return Constant.platforms[this.getElectron().platform];
};
isPlatformMac () {
@ -1002,7 +1006,7 @@ class UtilCommon {
reader.onload = () => {
ret.push({
name: item.name,
path: window.Electron.fileWrite(item.name, reader.result, 'binary'),
path: this.getElectron().fileWrite(item.name, reader.result, 'binary'),
});
cb();
};

View file

@ -5,7 +5,7 @@ import Constant from 'json/constant.json';
class UtilFile {
fromPath (path: string) {
const { buffer, type } = window.Electron.fileParam(path);
const { buffer, type } = UtilCommon.getElectron().fileParam(path);
if (!type) {
return null;
};

View file

@ -45,6 +45,7 @@ class CommonStore {
public languages: string[] = [];
public workspaceId = '';
public notionToken = '';
public serverPort = 0;
public previewObj: I.Preview = {
type: null,