Unity Web API 简要文档(翻译,v1.0)

23
2012
# 作者: Ye Xiaoxing / 本文采用CC BY-NC-SA 2.5协议授权,转载请注明本文链接

译者注:这是初三水平的学生翻译的技术文章,文笔比较不像中国话。。请见谅。
Unity Web API 简体中文翻译,根据原文v1.0翻译。 

介绍

Unity Web API(如无额外注明,译文简称API)是一个提供给 Web 程序来与 Ubuntu 桌面整合的工具。这儿是一份开发文档,普通用户适用的关于 webapps 的信息,请点击这里(如无意外,以下所有连接均仅提供英文版本)。对于开发者而言,这个API提供了一些方式使得您的应用在用户的桌面上更好地展现,加强与用户的交互。这些功能包括了信息交互、音乐菜单,甚至是Unity HUD的交互!

这些API目前只在Ubuntu 12.10的Firefox和Chromium中启用,关于如何安装Unity Webapps,请参见WebApps Team的信息(译者注:这个连接在官网上居然是错的。。)。
sudo add-apt-repository ppa:webapps/preview
sudo apt-get update & sudo apt-get install unity-webapps-preview

接下来的阅读大约耗时10分钟,这是一个关于如何整合Web App和 Unity 的简要指南。如果你已经准备好,想要了解更多,请点击这里查看引用文档。
开始
若想要使用API,首先得要告诉Unity你是一个程序。这需要使用到Unity.init方法。
function unityReady() {
// Integrate with Unity!
}
var Unity = external.getUnityObject(1.0);
Unity.init({name: "Unity Web Tutorial",
iconUrl: "http://www.ubuntu.com/tutorialIcon.png",
onInit: unityReady});

如果用户还没有为你的应用启用整合,浏览器会告诉用户程序请求整合,然后如果用户同意,会触发指定的方法。在进一步的调用中,onInit方法会立即被执行。在onInit被触发之前执行API将不会有任何结果。

虽然简单,但是你已经做到了很多!你得到了一个Unity启动器上的空间,以及与Unity的整合。
点这里可以看到Unity.init方法的全部参数。

 
通知
通知接口是最简单的API。
Unity.Notification.showNotification("Attention", "Lorem ipsum dolor sit amet");

这个通知接口可在一个浮动窗口中短暂地显示简短的信息。这些显示的信息不能获得用户的输入。此外为用户着想,这里并不推荐显示重要信息。

更多关于通知接口的信息可以在引用文档中找到。
音乐菜单
媒体应用现在可以与Unity的媒体控制菜单交互,比如在线音乐或视频网站。
var trackInfo = {title: "Synchronous Grabs on my Heart",
album: "Love in the Key of Compiz",
artist: "Sam Spilsbury", artLocation: "http://www.ubuntu.com/exampleCoverArt.svg"}
Unity.MediaPlayer.setTrack(trackInfo);

这将让用户在Unity中可以看到关于播放媒体的信息。 
你的应用也可以响应媒体菜单中的操作:

Unity.MediaPlayer.onNext(onNextTrackCallback);
Unity.MediaPlayer.onPrevious(onPreviousTrackCallback);
Unity.MediaPlayer.onPlaypause(onPlaypauseCallback);

想了解更多信息?点击这里看引用文档,你懂的。

Unity HUD
这可以在Unity HUD中显示你的应用程序能做的事情。对于那些有很复杂的操作的应用来说是很方便的。
这个API是很简单的:
Unity.addAction("/File/Rename", function () {
alert("Got callback");
});

关于Unity.addAction模块的更多信息。。你懂得,在引用文档。

通讯菜单

