首先通过例子的gears_init.js生成一个Google Gears对象:google.gears
后面所有的操作通过这个对象进行。这个就直接抄gears_init.js实现,自己不用做任何处理了。
对google.gears对象的判断:
if (!window.google || !google.gears) {
textOut("NOTE: You must install Gears first."); --- 提示没有安装google gear,
} else { ---- 安装了google gear,生成自己的localserver和store
localServer = google.gears.factory.create("beta.localserver");
store = localServer.createManagedStore(STORE_NAME);
textOut("Yeay, Gears is already installed.");
}
其中的:STORE_NAME就是一个自己随意取的名字;
MANIFEST的文件,在create store的时候使用到
if (!window.google || !google.gears) { --- 判断是否安装了gear
alert("You must install Gears first.");
return;
}
store.manifestUrl = MANIFEST_FILENAME; --- 这个就是定义manifest文件名字的,而且mainfest的文件,要和当前的页面放在同一个目录中(如果没有设置目录的话)
store.checkForUpdate(); --- 对store的创建更新
var timerId = window.setInterval(function() { --- 这是一个把更新的状态显示出来的脚本
// When the currentVersion property has a value, all of the resources
// listed in the manifest file for that version are captured. There is
// an open bug to surface this state change as an event.
if (store.currentVersion) {
window.clearInterval(timerId);
textOut("The documents are now available offline.\n" +
"With your browser offline, load the document at " +
"its normal online URL to see the locally stored " +
"version. The version stored is: " +
store.currentVersion);
} else if (store.updateStatus == 3) {
textOut("Error: " + store.lastErrorMessage);
}
}, 500);
删除一个store也是相当容易的:
if (!window.google || !google.gears) {
alert("You must install Gears first.");
return;
}
localServer.removeManagedStore(STORE_NAME); --- 删除,这个STORE_NAME就是上面创建时候的STORE NAME
textOut("Done. The local store has been removed." +
"You will now see online versions of the documents.");
没有评论:
发表评论