From 31c7908e57c01e04acfcb744eba67ed793fb2c12 Mon Sep 17 00:00:00 2001 From: Adam Lay Date: Mon, 30 Sep 2013 23:08:15 +0100 Subject: [PATCH 1/3] Adding Chrome App Definitions Includes definitions for app.runtime and app.window. --- chrome/chrome.d.ts | 93 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/chrome/chrome.d.ts b/chrome/chrome.d.ts index 3a01db6c1c..1aa91a2de5 100644 --- a/chrome/chrome.d.ts +++ b/chrome/chrome.d.ts @@ -2,6 +2,8 @@ // Project: http://developer.chrome.com/extensions/ // Definitions by: Matthew Kimber // Definitions: https://github.com/borisyankov/DefinitelyTyped +// Chrome App: http://developer.chrome.com/apps/api_index.html +// Definitions: Adam Lay //////////////////// // Alarms @@ -34,6 +36,97 @@ declare module chrome.alarms { var onAlarm: AlarmEvent; } +//////////////////// +// App Runtime +//////////////////// +declare module chrome.app.runtime { + interface LaunchData { + id?: string; + items?: LaunchDataItem[]; + url?: string; + referrerUrl?: string; + isKioskSession?: boolean; + } + + interface LaunchDataItem { + entry: File; + type: string; + } + + interface LaunchedEvent { + addListener(callback: (launchData: LaunchData) => void); + } + + interface RestartedEvent { + addListener(callback: () => void); + } + + var onLaunched: LaunchedEvent; + var onRestarted: RestartedEvent; +} + +//////////////////// +// App Window +//////////////////// +declare module chrome.app.window { + interface Bounds { + left?: number; + top?: number; + width?: number; + height?: number; + } + + interface AppWindow { + focus: () => void; + fullscreen: () => void; + isFullscreen: () => boolean; + minimize: () => void; + isMinimized: () => boolean; + maximize: () => void; + isMaximized: () => boolean; + restore: () => void; + moveTo: (left: number, top: number) => void; + resizeTo: (width: number, height: number) => void; + drawAttention: () => void; + clearAttention: () => void; + close: () => void; + show: () => void; + hide: () => void; + getBounds: () => Bounds; + setBounds: (bounds: Bounds) => void; + contentWindow: Window; + } + + interface CreateOptions { + id?: string; + minWidth?: number; + minHeight?: number; + maxWidth?: number; + maxHeight?: number; + frame?: string; // "none", "chrome" + bounds?: Bounds; + transparentBackground?: boolean; + state?: string; // "normal", "fullscreen", "maximized", "minimized" + hidden?: boolean; + resizable?: boolean; + singleton?: boolean; + } + + export function create(url: string, options?: CreateOptions, callback?: (created_window: AppWindow) => void): void; + export function current(): AppWindow; + + interface WindowEvent { + addListener(callback: () => void): void; + } + + var onBoundsChanged: WindowEvent; + var onClosed: WindowEvent; + var onFullscreened: WindowEvent; + var onMaximized: WindowEvent; + var onMinimized: WindowEvent; + var onRestored: WindowEvent; +} + //////////////////// // Bookmarks //////////////////// From 60a1057fbfeb2d5d9f9d2c70cc9e5bc127467056 Mon Sep 17 00:00:00 2001 From: Adam Lay Date: Mon, 30 Sep 2013 23:25:57 +0100 Subject: [PATCH 2/3] Adding Chrome App Definitions Adding Chrome packaged application definitions. --- chrome/chrome-app.d.ts | 95 ++++++++++++++++++++++++++++++++++++++++++ chrome/chrome.d.ts | 93 ----------------------------------------- 2 files changed, 95 insertions(+), 93 deletions(-) create mode 100644 chrome/chrome-app.d.ts diff --git a/chrome/chrome-app.d.ts b/chrome/chrome-app.d.ts new file mode 100644 index 0000000000..c8dd2e6d46 --- /dev/null +++ b/chrome/chrome-app.d.ts @@ -0,0 +1,95 @@ +// Type definitions for Chrome packaged application development. +// Project: http://developer.chrome.com/apps/ +// Definitions by: Adam Lay +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +//////////////////// +// App Runtime +//////////////////// +declare module chrome.app.runtime { + interface LaunchData { + id?: string; + items?: LaunchDataItem[]; + url?: string; + referrerUrl?: string; + isKioskSession?: boolean; + } + + interface LaunchDataItem { + entry: File; + type: string; + } + + interface LaunchedEvent { + addListener(callback: (launchData: LaunchData) => void); + } + + interface RestartedEvent { + addListener(callback: () => void); + } + + var onLaunched: LaunchedEvent; + var onRestarted: RestartedEvent; +} + +//////////////////// +// App Window +//////////////////// +declare module chrome.app.window { + interface Bounds { + left?: number; + top?: number; + width?: number; + height?: number; + } + + interface AppWindow { + focus: () => void; + fullscreen: () => void; + isFullscreen: () => boolean; + minimize: () => void; + isMinimized: () => boolean; + maximize: () => void; + isMaximized: () => boolean; + restore: () => void; + moveTo: (left: number, top: number) => void; + resizeTo: (width: number, height: number) => void; + drawAttention: () => void; + clearAttention: () => void; + close: () => void; + show: () => void; + hide: () => void; + getBounds: () => Bounds; + setBounds: (bounds: Bounds) => void; + contentWindow: Window; + } + + interface CreateOptions { + id?: string; + minWidth?: number; + minHeight?: number; + maxWidth?: number; + maxHeight?: number; + frame?: string; // "none", "chrome" + bounds?: Bounds; + transparentBackground?: boolean; + state?: string; // "normal", "fullscreen", "maximized", "minimized" + hidden?: boolean; + resizable?: boolean; + singleton?: boolean; + } + + export function create(url: string, options?: CreateOptions, callback?: (created_window: AppWindow) => void): void; + export function current(): AppWindow; + + interface WindowEvent { + addListener(callback: () => void): void; + } + + var onBoundsChanged: WindowEvent; + var onClosed: WindowEvent; + var onFullscreened: WindowEvent; + var onMaximized: WindowEvent; + var onMinimized: WindowEvent; + var onRestored: WindowEvent; +} \ No newline at end of file diff --git a/chrome/chrome.d.ts b/chrome/chrome.d.ts index 1aa91a2de5..3a01db6c1c 100644 --- a/chrome/chrome.d.ts +++ b/chrome/chrome.d.ts @@ -2,8 +2,6 @@ // Project: http://developer.chrome.com/extensions/ // Definitions by: Matthew Kimber // Definitions: https://github.com/borisyankov/DefinitelyTyped -// Chrome App: http://developer.chrome.com/apps/api_index.html -// Definitions: Adam Lay //////////////////// // Alarms @@ -36,97 +34,6 @@ declare module chrome.alarms { var onAlarm: AlarmEvent; } -//////////////////// -// App Runtime -//////////////////// -declare module chrome.app.runtime { - interface LaunchData { - id?: string; - items?: LaunchDataItem[]; - url?: string; - referrerUrl?: string; - isKioskSession?: boolean; - } - - interface LaunchDataItem { - entry: File; - type: string; - } - - interface LaunchedEvent { - addListener(callback: (launchData: LaunchData) => void); - } - - interface RestartedEvent { - addListener(callback: () => void); - } - - var onLaunched: LaunchedEvent; - var onRestarted: RestartedEvent; -} - -//////////////////// -// App Window -//////////////////// -declare module chrome.app.window { - interface Bounds { - left?: number; - top?: number; - width?: number; - height?: number; - } - - interface AppWindow { - focus: () => void; - fullscreen: () => void; - isFullscreen: () => boolean; - minimize: () => void; - isMinimized: () => boolean; - maximize: () => void; - isMaximized: () => boolean; - restore: () => void; - moveTo: (left: number, top: number) => void; - resizeTo: (width: number, height: number) => void; - drawAttention: () => void; - clearAttention: () => void; - close: () => void; - show: () => void; - hide: () => void; - getBounds: () => Bounds; - setBounds: (bounds: Bounds) => void; - contentWindow: Window; - } - - interface CreateOptions { - id?: string; - minWidth?: number; - minHeight?: number; - maxWidth?: number; - maxHeight?: number; - frame?: string; // "none", "chrome" - bounds?: Bounds; - transparentBackground?: boolean; - state?: string; // "normal", "fullscreen", "maximized", "minimized" - hidden?: boolean; - resizable?: boolean; - singleton?: boolean; - } - - export function create(url: string, options?: CreateOptions, callback?: (created_window: AppWindow) => void): void; - export function current(): AppWindow; - - interface WindowEvent { - addListener(callback: () => void): void; - } - - var onBoundsChanged: WindowEvent; - var onClosed: WindowEvent; - var onFullscreened: WindowEvent; - var onMaximized: WindowEvent; - var onMinimized: WindowEvent; - var onRestored: WindowEvent; -} - //////////////////// // Bookmarks //////////////////// From 229b4c5211be67b9a70e966eae6de74d23557dff Mon Sep 17 00:00:00 2001 From: Adam Lay Date: Mon, 30 Sep 2013 23:46:02 +0100 Subject: [PATCH 3/3] Added Chrome App Tests Added Chrome app tests file and amended Readme. --- README.md | 1 + chrome/chrome-app-tests.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 chrome/chrome-app-tests.ts diff --git a/README.md b/README.md index 59104d4d55..f67a3bae54 100755 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ List of Definitions * [Cheerio](https://github.com/MatthewMueller/cheerio) (by [Bret Little](https://github.com/blittle)) * [Chosen](http://harvesthq.github.com/chosen/) (by [Boris Yankov](https://github.com/borisyankov)) * [Chrome](http://developer.chrome.com/extensions/) (by [Matthew Kimber](https://github.com/matthewkimber)) +* [Chrome App](http://developer.chrome.com/apps/) (by [Adam Lay](https://github.com/AdamLay)) * [CodeMirror](http://codemirror.net) (by [François de Campredon](https://github.com/fdecampredon)) * [Commander](http://github.com/visionmedia/commander.js) (by [Marcelo Dezem](https://github.com/mdezem)) * [d3.js](http://d3js.org/) (from TypeScript samples) diff --git a/chrome/chrome-app-tests.ts b/chrome/chrome-app-tests.ts new file mode 100644 index 0000000000..0ae0ae2af4 --- /dev/null +++ b/chrome/chrome-app-tests.ts @@ -0,0 +1,27 @@ +/// + +import runtime = chrome.app.runtime; +import cwindow = chrome.app.window; + +var createOptions: cwindow.CreateOptions = { + id: "My Window", + bounds: { + left: 0, + top: 0, + width: 640, + height: 480 + }, + resizable: true +}; + +//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) { + return; + }); +}); + +chrome.app.runtime.onRestarted.addListener(function () { return; }); + +// Get Current Window +var currentWindow: cwindow.AppWindow = chrome.app.window.current(); \ No newline at end of file