对于那些通讯工具,像聊天或者邮箱软件,通讯菜单提供用户一个方便的方式查看最近的活动,并能获取更多信息。
Unity.MessagingIndicator.showIndicator("Inbox", {count: numberOfMessages,
callback: viewInboxCallback});
Unity.MessagingIndicator.showIndicator("Check out the Unity Web API", {time: new Date(),
callback: viewMessage});
Unity.MessagingIndicator.addAction("Compose New Message", composeNewMessageCallback);
// Later
Unity.MessagingIndicator.clearIndicator("Check out the Unity Web API");

这个API既可以让你往菜单里显示最近活动,也可以显示相关的操作。
更多:引用文档(我懒得写那么多。。

启动器
这个启动器API可以让你通过图标显示简短的信息。
Unity.Launcher.setCount(3);
Unity.Launcher.setProgress(0.4);
Unity.Launcher.setUrgent(true);
// Later
Unity.Launcher.clearCount();

你也可以使用快捷方式功能,来提供重要的操作或者书签等。如果你的网站或者应用可以简单地分成几个部分,这个API特别有用。
Unity.Launcher.addAction("Science", scienceActionCallback);
Unity.Launcher.addAction("Sports", scienceActionCallback);
Unity.Launcher.addAction("Entertainment", scienceActionCallback);

The complete Unity.Launcher interface is described, of course, in the Reference documentation.
详细的接口当然在引用文档里有咯。。

英文原文:http://developer.ubuntu.com/api/ … vascript/index.html
远景论坛Yexiaoxing原创翻译。

Ye Xiaoxing

一枚苦逼的准高一学生,远景论坛Linux版主

More PostsWebsite

Follow Me:
Twitter

  • 作者: Ye Xiaoxing
  • Post Time: 2012/07/23 8:59:46 下午
  • In: 未分类

9 Responses to Unity Web API 简要文档(翻译,v1.0)

Avatar

yexiaoxing

Firefox 14.0.1 Firefox 14.0.1 Windows 7 Windows 7

七月 23rd, 2012 at 10:45 下午

这篇文章真的被发出来了。。
翻译得很烂,请见谅。

Opera 12.02 Opera 12.02 GNU/Linux GNU/Linux

Jaco Reply:

@yexiaoxing, 歪一下楼,楼主怎么年轻,真好。。

Avatar

yetone

Google Chrome 20.0.1132.57 Google Chrome 20.0.1132.57 GNU/Linux x64 GNU/Linux x64

七月 24th, 2012 at 12:47 上午

竟然只支持12.10.。。。。。。。。。。。。

Firefox 14.0.1 Firefox 14.0.1 Windows 7 Windows 7

Ye Xiaoxing Reply:

@yetone, 其实也支持Ubuntu 12.04,我没写上。。

Avatar

longxia

Google Chrome 20.0.1132.57 Google Chrome 20.0.1132.57 Windows 7 Windows 7

七月 24th, 2012 at 9:53 上午

感谢楼主能为开源事业尽的一份力。

Avatar

freetstar

Firefox 14.0.1 Firefox 14.0.1 GNU/Linux GNU/Linux

七月 24th, 2012 at 2:26 下午

支持,可以考虑在gitcafe上放个repos,然后大家一起翻译

Avatar

freetstar

Firefox 14.0.1 Firefox 14.0.1 GNU/Linux GNU/Linux

七月 24th, 2012 at 2:27 下午

支持,可以考虑在gitcafe上放个repos,然后大家一起翻译

Avatar

小雨

Google Chrome 20.0.1132.57 Google Chrome 20.0.1132.57 Windows 7 x64 Edition Windows 7 x64 Edition

七月 27th, 2012 at 8:25 下午

初中水平的翻译真是压力

Avatar

FreeBSD

Epiphany 2.30.6 Epiphany 2.30.6 FreeBSD FreeBSD

七月 28th, 2012 at 11:31 下午

FreeBSD

Avatar

lowatt

Google Chrome 19.0.1084.56 Google Chrome 19.0.1084.56 Windows 7 Windows 7

八月 29th, 2012 at 12:39 下午

好了, 大家可以回家学英语去了~

top