Chromeextension (#499)
* updates to chrome extension manifest * update manifest with chrome extension id
This commit is contained in:
parent
5a48f898c6
commit
7465ffeb3b
@ -25,14 +25,19 @@ function findNewDevices() {
|
||||
serialPorts.forEach(function (serialPort) {
|
||||
if (byPath(serialPort.path).length == 0 &&
|
||||
serialPort.displayName == "mbed Serial Port") {
|
||||
chrome.serial.connect(serialPort.path, { bitrate: 115200 }, function (info) {
|
||||
// In case the [connect] operation takes more than five seconds...
|
||||
if (info && byPath(serialPort.path).length == 0)
|
||||
connections.push({
|
||||
id: info.connectionId,
|
||||
path: serialPort.path
|
||||
});
|
||||
});
|
||||
try {
|
||||
chrome.serial.connect(serialPort.path, { bitrate: 115200 }, function (info) {
|
||||
// In case the [connect] operation takes more than five seconds...
|
||||
if (info && byPath(serialPort.path).length == 0)
|
||||
connections.push({
|
||||
id: info.connectionId,
|
||||
path: serialPort.path
|
||||
});
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
console.log("failed to connect to " + serialPort.displayName);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -40,7 +45,8 @@ function findNewDevices() {
|
||||
function main() {
|
||||
// Register new clients in the [ports] global variable.
|
||||
chrome.runtime.onConnectExternal.addListener(function (port) {
|
||||
if (/^(micro:bit|touchdevelop|yelm|pxt|codemicrobit|codethemicrobit|pxt.microbit.org|makecode)$/.test(port.name)) {
|
||||
console.log('connection to port ' + port.name);
|
||||
if (/^serial$/.test(port.name)) {
|
||||
ports.push(port);
|
||||
port.onDisconnect.addListener(function () {
|
||||
ports = ports.filter(function (x) { return x != port; });
|
||||
|
@ -1,3 +1,9 @@
|
||||
declare var chrome: any;
|
||||
declare class TextDecoder {
|
||||
constructor(encoding: string);
|
||||
decode(data: DataView): string;
|
||||
}
|
||||
|
||||
// A list of: {
|
||||
// id: number;
|
||||
// path: string;
|
||||
@ -27,7 +33,7 @@ function byId(id: string): Connection[] {
|
||||
return connections.filter((x) => x.id == id);
|
||||
}
|
||||
|
||||
function onReceive(data, id: string) {
|
||||
function onReceive(data: ArrayBuffer, id: string) {
|
||||
if (ports.length == 0) return;
|
||||
|
||||
let view = new DataView(data);
|
||||
@ -36,7 +42,7 @@ function onReceive(data, id: string) {
|
||||
ports.forEach(port => port.postMessage(<Message>{
|
||||
type: "serial",
|
||||
data: decodedString,
|
||||
id: id,
|
||||
id: id
|
||||
}));
|
||||
}
|
||||
|
||||
@ -45,14 +51,18 @@ function findNewDevices() {
|
||||
serialPorts.forEach(function (serialPort) {
|
||||
if (byPath(serialPort.path).length == 0 &&
|
||||
serialPort.displayName == "mbed Serial Port") {
|
||||
chrome.serial.connect(serialPort.path, { bitrate: 115200 }, function (info) {
|
||||
// In case the [connect] operation takes more than five seconds...
|
||||
if (info && byPath(serialPort.path).length == 0)
|
||||
connections.push({
|
||||
id: info.connectionId,
|
||||
path: serialPort.path
|
||||
});
|
||||
});
|
||||
try {
|
||||
chrome.serial.connect(serialPort.path, { bitrate: 115200 }, function (info) {
|
||||
// In case the [connect] operation takes more than five seconds...
|
||||
if (info && byPath(serialPort.path).length == 0)
|
||||
connections.push({
|
||||
id: info.connectionId,
|
||||
path: serialPort.path
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(`failed to connect to ${serialPort.displayName}`)
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -61,7 +71,8 @@ function findNewDevices() {
|
||||
function main() {
|
||||
// Register new clients in the [ports] global variable.
|
||||
chrome.runtime.onConnectExternal.addListener(function (port) {
|
||||
if (/^(micro:bit|touchdevelop|yelm|pxt|codemicrobit|codethemicrobit|pxt.microbit.org|makecode)$/.test(port.name)) {
|
||||
console.log('connection to port ' + port.name)
|
||||
if (/^serial$/.test(port.name)) {
|
||||
ports.push(port);
|
||||
port.onDisconnect.addListener(function () {
|
||||
ports = ports.filter(function (x) { return x != port });
|
||||
|
@ -7,13 +7,12 @@
|
||||
|
||||
"manifest_version": 2,
|
||||
"name": "makecode.microbit.org",
|
||||
"version": "0.7.0",
|
||||
"version": "0.8.0",
|
||||
"author": "Microsoft Corporation",
|
||||
"short_name": "makecode.microbit.org",
|
||||
|
||||
"description": "Extension for https://makecode.microbit.org.",
|
||||
"homepage_url": "https://makecode.microbit.org",
|
||||
"offline_enabled": "true",
|
||||
"offline_enabled": true,
|
||||
"icons": {
|
||||
"48": "logo48.png",
|
||||
"128": "logo128.png"
|
||||
|
@ -197,7 +197,8 @@
|
||||
"productFilter": "0x0204",
|
||||
"vendorFilter": "0x0d28",
|
||||
"nameFilter": "^mbed Serial Port",
|
||||
"log": true
|
||||
"log": true,
|
||||
"chromeExtension": "hjcflblhjoglmjjkecamiegdigfkgeni"
|
||||
},
|
||||
"appTheme": {
|
||||
"accentColor": "#5C005C",
|
||||
|
Loading…
Reference in New Issue
Block a user