Skip to content

Commit

Permalink
Merge branch 'feature/JS-6113-space-store-migration' into nightly-ci-…
Browse files Browse the repository at this point in the history
…test
  • Loading branch information
fb929 committed Jan 23, 2025
2 parents 73a7b3a + 8624fe1 commit ca8ace9
Show file tree
Hide file tree
Showing 371 changed files with 13,887 additions and 14,592 deletions.
2 changes: 1 addition & 1 deletion dist/challenge/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
src: url('../font/inter/bold.woff2') format('woff2');
}

html, body { height: 100%; }
html, body { height: 100%; -webkit-app-region: drag; }
/*html.dark body { background-color: #171717; color: #a09f92; }*/

body { font-family: 'Inter', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; background-color: #fff; color: #252525; }
Expand Down
22 changes: 22 additions & 0 deletions dist/embed/iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
let cachedHtml = '';
let height = 0;
let blockId = '';
let player;

win.off('message resize');

Expand Down Expand Up @@ -139,6 +140,23 @@
insertHtml(html);
};

if (processor == Processor.Youtube) {
window.onYouTubeIframeAPIReady = () => {
player = new YT.Player('player', {
events: {
onReady,
onStateChange,
}
});
};

const onReady = (event) => {
};

const onStateChange = (event) => {
};
};

