Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit 4c45ff4

Browse files
authored
add extensions support (#247)
1 parent e23cf31 commit 4c45ff4

38 files changed

+1313
-0
lines changed

extensions/chrome_ext_v3/Test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const Particle = ({
2+
});
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* @license
3+
* Copyright 2022 Google LLC
4+
*
5+
* Use of this source code is governed by a BSD-style
6+
* license that can be found in the LICENSE file or at
7+
* https://developers.google.com/open-source/licenses/bsd
8+
*/
9+
import {App} from '../deploy/Library/App/TopLevel/App.js';
10+
import {logFactory} from '../deploy/Library/Core/utils.min.js';
11+
import {XenComposer} from '../deploy/Library/Dom/Surfaces/Default/XenComposer.js';
12+
import {HistoryService} from '../deploy/Library/App/HistoryService.js';
13+
import {FirebaseStoragePersistor} from '../deploy/Library/Firebase/FirebaseStoragePersistor.js';
14+
import {DeviceUxRecipe} from '../deploy/Library/Media/DeviceUxRecipe.js';
15+
import {CameraNode} from '../deploy/Library/GraphsNodes/CameraNode.js';
16+
17+
const log = logFactory(true, 'ExtensionApp', 'navy');
18+
19+
const ExtensionRecipe = {
20+
$stores: {
21+
html: {
22+
$tags: ['persisted'],
23+
$type: 'MultilineString',
24+
$value: `
25+
<div style="padding: 24px;">
26+
<h3>Hello World ${Math.random()}</h3>
27+
</div>
28+
`.trim(),
29+
}
30+
},
31+
echo: {
32+
$kind: '$library/Echo.js',
33+
$inputs: ['html']
34+
}
35+
};
36+
37+
export const ExtensionApp = class extends App {
38+
constructor(path, root, options) {
39+
super(path, root, options);
40+
this.services = {
41+
HistoryService
42+
};
43+
this.persistor = new FirebaseStoragePersistor('user');
44+
this.userAssembly = [CameraNode, ExtensionRecipe];
45+
this.composer = new XenComposer(document.body, true);
46+
this.composer.onevent = (p, e) => this.handle(p, e);
47+
this.arcs.render = p => this.render(p);
48+
log('Extension lives!');
49+
}
50+
async spinup() {
51+
await super.spinup();
52+
setTimeout(() => {
53+
this.arcs.set('user', 'mediaDevices', {
54+
videoinput: {
55+
deviceId: '545b0c354475465dd731e6fe7414319c2d88f4660c6c108ca43528191638406b',
56+
kind: 'videoinput',
57+
label: 'HD Pro Webcam C920 (046d:082d)',
58+
groupId: '6b5db3734e5bd10ecda9de583b7ef3761be03ce1ab1b49c1a91a312fb91f6de2'
59+
}
60+
});
61+
}, 1000);
62+
// this.arcs.set('user', 'html', `
63+
// <div style="padding: 24px;">
64+
// <h3>Hello World ${Math.random()}</h3>
65+
// </div>
66+
// `);
67+
}
68+
render(packet) {
69+
log('render', packet);
70+
this.composer.render(packet);
71+
}
72+
handle(pid, eventlet) {
73+
// TODO(sjmiles): the composer doesn't know from Arcs or Users, so the PID is all we have
74+
// we should make the PID into an USERID:ARCID:PARTICLEID ... UAPID? UAP? E[vent]ID?
75+
const arc = Object.values(this.arcs.user.arcs).find(({hosts}) => hosts[pid]);
76+
arc?.onevent(pid, eventlet);
77+
}
78+
};
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2022 Google LLC All rights reserved.
4+
* Use of this source code is governed by a BSD-style
5+
* license that can be found in the LICENSE file.
6+
*/
7+
8+
// use Library path from configuration
9+
10+
const Library = globalThis.config.arcsPath;
11+
12+
// import modules from the ArcsJs Library
13+
// the 'load' function imports modules in parallel
14+
15+
const load = async paths => (await Promise.all(paths.map(p => import(`${Library}/${p}`)))).reduce((e, m) =>({...e, ...m}),{});
16+
17+
export const {
18+
Paths, logFactory, App, Resources, Params,
19+
deepQuerySelector, Xen,
20+
quickStart,
21+
LocalStoragePersistor,
22+
// HistoryService,
23+
// NodeCatalogRecipe,
24+
// MediaService,
25+
// MediapipeNodes,
26+
// FaceMeshService, SelfieSegmentationService,
27+
// ThreejsService, ShaderService,
28+
// TensorFlowService, CocoSsdService,
29+
// LobbyService,
30+
// GoogleApisService,
31+
// // must be last
32+
// ...etc
33+
} = await load([
34+
'Core/utils.js',
35+
'Isolation/vanilla.js',
36+
'App/TopLevel/App.js',
37+
'App/Resources.js',
38+
'App/Params.js',
39+
'App/boot.js',
40+
'App/common-dom.js',
41+
//'App/HistoryService.js',
42+
'Dom/Xen/xen-async.js',
43+
'Dom/dom.js',
44+
'Dom/multi-select.js',
45+
'Dom/code-mirror/code-mirror.js',
46+
'LocalStorage/LocalStoragePersistor.js',
47+
// 'Designer/designer-layout.js',
48+
// 'NodeGraph/dom/node-graph.js',
49+
// 'NodeTypeCatalog/draggable-item.js',
50+
// 'NodeTypeCatalog/NodeCatalogRecipe.js',
51+
// 'Rtc/LobbyService.js',
52+
// 'Goog/GoogleApisService.js',
53+
// 'NewMedia/CameraNode.js',
54+
// 'NewMedia/MediaService.js',
55+
// 'Mediapipe/FaceMeshService.js',
56+
// 'Mediapipe/SelfieSegmentationService.js',
57+
// 'Mediapipe/MediapipeNodes.js',
58+
// 'Threejs/ThreejsService.js',
59+
// 'Shader/ShaderService.js',
60+
// 'Shader/ShaderNodes.js',
61+
// 'TensorFlow/TensorFlow.js',
62+
// 'TensorFlow/TensorFlowService.js',
63+
// 'TensorFlow/CocoSsdService.js',
64+
// 'TensorFlow/CocoSsdNode.js',
65+
// 'Display/DisplayNodes.js'
66+
]);
67+
68+
// // memoize important paths
69+
70+
// const url = Paths.getAbsoluteHereUrl(import.meta, 1);
71+
72+
// // important paths
73+
// Paths.add({
74+
// $app: `${url}/../deploy/nodegraph`,
75+
// $config: `${url}/config.js`,
76+
// $library:`${url}/../deploy/Library`
77+
// });
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
globalThis.config = {
2+
arcsPath: `../deploy/Library`,
3+
logFlags: {
4+
particles: true,
5+
//recipe: true,
6+
//runtime: true,
7+
storage: true
8+
}
9+
};
2.46 KB
Loading
3.05 KB
Loading
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* global chrome */
2+
3+
import './deploy/Library/Core/core.js';
4+
import './deploy/Library/Isolation/vanilla.js';
5+
//import {Arcs} from './deploy/Library/App/TopLevel/Arcs.js';
6+
import {App} from './deploy/Library/App/TopLevel/App.js';
7+
8+
const paths = {
9+
$library: './deploy/Library'
10+
};
11+
12+
(async () => {
13+
await import('./Test.js');
14+
const app = new App(paths);
15+
//await app.spinup();
16+
// await Arcs.init({
17+
// //paths: this.paths,
18+
// //root: this.root || document.body,
19+
// //onservice: this.service.bind(this),
20+
// //injections: {themeRules, ...this.injections}
21+
// });
22+
})();
23+
24+
chrome.action.onClicked.addListener(async () => {
25+
const url = chrome.runtime.getURL("hello.html");
26+
/*const tab = */await chrome.tabs.create({url});
27+
});
28+
29+
onmessage = event => {
30+
console.log(event);
31+
};
32+
33+
chrome.runtime.onMessage.addListener(event => {
34+
console.log(event);
35+
});

extensions/chrome_ext_v3/content-script.js

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!doctype html>
2+
3+
<link type="text/css" rel="stylesheet" href="./deploy/Library/Dom/Material/material-icon-font/icons.css">
4+
5+
<style>
6+
html {
7+
overflow: hidden;
8+
}
9+
body {
10+
margin: 0;
11+
width: 600px;
12+
height: 400px;
13+
overflow: hidden;
14+
display: flex;
15+
flex-direction: column;
16+
align-items: stretch;
17+
}
18+
body > * {
19+
flex: 1;
20+
}
21+
</style>
22+
23+
<script type="module" src="hello.js"></script>

extensions/chrome_ext_v3/hello.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2022 Google LLC All rights reserved.
4+
* Use of this source code is governed by a BSD-style
5+
* license that can be found in the LICENSE file.
6+
*/
7+
import './app/config.js';
8+
import {quickStart} from './app/arcs.js';
9+
import {ExtensionApp} from './app/ExtensionApp.js';
10+
11+
await quickStart(ExtensionApp, import.meta.url, {
12+
$nodegraph: '$app/deploy/nodegraph/Library'
13+
});

0 commit comments

Comments
 (0)