Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add systemInfo API sample #49

Merged
merged 1 commit into from

2 participants

Hongbo Min Paul Kinlan
Hongbo Min

No description provided.

Paul Kinlan
Owner

Hi @hmin

Thanks for this, and very sorry for the delay. To accept your first submission we need to have this signed: http://code.google.com/legal/corporate-cla-v1.0.html

If Intel has already done this, let me know and I will get it merged immediately.

Thanks,

Paul Kinlan PaulKinlan merged commit 106c4a4 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 22, 2012
This page is out of date. Refresh to see the latest.
28 systemInfo/index.html
View
@@ -0,0 +1,28 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<title> System Information </title>
+<script src="systemInfo.js"></script>
+</head>
+<body>
+<h2><b>CPU Information</b></h2>
+<div id="cpu-info">
+ <i> Loading ...</i>
+</div>
+<div id="cpu-cores">
+ <i> <br>Loading ...</i>
+</div>
+<h2><b>Memory Information</b></h2>
+<div id="memory-info">
+ <i>Loading...</i>
+</div>
+<h2><b>Storage Information</b></h2>
+<div>
+ <i>Monitor free space change? </i>
+ <input type="button" value="Start" id="start-btn"></input>
+ <input type="button" value="Stop" id="stop-btn"></input>
+</div>
+<div id="storage-list">
+ <i>Loading ...</i>
+</div>
+</body>
+</html>
18 systemInfo/main.js
View
@@ -0,0 +1,18 @@
+/**
+ * Copyright (c) 2012 The Chromium Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ **/
+
+
+/**
+ * Listens for the app launching then creates the window
+ *
+ * @see http://developer.chrome.com/trunk/apps/app.window.html
+ */
+ chrome.app.runtime.onLaunched.addListener(function() {
+ chrome.app.window.create('index.html', {
+ height: 550,
+ width: 800
+ });
+});
13 systemInfo/manifest.json
View
@@ -0,0 +1,13 @@
+{
+ "name": "SystemInfo Sample",
+ "version": "0.1",
+ "permissions": ["experimental"],
+ "minimum_chrome_version": "23",
+ "manifest_version": 2,
+ "description": "Show disk capacity via SystemInfo API",
+ "app": {
+ "background": {
+ "scripts": ["main.js"]
+ }
+ }
+}
99 systemInfo/systemInfo.js
View
@@ -0,0 +1,99 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var systemInfo = chrome.experimental.systemInfo;
+
+var indicator = {}
+var isStarted = false;
+
+function onStorageChanged(info) {
+ var elem = document.getElementById(info.id);
+ if (indicator[info.id]++ % 2)
+ elem.bgColor = "green";
+ else
+ elem.bgColor = "white";
+ elem.innerHTML = info.availableCapacity;
+}
+
+function startMonitor() {
+ if (isStarted) return;
+ systemInfo.storage.onAvailableCapacityChanged.addListener(onStorageChanged);
+ isStarted = true;
+}
+
+function stopMonitor() {
+ if (!isStarted) return;
+ systemInfo.storage.onAvailableCapacityChanged.removeListener(
+ onStorageChanged);
+ isStarted = false;
+}
+
+function showStorageInfo(unit) {
+ table = "<tr><td>" + unit.id + "</td>" +
+ "<td>" + unit.type + "</td>" +
+ "<td>" + Math.round(unit.capacity/1024) + "</td>" +
+ "<td id=" + "\"" + unit.id + "\">" +
+ Math.round(unit.availableCapacity/1024) +
+ "</td></tr>\n";
+ return table;
+}
+
+function init() {
+ document.getElementById("start-btn").onclick = startMonitor;
+ document.getElementById("stop-btn").onclick = stopMonitor;
+
+ // Get CPU information.
+ chrome.experimental.systemInfo.cpu.get(function(cpu) {
+ var cpuInfo = "<b>Architecture:</b> " + cpu.archName +
+ "<br><b>Model Name: </b>" + cpu.modelName +
+ "<br><b>Number of Processors: </b>" + cpu.numOfProcessors;
+ var div = document.getElementById("cpu-info");
+ div.innerHTML = cpuInfo;
+ });
+ chrome.experimental.systemInfo.cpu.onUpdated.addListener(function(info) {
+ var table = "<br><table border=\"1\">\n" +
+ "<tr><td width=\"80px\"><b>Index</b></td>";
+ for (var i = 0; i < info.usagePerProcessor.length; i++) {
+ table += "<td width=\"120px\"><b>" + i + "</b></td>";
+ }
+ table += "<td width=\"120px\"><b>Total</b></td></tr>\n";
+ table += "<tr><td><b>History Usage</b></td>";
+ for (var i = 0; i < info.usagePerProcessor.length; i++) {
+ table += "<td>" + Math.round(info.usagePerProcessor[i]) + "</td>";
+ }
+ table += "<td>" + Math.round(info.averageUsage) + "</td></tr>";
+ table += "</table>\n";
+ var div = document.getElementById("cpu-cores");
+ div.innerHTML = table;
+ });
+
+ // Get memory information.
+ chrome.experimental.systemInfo.memory.get(function(memory) {
+ var memoryInfo =
+ "<b>Total Capacity:</b> " + Math.round(memory.capacity / 1024) + "KB" +
+ "<br><b>Available Capacity: </b>" +
+ Math.round(memory.availableCapacity / 1024) + "KB"
+ var div = document.getElementById("memory-info");
+ div.innerHTML = memoryInfo;
+ });
+
+ // Get storage information.
+ chrome.experimental.systemInfo.storage.get(function(units) {
+ var table = "<table width=65% border=\"1\">\n" +
+ "<tr><td><b>ID</b></td>" +
+ "<td><b>Type</b></td>" +
+ "<td><b>Total Capacity (KB)</b></td>" +
+ "<td><b>Available Capacity (KB)</b></td>" +
+ "</tr>\n";
+ for (var i = 0; i < units.length; i++) {
+ indicator[units[i].id] = 0;
+ table += showStorageInfo(units[i]);
+ }
+ table += "</table>\n";
+ var div = document.getElementById("storage-list");
+ div.innerHTML = table;
+ });
+}
+
+document.addEventListener('DOMContentLoaded', init);
Something went wrong with that request. Please try again.