Skip to content

Commit

Permalink
Merge branch 'main' of github.com:anyproto/anytype-ts into feature/no…
Browse files Browse the repository at this point in the history
…tifications
  • Loading branch information
ra3orblade committed Mar 11, 2024
2 parents 060932b + 5ad95ae commit c15bd61
Show file tree
Hide file tree
Showing 114 changed files with 1,613 additions and 1,318 deletions.
2 changes: 1 addition & 1 deletion dist/extension/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@

let html = '';
if (sel.rangeCount) {
const container = document.createElement("div");
const container = document.createElement('div');
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
};
Expand Down
4 changes: 2 additions & 2 deletions dist/extension/manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"manifest_version": 3,
"name": "Anytype Web Clipper",
"description": "Anytype is a next generation software that breaks down barriers between applications, gives back privacy and data ownership to users",
"version": "0.0.2",
"description": "Save web content to the Anytype — open, encrypted, and local-first application that connects everything as objects.",
"version": "0.0.3",
"icons": {
"16": "img/icon16x16.png",
"128": "img/icon128x128.png"
Expand Down
3 changes: 2 additions & 1 deletion electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ function createWindow () {
};

if (Api[cmd]) {
Api[cmd].apply(Api, [ win ].concat(args || []));
return Api[cmd].apply(Api, [ win ].concat(args || []));
} else {
console.error('[Api] method not defined:', cmd);
return null;
};
});
};
Expand Down
10 changes: 2 additions & 8 deletions electron/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const KEYTAR_SERVICE = 'Anytype';
class Api {

account = null;
phrase = '';
isPinChecked = false;

appOnLoad (win) {
Expand All @@ -35,7 +34,6 @@ class Api {
isChild: win.isChild,
route: win.route,
account: this.account,
phrase: this.phrase,
isPinChecked: this.isPinChecked,
languages: win.webContents.session.availableSpellCheckerLanguages,
css: String(css || ''),
Expand Down Expand Up @@ -104,16 +102,12 @@ class Api {

keytarSet (win, key, value) {
if (key && value) {
this.phrase = value;
keytar.setPassword(KEYTAR_SERVICE, key, value);
};
};

keytarGet (win, key) {
keytar.getPassword(KEYTAR_SERVICE, key).then(value => {
this.phrase = value;
Util.send(win, 'keytarGet', key, value);
});
async keytarGet (win, key) {
return await keytar.getPassword(KEYTAR_SERVICE, key);
};

keytarDelete (win, key) {
Expand Down
88 changes: 43 additions & 45 deletions electron/js/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class MenuManager {
const WindowManager = require('./window.js');
const UpdateManager = require('./update.js');

config.debug = config.debug || {};

const menuParam = [
{
label: 'Anytype',
Expand Down Expand Up @@ -66,16 +68,6 @@ class MenuManager {

Separator,

{
label: Util.translate('electronMenuDebug'), submenu: [
{ label: Util.translate('electronMenuDebugSpace'), click: () => Util.send(this.win, 'commandGlobal', 'debugSpace') },
{ label: Util.translate('electronMenuDebugObject'), click: () => Util.send(this.win, 'commandGlobal', 'debugTree') },
{ label: Util.translate('electronMenuDebugProcess'), click: () => Util.send(this.win, 'commandGlobal', 'debugProcess') },
],
},

Separator,

{ role: 'close', label: Util.translate('electronMenuClose') },
]
},
Expand Down Expand Up @@ -172,42 +164,48 @@ class MenuManager {
},
];

//if (config.allowDebug || config.allowBeta) {
config.debug = config.debug || {};

const flags = {
ui: Util.translate('electronMenuFlagInterface'),
ho: Util.translate('electronMenuFlagHidden'),
mw: Util.translate('electronMenuFlagMiddleware'),
th: Util.translate('electronMenuFlagThreads'),
fi: Util.translate('electronMenuFlagFiles'),
an: Util.translate('electronMenuFlagAnalytics'),
js: Util.translate('electronMenuFlagJson'),
};
const flagMenu = [];

for (const i in flags) {
flagMenu.push({
label: flags[i], type: 'checkbox', checked: config.debug[i],
click: () => {
config.debug[i] = !config.debug[i];
Api.setConfig(this.win, { debug: config.debug });

if ([ 'ho' ].includes(i)) {
this.win.reload();
};
}
});
};

menuParam.push({
label: Util.translate('electronMenuDebug'),
submenu: [
{ label: Util.translate('electronMenuFlags'), submenu: flagMenu },
{ label: Util.translate('electronMenuDevTools'), accelerator: 'Alt+CmdOrCtrl+I', click: () => this.win.toggleDevTools() },
]
const flags = {
ui: Util.translate('electronMenuFlagInterface'),
ho: Util.translate('electronMenuFlagHidden'),
mw: Util.translate('electronMenuFlagMiddleware'),
th: Util.translate('electronMenuFlagThreads'),
fi: Util.translate('electronMenuFlagFiles'),
an: Util.translate('electronMenuFlagAnalytics'),
js: Util.translate('electronMenuFlagJson'),
};
const flagMenu = [];

for (const i in flags) {
flagMenu.push({
label: flags[i], type: 'checkbox', checked: config.debug[i],
click: () => {
config.debug[i] = !config.debug[i];
Api.setConfig(this.win, { debug: config.debug });

if ([ 'ho' ].includes(i)) {
this.win.reload();
};
}
});
//};
};

menuParam.push({
label: Util.translate('electronMenuDebug'),
submenu: [
{ label: Util.translate('electronMenuFlags'), submenu: flagMenu },

Separator,

{ label: Util.translate('electronMenuDebugSpace'), click: () => Util.send(this.win, 'commandGlobal', 'debugSpace') },
{ label: Util.translate('electronMenuDebugObject'), click: () => Util.send(this.win, 'commandGlobal', 'debugTree') },
{ label: Util.translate('electronMenuDebugProcess'), click: () => Util.send(this.win, 'commandGlobal', 'debugProcess') },
{ label: Util.translate('electronMenuDebugStat'), click: () => Util.send(this.win, 'commandGlobal', 'debugStat') },

Separator,

{ label: Util.translate('electronMenuDevTools'), accelerator: 'Alt+CmdOrCtrl+I', click: () => this.win.toggleDevTools() },
]
});

const channels = ConfigManager.getChannels().map(it => {
it.click = () => {
Expand Down
2 changes: 1 addition & 1 deletion electron/js/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ contextBridge.exposeInMainWorld('Electron', {
cmd = String(cmd || '');
args = args || [];

ipcRenderer.invoke('Api', id, cmd, args);
return ipcRenderer.invoke('Api', id, cmd, args);
},
});
10 changes: 8 additions & 2 deletions electron/js/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class WindowManager {
win = null;
});

win.once('ready-to-show', () => win.show());
win.on('focus', () => {
UpdateManager.setWindow(win);
MenuManager.setWindow(win);
Expand Down Expand Up @@ -127,6 +126,8 @@ class WindowManager {
};

win.loadURL(is.development ? `http://localhost:${port}` : 'file://' + path.join(Util.appPath, 'dist', 'index.html'));

win.once('ready-to-show', () => win.show());
win.on('enter-full-screen', () => MenuManager.initMenu());
win.on('leave-full-screen', () => MenuManager.initMenu());

Expand All @@ -147,12 +148,17 @@ class WindowManager {

win.loadURL('file://' + path.join(Util.appPath, 'dist', 'challenge', `index.html`));
win.setMenu(null);
win.showInactive();

win.webContents.once('did-finish-load', () => {
win.webContents.postMessage('challenge', options);
});

setTimeout(() => win.close(), 5000);
setTimeout(() => {
if (win && !win.isDestroyed()) {
win.close();
};
}, 30000);
return win;
};

Expand Down
1 change: 1 addition & 0 deletions electron/json/cors.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"https://*.vimeo.com",
"https://w.soundcloud.com",
"https://*.google.com",
"https://miro.com",
"https://*.miro.com",
"https://*.figma.com",
"https://*.github.com",
Expand Down
1 change: 1 addition & 0 deletions extension/entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ window.isExtension = true;
window.Electron = {
currentWindow: () => ({}),
Api: () => {},
platform: '',
};

window.Anytype = {
Expand Down
12 changes: 7 additions & 5 deletions extension/iframe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RouteComponentProps } from 'react-router';
import { Provider } from 'mobx-react';
import { configure } from 'mobx';
import { ListMenu } from 'Component';
import { C, UtilRouter } from 'Lib';
import { C, UtilRouter, UtilData } from 'Lib';
import { commonStore, authStore, blockStore, detailStore, dbStore, menuStore, popupStore, extensionStore } from 'Store';

import Index from './iframe/index';
Expand Down Expand Up @@ -111,11 +111,13 @@ class Iframe extends React.Component {
});

win.off('beforeunload').on('beforeunload', (e: any) => {
if (authStore.token) {
C.WalletCloseSession(authStore.token, () => {
authStore.tokenSet('');
});
if (!authStore.token) {
return;
};

UtilData.destroySubscriptions(() => {
C.WalletCloseSession(authStore.token, () => authStore.tokenSet(''));
});
});
};

Expand Down
16 changes: 14 additions & 2 deletions extension/iframe/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,13 @@ const Create = observer(class Create extends React.Component<I.PageComponent, St

componentDidUpdate (): void {
this.initBlocks();

};

init () {
const spaces = dbStore.getSpaces().map(it => ({ ...it, id: it.targetSpaceId, object: it, iconSize: 16 })).filter(it => it);
const spaces = dbStore.getSpaces()
.filter(it => it && UtilObject.canParticipantWrite(it.targetSpaceId))
.map(it => ({ ...it, id: it.targetSpaceId, object: it, iconSize: 16 }));

if (this.refSpace && spaces.length) {
const space = commonStore.space || spaces[0].targetSpaceId;
Expand All @@ -115,11 +118,17 @@ const Create = observer(class Create extends React.Component<I.PageComponent, St
initBlocks () {
const { html, tabUrl } = extensionStore;

if (!html || (html == this.html)) {
if (html == this.html) {
return;
};

this.html = html;
blockStore.clear(ROOT_ID);

if (!html) {
this.forceUpdate();
return;
};

C.BlockPreview(html, tabUrl, (message: any) => {
if (message.error.code) {
Expand All @@ -135,6 +144,9 @@ const Create = observer(class Create extends React.Component<I.PageComponent, St

blockStore.set(ROOT_ID, blocks);
blockStore.setStructure(ROOT_ID, structure);
blockStore.updateStructureParents(ROOT_ID);
blockStore.updateNumbers(ROOT_ID);
blockStore.updateMarkup(ROOT_ID);

this.forceUpdate();
});
Expand Down
2 changes: 1 addition & 1 deletion extension/iframe/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { observer } from 'mobx-react';
import { I, UtilRouter, Storage } from 'Lib';
import { I, Storage } from 'Lib';
import Util from '../lib/util';

const Index = observer(class Index extends React.Component<I.PageComponent> {
Expand Down
6 changes: 5 additions & 1 deletion extension/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,17 @@ class Util {

authorize (appKey: string, onSuccess?: () => void, onError?: (error) => void) {
authStore.appKeySet(appKey);
UtilData.createSession((message: any) => {
UtilData.createSession('', appKey, (message: any) => {
if (message.error.code) {
if (onError) {
onError(message.error);
};
return;
};

if (message.accountId) {
authStore.accountSet({ id: message.accountId });
};

if (onSuccess) {
onSuccess();
Expand Down
12 changes: 7 additions & 5 deletions extension/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RouteComponentProps } from 'react-router';
import { Provider } from 'mobx-react';
import { configure } from 'mobx';
import { ListMenu } from 'Component';
import { UtilRouter, C } from 'Lib';
import { UtilRouter, C, UtilData } from 'Lib';
import { commonStore, authStore, blockStore, detailStore, dbStore, menuStore, popupStore, extensionStore } from 'Store';
import Extension from 'json/extension.json';

Expand Down Expand Up @@ -97,11 +97,13 @@ class Popup extends React.Component {
});

win.off('beforeunload').on('beforeunload', (e: any) => {
if (authStore.token) {
C.WalletCloseSession(authStore.token, () => {
authStore.tokenSet('');
});
if (!authStore.token) {
return;
};

UtilData.destroySubscriptions(() => {
C.WalletCloseSession(authStore.token, () => authStore.tokenSet(''));
});
});
};

Expand Down
Loading

0 comments on commit c15bd61

Please sign in to comment.