From e3a3d80a639123fb2c53fa13bb664c985b38645c Mon Sep 17 00:00:00 2001 From: mzsm Date: Thu, 16 Oct 2014 02:47:03 +0900 Subject: [PATCH] add chrome.fileSystem --- chrome/chrome-app-tests.ts | 29 +++++++++++++++++++++ chrome/chrome-app.d.ts | 52 +++++++++++++++++++++++++++++++++++--- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/chrome/chrome-app-tests.ts b/chrome/chrome-app-tests.ts index 12dc7b97db..851bc27ba6 100644 --- a/chrome/chrome-app-tests.ts +++ b/chrome/chrome-app-tests.ts @@ -26,6 +26,35 @@ chrome.app.runtime.onRestarted.addListener(function () { return; }); // Get Current Window var currentWindow: cwindow.AppWindow = chrome.app.window.current(); +// FileSystem +// https://developer.chrome.com/apps/fileSystem + +function test_fileSystem(): void { + var accepts: chrome.fileSystem.AcceptOptions[] = [ + {mimeTypes: ["text/*"], extensions: ['js', 'css', 'txt', 'html', 'xml', 'tsv', 'csv', 'rtf']} + ]; + var chooseOption: chrome.fileSystem.ChooseEntryOptions = { + type: "openFile", + suggestedName: "foo.txt", + accepts: accepts, + acceptsAllTypes: false, + acceptsMultiple: false + }; + chrome.fileSystem.chooseEntry(chooseOption, (entry: Entry) => { + chrome.fileSystem.getDisplayPath(entry, (displayPath: string) => { }); + + var retainedId = chrome.fileSystem.retainEntry(entry); + chrome.fileSystem.isRestorable(retainedId, (isRestorable: boolean) => { + if(isRestorable){ + chrome.fileSystem.restoreEntry(retainedId, (restoredEntry: Entry) => { }); + } + }); + + chrome.fileSystem.getWritableEntry(entry, (writableEntry: Entry) => {}); + chrome.fileSystem.isWritableEntry(entry, (isWritable: boolean) => {}); + }); +} + // Sockets // https://developer.chrome.com/apps/sockets_tcp function test_socketsTcp(): void { diff --git a/chrome/chrome-app.d.ts b/chrome/chrome-app.d.ts index 830b26e4fd..9299e125c7 100644 --- a/chrome/chrome-app.d.ts +++ b/chrome/chrome-app.d.ts @@ -1,8 +1,10 @@ // Type definitions for Chrome packaged application development // Project: http://developer.chrome.com/apps/ -// Definitions by: Adam Lay , MIZUNE Pine +// Definitions by: Adam Lay , MIZUNE Pine , MIZUSHIMA Junki // Definitions: https://github.com/borisyankov/DefinitelyTyped +/// + //////////////////// // App Runtime //////////////////// @@ -21,11 +23,11 @@ declare module chrome.app.runtime { } interface LaunchedEvent { - addListener(callback: (launchData: LaunchData) => void); + addListener(callback: (launchData: LaunchData) => void): void; } interface RestartedEvent { - addListener(callback: () => void); + addListener(callback: () => void): void; } var onLaunched: LaunchedEvent; @@ -94,6 +96,50 @@ declare module chrome.app.window { var onRestored: WindowEvent; } +//////////////////// +// fileSystem +//////////////////// +declare module chrome.fileSystem { + + interface ChildChangeInfo { + entry: Entry; + type: string; + } + + interface EntryChangedEvent { + target: Entry; + childChanges?: ChildChangeInfo[]; + } + + interface EntryRemovedEvent { + target: Entry; + } + + interface AcceptOptions { + description?: string; + mimeTypes?: string[]; + extensions?: string[]; + } + + interface ChooseEntryOptions { + type?: string; + suggestedName?: string; + accepts?: AcceptOptions[]; + acceptsAllTypes?: boolean; + acceptsMultiple?: boolean; + } + + export function getDisplayPath(entry: Entry, callback: (displayPath: string) => void): void; + export function getWritableEntry(entry: Entry, callback: (entry: Entry) => void): void; + export function isWritableEntry(entry: Entry, callback: (isWritable: boolean) => void): void; + export function chooseEntry(callback: (entry: Entry) => void): void; + export function chooseEntry(callback: (fileEntries: FileEntry[]) => void): void; + export function chooseEntry(options: ChooseEntryOptions, callback: (entry: Entry) => void): void; + export function chooseEntry(options: ChooseEntryOptions, callback: (fileEntries: FileEntry[]) => void): void; + export function restoreEntry(id: string, callback: (entry: Entry) => void): void; + export function isRestorable(id: string, callback: (isRestorable: boolean) => void): void; + export function retainEntry(entry: Entry): string; +} //////////////////// // Sockets