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) {
|
serialPorts.forEach(function (serialPort) {
|
||||||
if (byPath(serialPort.path).length == 0 &&
|
if (byPath(serialPort.path).length == 0 &&
|
||||||
serialPort.displayName == "mbed Serial Port") {
|
serialPort.displayName == "mbed Serial Port") {
|
||||||
chrome.serial.connect(serialPort.path, { bitrate: 115200 }, function (info) {
|
try {
|
||||||
// In case the [connect] operation takes more than five seconds...
|
chrome.serial.connect(serialPort.path, { bitrate: 115200 }, function (info) {
|
||||||
if (info && byPath(serialPort.path).length == 0)
|
// In case the [connect] operation takes more than five seconds...
|
||||||
connections.push({
|
if (info && byPath(serialPort.path).length == 0)
|
||||||
id: info.connectionId,
|
connections.push({
|
||||||
path: serialPort.path
|
id: info.connectionId,
|
||||||
});
|
path: serialPort.path
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.log("failed to connect to " + serialPort.displayName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -40,7 +45,8 @@ function findNewDevices() {
|
|||||||
function main() {
|
function main() {
|
||||||
// Register new clients in the [ports] global variable.
|
// Register new clients in the [ports] global variable.
|
||||||
chrome.runtime.onConnectExternal.addListener(function (port) {
|
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);
|
ports.push(port);
|
||||||
port.onDisconnect.addListener(function () {
|
port.onDisconnect.addListener(function () {
|
||||||
ports = ports.filter(function (x) { return x != port; });
|
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: {
|
// A list of: {
|
||||||
// id: number;
|
// id: number;
|
||||||
// path: string;
|
// path: string;
|
||||||
@ -27,7 +33,7 @@ function byId(id: string): Connection[] {
|
|||||||
return connections.filter((x) => x.id == id);
|
return connections.filter((x) => x.id == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onReceive(data, id: string) {
|
function onReceive(data: ArrayBuffer, id: string) {
|
||||||
if (ports.length == 0) return;
|
if (ports.length == 0) return;
|
||||||
|
|
||||||
let view = new DataView(data);
|
let view = new DataView(data);
|
||||||
@ -36,7 +42,7 @@ function onReceive(data, id: string) {
|
|||||||
ports.forEach(port => port.postMessage(<Message>{
|
ports.forEach(port => port.postMessage(<Message>{
|
||||||
type: "serial",
|
type: "serial",
|
||||||
data: decodedString,
|
data: decodedString,
|
||||||
id: id,
|
id: id
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,14 +51,18 @@ function findNewDevices() {
|
|||||||
serialPorts.forEach(function (serialPort) {
|
serialPorts.forEach(function (serialPort) {
|
||||||
if (byPath(serialPort.path).length == 0 &&
|
if (byPath(serialPort.path).length == 0 &&
|
||||||
serialPort.displayName == "mbed Serial Port") {
|
serialPort.displayName == "mbed Serial Port") {
|
||||||
chrome.serial.connect(serialPort.path, { bitrate: 115200 }, function (info) {
|
try {
|
||||||
// In case the [connect] operation takes more than five seconds...
|
chrome.serial.connect(serialPort.path, { bitrate: 115200 }, function (info) {
|
||||||
if (info && byPath(serialPort.path).length == 0)
|
// In case the [connect] operation takes more than five seconds...
|
||||||
connections.push({
|
if (info && byPath(serialPort.path).length == 0)
|
||||||
id: info.connectionId,
|
connections.push({
|
||||||
path: serialPort.path
|
id: info.connectionId,
|
||||||
});
|
path: serialPort.path
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.log(`failed to connect to ${serialPort.displayName}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -61,7 +71,8 @@ function findNewDevices() {
|
|||||||
function main() {
|
function main() {
|
||||||
// Register new clients in the [ports] global variable.
|
// Register new clients in the [ports] global variable.
|
||||||
chrome.runtime.onConnectExternal.addListener(function (port) {
|
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);
|
ports.push(port);
|
||||||
port.onDisconnect.addListener(function () {
|
port.onDisconnect.addListener(function () {
|
||||||
ports = ports.filter(function (x) { return x != port });
|
ports = ports.filter(function (x) { return x != port });
|
||||||
|
@ -7,13 +7,12 @@
|
|||||||
|
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "makecode.microbit.org",
|
"name": "makecode.microbit.org",
|
||||||
"version": "0.7.0",
|
"version": "0.8.0",
|
||||||
"author": "Microsoft Corporation",
|
"author": "Microsoft Corporation",
|
||||||
"short_name": "makecode.microbit.org",
|
"short_name": "makecode.microbit.org",
|
||||||
|
|
||||||
"description": "Extension for https://makecode.microbit.org.",
|
"description": "Extension for https://makecode.microbit.org.",
|
||||||
"homepage_url": "https://makecode.microbit.org",
|
"offline_enabled": true,
|
||||||
"offline_enabled": "true",
|
|
||||||
"icons": {
|
"icons": {
|
||||||
"48": "logo48.png",
|
"48": "logo48.png",
|
||||||
"128": "logo128.png"
|
"128": "logo128.png"
|
||||||
|
@ -197,7 +197,8 @@
|
|||||||
"productFilter": "0x0204",
|
"productFilter": "0x0204",
|
||||||
"vendorFilter": "0x0d28",
|
"vendorFilter": "0x0d28",
|
||||||
"nameFilter": "^mbed Serial Port",
|
"nameFilter": "^mbed Serial Port",
|
||||||
"log": true
|
"log": true,
|
||||||
|
"chromeExtension": "hjcflblhjoglmjjkecamiegdigfkgeni"
|
||||||
},
|
},
|
||||||
"appTheme": {
|
"appTheme": {
|
||||||
"accentColor": "#5C005C",
|
"accentColor": "#5C005C",
|
||||||
|
Loading…
Reference in New Issue
Block a user