Chrome-apps better coverage, cleanup and fixes (#27849)

* Bugfixes: Webview is an HTMLElement and also frame must be of type chrome to set options

* Bugfixes: Webview is an HTMLElement and also frame must be of type chrome to set options

* Bluetooth Socket: typings complete

* Bluetooth tests

* Fix typo

* Typo fix

* HID typings, but missing documentation

* Documentation and testing added

* InstanceID Typings

* Typings for mdns complete

* typings for chrome.syncFileSystem

* Major cleanup - comments and documentation review

* More cleanup, comment shortening, bugfixing, updates

* Cleanup and fixes: Continued (WIP)

* Fixed and cleanup: idle, instanceId, mediaGalleries (+added docs)

* Transfer types to enums

* networking.onc -> complete api typing, Enums to types to prevent runtime errors

* Restored enums that are present (after checking)

* Implemented desktopCapture

* Added management

* Typings for experimental clipboard api

* chrome.networking.onc: Documentation + fixes

* Removed unnecessary imports and compiler options.

* Bumped typescript version to support new language features.

* Cleanup: No need to specify defaults
This commit is contained in:
Nikolai Ommundsen
2018-08-03 10:59:09 -07:00
committed by Sheetal Nandi
parent c64a754835
commit fb1b2554a8
2 changed files with 4897 additions and 2071 deletions
+4695 -2042
View File
File diff suppressed because it is too large Load Diff
+202 -29
View File
@@ -1,8 +1,8 @@
import runtime = chrome.app.runtime;
import cwindow = chrome.app.window;
const cwindow = chrome.app.window;
const createOptions: cwindow.CreateWindowOptions = {
id: "My Window",
const createOptions: chrome.app.CreateWindowOptions = {
id: 'My Window',
bounds: {
left: 0,
top: 0,
@@ -14,7 +14,7 @@ const createOptions: cwindow.CreateWindowOptions = {
//Create new window on app launch
chrome.app.runtime.onLaunched.addListener(function (launchData: runtime.LaunchData) {
chrome.app.window.create('app/url', createOptions, function (created_window: cwindow.AppWindow) {
chrome.app.window.create('app/url', createOptions, function (created_window: chrome.app.AppWindow) {
return;
});
});
@@ -22,9 +22,9 @@ chrome.app.runtime.onLaunched.addListener(function (launchData: runtime.LaunchDa
chrome.app.runtime.onRestarted.addListener(function () { return; });
// retrieving windows
var currentWindow: cwindow.AppWindow = chrome.app.window.current();
var otherWindow: cwindow.AppWindow = chrome.app.window.get('some-string');
var allWindows: cwindow.AppWindow[] = chrome.app.window.getAll();
var currentWindow: chrome.app.AppWindow = chrome.app.window.current();
var otherWindow: chrome.app.AppWindow = chrome.app.window.get('some-string');
var allWindows: chrome.app.AppWindow[] = chrome.app.window.getAll();
// listening to window events
currentWindow.onBoundsChanged.addListener(function () { return; });
@@ -42,11 +42,11 @@ var visibleEverywhere: boolean = chrome.app.window.canSetVisibleOnAllWorkspaces(
function test_fileSystem(): void {
var accepts: chrome.fileSystem.AcceptOptions[] = [
{ mimeTypes: ["text/*"], extensions: ['js', 'css', 'txt', 'html', 'xml', 'tsv', 'csv', 'rtf'] }
{ mimeTypes: ['text/*'], extensions: ['js', 'css', 'txt', 'html', 'xml', 'tsv', 'csv', 'rtf'] }
];
var chooseOption: chrome.fileSystem.ChooseEntryOptions = {
type: "openFile",
suggestedName: "foo.txt",
type: 'openFile',
suggestedName: 'foo.txt',
accepts: accepts,
acceptsAllTypes: false,
acceptsMultiple: false
@@ -98,7 +98,7 @@ function test_socketsTcp(): void {
chrome.sockets.tcp.setNoDelay(socketId, true, (result: number) => { });
// connect
chrome.sockets.tcp.connect(socketId, "192.168.0.1", 8080, (result: number) => { });
chrome.sockets.tcp.connect(socketId, '192.168.0.1', 8080, (result: number) => { });
// disconnect
chrome.sockets.tcp.disconnect(socketId);
@@ -132,7 +132,7 @@ function testSocketsTcpTypes(): void {
properties = {
persistent: true,
name: "test",
name: 'test',
bufferSize: 1024
};
@@ -146,11 +146,11 @@ function testSocketsTcpTypes(): void {
connected: false
};
socketInfo.name = "test";
socketInfo.name = 'test';
socketInfo.bufferSize = 1024;
socketInfo.localAddress = "192.168.0.2";
socketInfo.localAddress = '192.168.0.2';
socketInfo.localPort = 8000;
socketInfo.peerAddress = "192.168.0.3";
socketInfo.peerAddress = '192.168.0.3';
socketInfo.peerPort = 1000;
}
@@ -178,10 +178,10 @@ function test_socketsUdp(): void {
chrome.sockets.udp.setPaused(socketId, true, () => { });
// bind
chrome.sockets.udp.bind(socketId, "0.0.0.0", 8080, (result: number) => { });
chrome.sockets.udp.bind(socketId, '0.0.0.0', 8080, (result: number) => { });
// send
chrome.sockets.udp.send(socketId, buffer, "172.21.0.1", 10080, (info: chrome.sockets.udp.SendInfo) => { });
chrome.sockets.udp.send(socketId, buffer, '172.21.0.1', 10080, (info: chrome.sockets.udp.SendInfo) => { });
// close
chrome.sockets.udp.close(socketId);
@@ -194,10 +194,10 @@ function test_socketsUdp(): void {
chrome.sockets.udp.getSockets((infos: chrome.sockets.udp.SocketInfo[]) => { });
// joinGroup
chrome.sockets.udp.joinGroup(socketId, "224.0.0.1", (result: number) => { });
chrome.sockets.udp.joinGroup(socketId, '224.0.0.1', (result: number) => { });
// leaveGroup
chrome.sockets.udp.leaveGroup(socketId, "224.0.0.1", (result: number) => { });
chrome.sockets.udp.leaveGroup(socketId, '224.0.0.1', (result: number) => { });
// setMulticastTimeToLive
chrome.sockets.udp.setMulticastTimeToLive(socketId, 100, (result: number) => { });
@@ -223,7 +223,7 @@ function testSocketsUdpTypes(): void {
properties = {
persistent: true,
name: "test",
name: 'test',
bufferSize: 1024
};
@@ -236,9 +236,9 @@ function testSocketsUdpTypes(): void {
paused: true
};
socketInfo.name = "test";
socketInfo.name = 'test';
socketInfo.bufferSize = 1024;
socketInfo.localAddress = "192.168.0.2";
socketInfo.localAddress = '192.168.0.2';
socketInfo.localPort = 8000;
}
@@ -266,8 +266,8 @@ function test_socketsTcpServer(): void {
chrome.sockets.tcpServer.setPaused(socketId, true, () => { });
// listen
chrome.sockets.tcpServer.listen(socketId, "0.0.0.0", 80, (result: number) => { });
chrome.sockets.tcpServer.listen(socketId, "0.0.0.0", 80, 128, (result: number) => { });
chrome.sockets.tcpServer.listen(socketId, '0.0.0.0', 80, (result: number) => { });
chrome.sockets.tcpServer.listen(socketId, '0.0.0.0', 80, 128, (result: number) => { });
// disconnect
chrome.sockets.tcp.disconnect(socketId);
@@ -298,7 +298,7 @@ function testSocketsTcpServerTypes(): void {
properties = {
persistent: true,
name: "test"
name: 'test'
};
// SocketInfo
@@ -310,8 +310,8 @@ function testSocketsTcpServerTypes(): void {
paused: true
};
socketInfo.name = "test";
socketInfo.localAddress = "192.168.0.2";
socketInfo.name = 'test';
socketInfo.localAddress = '192.168.0.2';
socketInfo.localPort = 8000;
}
@@ -340,7 +340,7 @@ wve.addEventListener('close', () => {
return;
});
wve.addEventListener('consolemessage', (ev) => {
if (ev.level === chrome.webview.ConsoleMessageLevel.LOG_ERROR) {
if (ev.level === 2) {
const msg = ev.message;
}
});
@@ -360,4 +360,177 @@ wve.addEventListener('loadredirect', (ev) => {
return ev.newUrl || ev.oldUrl;
});
chrome.bluetoothLowEnergy.connect('1111111', () => { });
chrome.bluetooth.getAdapterState((adapter) => {
console.log('Adapter ' + adapter.address + ': ' + adapter.name);
});
chrome.bluetooth.getDevices((devices) => {
for (const device of devices) {
console.log(device.address);
}
});
chrome.bluetooth.onDeviceAdded.addListener((device) => {
let uuid = '0000180d-0000-1000-8000-00805f9b34fb';
if (!device.uuids || device.uuids.indexOf(uuid) < 0)
return;
// The device has a service with the desired UUID.
chrome.bluetoothLowEnergy.connect(device.address, () => {
if (chrome.runtime.lastError) {
console.log('Failed to connect: ' + chrome.runtime.lastError.message);
return;
}
// Connected! Do stuff...
});
});
const uuid = '1105';
chrome.bluetooth.getDevices((devices) => {
chrome.bluetoothSocket.create((createInfo) => {
chrome.bluetoothSocket.connect(createInfo.socketId,
devices[0].address, uuid, () => {
if (chrome.runtime.lastError) {
console.log('Connection failed: ' + chrome.runtime.lastError.message);
} else {
chrome.bluetoothSocket.send(createInfo.socketId, new ArrayBuffer(4096), (bytes_sent) => {
if (chrome.runtime.lastError) {
console.log('Send failed: ' + chrome.runtime.lastError.message);
} else {
console.log('Sent ' + bytes_sent + ' bytes')
}
});
}
});
chrome.bluetoothSocket.onReceive.addListener((receiveInfo) => {
if (receiveInfo.socketId != createInfo.socketId)
return;
// receiveInfo.data is an ArrayBuffer.
});
});
});
chrome.hid.getDevices({
filters: [
{ vendorId: 5 }
]
}, (devices) => {
const productId = devices[0].productId;
chrome.hid.getUserSelectedDevices((selectedDevices) => {
const hmm = selectedDevices.productId == productId ? selectedDevices.vendorId : selectedDevices.maxFeatureReportSize;
});
});
chrome.syncFileSystem.getConflictResolutionPolicy((policy) => {
if (policy === 'manual') {
chrome.syncFileSystem.requestFileSystem((fs) => {
if (fs.root.isFile) {
throw new Error('It was a file!');
}
});
}
})
chrome.contextMenus.ACTION_MENU_TOP_LEVEL_LIMIT;
chrome.i18n.getMessage('click_here', ['string1', 'string2']);
const TLSFormatExample = {
NetworkConfigurations: <chrome.networking.onc.NetworkConfigProperties>
{
GUID: '{00f79111-51e0-e6e0-76b3b55450d80a1b}',
Name: 'MyTTLSNetwork',
Type: 'WiFi',
WiFi: {
AutoConnect: false,
EAP: {
ClientCertPattern: {
EnrollmentURI: [
'http://fetch-my-certificate.com'
],
IssuerCARef: [
'{6ed8dce9-64c8-d568-d225d7e467e37828}'
]
},
'ClientCertType': 'Pattern',
'Outer': 'EAP-TLS',
'ServerCARef': '{6ed8dce9-64c8-d568-d225d7e467e37828}',
'UseSystemCAs': true
},
'HiddenSSID': false,
'SSID': 'MyTTLSNetwork',
'Security': 'WPA-EAP'
}
}
}
let serviceId: any = null;
const runApp = () => {
var options = {
'id': 'Bluetooth Sample App',
'bounds': {
'width': 1024,
'height': 768
}
};
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.serviceId) {
serviceId = request.serviceId;
console.log('Received registered service Id: ' + serviceId);
}
});
chrome.app.window.create('test.html', options, (theWindow) => {
theWindow.onClosed.addListener(() => {
if (serviceId) {
console.log('Unregistering service: ' + serviceId);
chrome.bluetoothLowEnergy.unregisterService(serviceId, (status) => {
console.log('Unregister service status = ' + status);
});
}
});
});
}
chrome.app.runtime.onLaunched.addListener(runApp);
chrome.app.runtime.onRestarted.addListener(runApp);
// networking.onc
chrome.networking.onc.getNetworks({ 'networkType': 'All' }, (networkList) => {
console.log('Length of Network list: ' + networkList.length);
for (let networkObj of networkList) {
console.log('GUID: ' + networkObj.GUID);
console.log('Connectable: ' + networkObj.Connectable);
if (networkObj.WiFi) {
// WiFi active :)
console.log('Wifi BSID: ' + networkObj.WiFi.BSSID);
}
chrome.networking.onc.setProperties(networkObj.GUID || '', {
WiFi: {
Passphrase: 'Can be set :) but not get?'
}
})
// Test that we can't get passphrase
chrome.networking.onc.getProperties(networkObj.GUID || '', (props) => {
const WiFiResult = props.WiFi;
});
}
});
//// AUDIO
chrome.audio.getDevices({}, (audioDeviceInfoList) => {
for (let audioObj of audioDeviceInfoList) {
console.log('ID: ' + audioObj.id);
console.log('Audio Stream Type: ' + audioObj.streamType);
console.log('Audio Device Name: ' + audioObj.deviceName);
}
});
chrome.desktopCapture.chooseDesktopMedia(["screen", "window", "tab"], () => { });
chrome.desktopCapture.chooseDesktopMedia([chrome.desktopCapture.DesktopCaptureSourceType.AUDIO], () => { });