loadLibs(libs, () => {
if (!insertBeforeLoad) {
insertHtml(html);
Expand Down Expand Up @@ -258,6 +276,10 @@
libs.push('https://cpwebassets.codepen.io/assets/embed/ei.js');
break;
};

case Processor.Youtube:
libs.push('https://www.youtube.com/iframe_api');
break;
};

return {
Expand Down
10 changes: 10 additions & 0 deletions dist/extension/auth/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Anytype Web Clipper</title>
</head>
<body>
<script type="text/javascript" src="../js/main.js"></script>
</body>
</html>
6 changes: 4 additions & 2 deletions dist/workers/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ updateSettings = (param) => {

updateTheme = ({ theme, colors }) => {
data.colors = colors;

initTheme(theme);
redraw();
};
Expand Down Expand Up @@ -624,7 +623,9 @@ onClick = ({ x, y }) => {

onSelect = ({ x, y, selectRelated }) => {
const d = getNodeByCoords(x, y);
let related = [];

let related = [];

if (d) {
if (selectRelated) {
related = edgeMap.get(d.id);
Expand All @@ -638,6 +639,7 @@ onSetRootId = ({ x, y }) => {
const d = getNodeByCoords(x, y);
if (d) {
this.setRootId({ rootId: d.id });
send('setRootId', { node: d.id });
};
};

Expand Down
2 changes: 2 additions & 0 deletions electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ const protocol = 'anytype';
const remote = require('@electron/remote/main');
const { installNativeMessagingHost } = require('./electron/js/lib/installNativeMessagingHost.js');
const binPath = fixPathForAsarUnpack(path.join(__dirname, 'dist', `anytypeHelper${is.windows ? '.exe' : ''}`));
const Store = require('electron-store');

// Fix notifications app name
if (is.windows) {
app.setAppUserModelId(app.name);
};

storage.setDataPath(app.getPath('userData'));
Store.initRenderer();

const Api = require('./electron/js/api.js');
const ConfigManager = require('./electron/js/config.js');
Expand Down
10 changes: 8 additions & 2 deletions electron/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ class Api {
WindowManager.sendToAll('pin-check');
};

setConfig (win, config) {
ConfigManager.set(config, () => Util.send(win, 'config', ConfigManager.config));
setConfig (win, config, callBack) {
ConfigManager.set(config, () => {
Util.send(win, 'config', ConfigManager.config);

if (callBack) {
callBack();
};
});
};

setAccount (win, account) {
Expand Down
34 changes: 30 additions & 4 deletions electron/js/menu.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { app, shell, Menu, Tray } = require('electron');
const { is } = require('electron-util');
const fs = require('fs');
const path = require('path');
const ConfigManager = require('./config.js');
const Util = require('./util.js');
Expand Down Expand Up @@ -64,16 +65,40 @@ class MenuManager {
Separator,

{
label: Util.translate('electronMenuDirectory'), submenu: [
label: Util.translate('electronMenuOpen'), submenu: [
{ label: Util.translate('electronMenuWorkDirectory'), click: () => shell.openPath(Util.userPath()) },
{ label: Util.translate('electronMenuDataDirectory'), click: () => shell.openPath(Util.dataPath()) },
{ label: Util.translate('electronMenuConfigDirectory'), click: () => shell.openPath(Util.defaultUserDataPath()) },
{ label: Util.translate('electronMenuLogsDirectory'), click: () => shell.openPath(Util.logPath()) },
{
label: Util.translate('electronMenuCustomCss'),
click: () => {
const fp = path.join(Util.userPath(), 'custom.css');

if (!fs.existsSync(fp)) {
fs.writeFileSync(fp, '');
};

shell.openPath(fp);
},
},
]
},

Separator,

{
label: Util.translate('electronMenuApplyCustomCss'), type: 'checkbox', checked: !config.disableCss,
click: () => {
config.disableCss = !config.disableCss;
Api.setConfig(this.win, { disableCss: config.disableCss }, () => {
WindowManager.reloadAll();
});
},
},

Separator,

{ role: 'close', label: Util.translate('electronMenuClose') },
]
},
Expand Down Expand Up @@ -150,11 +175,11 @@ class MenuManager {
submenu: [
{
label: `${Util.translate('electronMenuReleaseNotes')} (${app.getVersion()})`,
click: () => Util.send(this.win, 'popup', 'help', { preventResize: true, data: { document: 'whatsNew' } })
click: () => Util.send(this.win, 'popup', 'help', { data: { document: 'whatsNew' } })
},
{
label: Util.translate('electronMenuShortcuts'), accelerator: 'Ctrl+Space',
click: () => Util.send(this.win, 'popup', 'shortcut', { preventResize: true })
click: () => Util.send(this.win, 'popup', 'shortcut', {})
},

Separator,
Expand Down Expand Up @@ -235,6 +260,7 @@ class MenuManager {
{ label: Util.translate('electronMenuDebugStat'), click: () => Util.send(this.win, 'commandGlobal', 'debugStat') },
{ label: Util.translate('electronMenuDebugReconcile'), click: () => Util.send(this.win, 'commandGlobal', 'debugReconcile') },
{ label: Util.translate('electronMenuDebugNet'), click: () => Util.send(this.win, 'commandGlobal', 'debugNet') },
{ label: Util.translate('electronMenuDebugLog'), click: () => Util.send(this.win, 'commandGlobal', 'debugLog') },

Separator,

Expand Down Expand Up @@ -319,7 +345,7 @@ class MenuManager {
this.tray = new Tray (this.getTrayIcon());
this.tray.setToolTip('Anytype');
this.tray.setContextMenu(Menu.buildFromTemplate([
{ label: Util.translate('electronMenuOpen'), click: () => this.winShow() },
{ label: Util.translate('electronMenuOpenApp'), click: () => this.winShow() },

Separator,

Expand Down
13 changes: 12 additions & 1 deletion electron/js/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const os = require('os');
const path = require('path');
const mime = require('mime-types');
const tmpPath = () => app.getPath('temp');
const Store = require('electron-store');
const suffix = app.isPackaged ? '' : 'dev';
const store = new Store({ name: [ 'localStorage', suffix ].join('-') });

contextBridge.exposeInMainWorld('Electron', {
version: {
Expand All @@ -16,6 +19,10 @@ contextBridge.exposeInMainWorld('Electron', {
platform: os.platform(),
arch: process.arch,

storeSet: (key, value) => store.set(key, value),
storeGet: key => store.get(key),
storeDelete: key => store.delete(key),

isPackaged: app.isPackaged,
userPath: () => app.getPath('userData'),
tmpPath,
Expand All @@ -26,7 +33,11 @@ contextBridge.exposeInMainWorld('Electron', {
fileMime: fp => mime.lookup(fp),
fileExt: fp => path.extname(fp).replace(/^./, ''),
fileSize: fp => fs.statSync(fp).size,
isDirectory: fp => fs.lstatSync(fp).isDirectory(),
isDirectory: fp => {
let ret = false;
try { ret = fs.lstatSync(fp).isDirectory(); } catch (e) {};
return ret;
},
defaultPath: () => path.join(app.getPath('appData'), app.getName()),

currentWindow: () => getCurrentWindow(),
Expand Down
10 changes: 8 additions & 2 deletions electron/js/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { app, dialog, shell } = require('electron');
const Util = require('./util.js');

let maxStdErrChunksBuffer = 10;
const winShutdownStdinMessage = 'shutdown\n';

class Server {

Expand Down Expand Up @@ -114,7 +115,12 @@ class Server {
});

this.stopTriggered = true;
this.cp.kill(signal);
if (process.platform === 'win32') {
// it is not possible to handle os signals on windows, so we can't do graceful shutdown on go side
this.cp.stdin.write(winShutdownStdinMessage);
} else {
this.cp.kill(signal);
};
} else {
resolve();
};
Expand All @@ -131,4 +137,4 @@ class Server {

};

module.exports = new Server();
module.exports = new Server();
10 changes: 9 additions & 1 deletion electron/js/window.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow, nativeImage, dialog, screen } = require('electron');
const { app, BrowserWindow, nativeImage, dialog } = require('electron');
const { is, fixPathForAsarUnpack } = require('electron-util');
const path = require('path');
const windowStateKeeper = require('electron-window-state');
Expand Down Expand Up @@ -115,6 +115,7 @@ class WindowManager {
height: state.height,
});
} else {
const { screen } = require('electron');
const primaryDisplay = screen.getPrimaryDisplay();
const { width, height } = primaryDisplay.workAreaSize;

Expand All @@ -141,17 +142,24 @@ class WindowManager {
};

createChallenge (options) {
const { screen } = require('electron');
const primaryDisplay = screen.getPrimaryDisplay();
const { width } = primaryDisplay.workAreaSize;

const win = this.create({}, {
backgroundColor: '',
width: 424,
height: 232,
x: Math.floor(width / 2 - 212),
y: 50,
titleBarStyle: 'hidden',
});

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

is.windows || is.linux ? win.showInactive() : win.show();
win.focus();

win.webContents.once('did-finish-load', () => {
win.webContents.postMessage('challenge', options);
Expand Down
82 changes: 82 additions & 0 deletions extension/auth.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import * as React from 'react';
import * as hs from 'history';
import { Router, Route, Switch } from 'react-router-dom';
import { RouteComponentProps } from 'react-router';
import { Provider } from 'mobx-react';
import { configure } from 'mobx';
import { S, U } from 'Lib';

import Index from './auth/index';
import Success from './auth/success';
import Util from './lib/util';

import './scss/auth.scss';

configure({ enforceActions: 'never' });

const Routes = [
{ path: '/' },
{ path: '/:page' },
];

const Components = {
index: Index,
success: Success,
};

const memoryHistory = hs.createMemoryHistory;
const history = memoryHistory();

class RoutePage extends React.Component<RouteComponentProps> {

render () {
const { match } = this.props;
const params = match.params as any;
const page = params.page || 'index';
const Component = Components[page];

return Component ? <Component /> : null;
};

};

class Auth extends React.Component {

render () {
return (
<Router history={history}>
<Provider {...S}>
<div>
<Switch>
{Routes.map((item: any, i: number) => (
<Route path={item.path} exact={true} key={i} component={RoutePage} />
))}
</Switch>
</div>
</Provider>
</Router>
);
};

componentDidMount () {
U.Router.init(history);

/* @ts-ignore */
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
switch (msg.type) {
case 'initAuth':
const { appKey, gatewayPort, serverPort } = msg;

Util.init(serverPort, gatewayPort);
Util.authorize(appKey);

sendResponse({});
break;
};
return true;
});
};

};

export default Auth;
Loading

0 comments on commit ca8ace9

Please sign in to comment.