screenshot support in hosted apps
This commit is contained in:
Родитель
d9c38b1a40
Коммит
bdf104434a
|
@ -35,6 +35,7 @@ module TDev {
|
|||
export var isWindows8plus = false;
|
||||
export var isCompiledApp = false;
|
||||
export var isWP8app = false;
|
||||
export var isHosted = false;
|
||||
export var browser = BrowserSoftware.unknown;
|
||||
export var browserVersion = 0;
|
||||
export var browserVersion2 = 0; // not set for pinned iOS apps; look at webkitVersion instead
|
||||
|
@ -113,6 +114,11 @@ module TDev {
|
|||
export function detect() {
|
||||
startTimestamp = new Date().getTime(); // no Util here
|
||||
|
||||
if ((<any>window).touchDevelopExec || (<any>window).mcefQuery) {
|
||||
isHosted = true;
|
||||
Browser.screenshots = true;
|
||||
}
|
||||
|
||||
if ((<any>window).isNodeJS) {
|
||||
isNodeJS = true
|
||||
isHeadless = true
|
||||
|
|
|
@ -191,9 +191,7 @@ module TDev
|
|||
public additionalFullScreenButtons(): HTMLElement[] {
|
||||
var btns = [];
|
||||
if (ScriptEditorWorldInfo.status == "published")
|
||||
btns.push(
|
||||
HTML.mkRoundButton("svg:camera,black", lf("screenshot"), Ticks.wallScreenshot, () => this.takeScreenshot())
|
||||
);
|
||||
btns.push(HTML.mkRoundButton("svg:camera,black", lf("screenshot"), Ticks.wallScreenshot, () => this.takeScreenshot()));
|
||||
return btns;
|
||||
}
|
||||
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
25
lib/App.ts
25
lib/App.ts
|
@ -300,7 +300,7 @@ module TDev.RT {
|
|||
//? Indicates if the `app->host_exec` action can be used to run host commands.
|
||||
//@ betaOnly
|
||||
public has_host(): boolean {
|
||||
return !!(<any>window).mcefQuery || !!(<any>window).touchDevelopExec;
|
||||
return Browser.isHosted;
|
||||
}
|
||||
|
||||
//? Where are we running from: "editor", "website", "nodejs", "mobileapp", "plugin"
|
||||
|
@ -712,20 +712,18 @@ module TDev.RT {
|
|||
return r
|
||||
}
|
||||
|
||||
|
||||
//? Invokes the host to execute a command described in the message and returns the response. There is no restriction on the format of the request and response. If not available or errored, returns invalid.
|
||||
//@ async readsMutable returns(string) betaOnly
|
||||
export function host_exec(message: string, r: ResumeCtx) {
|
||||
export function hostExecAsync(message: string): Promise {
|
||||
return new Promise((onSuccess, onError, onProgress) => {
|
||||
var mcefQuery = (<any>window).mcefQuery;
|
||||
if (mcefQuery) {
|
||||
mcefQuery({
|
||||
request: message,
|
||||
persistent: false,
|
||||
onSuccess: function (response) {
|
||||
r.resumeVal(response);
|
||||
onSuccess(response);
|
||||
},
|
||||
onFailure: function (error_code, error_message) {
|
||||
r.resumeVal(JSON.stringify({ error: error_code, message: error_message }));
|
||||
onSuccess(JSON.stringify({ error: error_code, message: error_message }));
|
||||
}
|
||||
});
|
||||
return;
|
||||
|
@ -734,17 +732,24 @@ module TDev.RT {
|
|||
var exec = (<any>window).touchDevelopExec;
|
||||
if (!exec) {
|
||||
App.log("window.touchDevelopExec function not defined");
|
||||
r.resumeVal(undefined);
|
||||
onSuccess(undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
exec(message, (result) => { r.resumeVal(result); });
|
||||
exec(message,(result) => { onSuccess(result); });
|
||||
}
|
||||
catch (e) {
|
||||
App.logEvent(App.DEBUG, "app", "touchDevelopExec failed", undefined);
|
||||
r.resumeVal(undefined);
|
||||
onSuccess(undefined);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//? Invokes the host to execute a command described in the message and returns the response. There is no restriction on the format of the request and response. If not available or errored, returns invalid.
|
||||
//@ async readsMutable returns(string) betaOnly
|
||||
export function host_exec(message: string, r: ResumeCtx) {
|
||||
return hostExecAsync(message).done(resp => r.resumeVal(resp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
13
lib/Wall.ts
13
lib/Wall.ts
|
@ -470,6 +470,19 @@ module TDev.RT {
|
|||
|
||||
export module ScreenshotManager {
|
||||
export var toScreenshotURLAsync = (rt: RuntimeHost): Promise => { // string {
|
||||
// TODO: move somewhere else
|
||||
if (App.env().has_host()) {
|
||||
var durl: string;
|
||||
return App.hostExecAsync("screen.min")
|
||||
.then(() => new Promise((onSuccess, onError, onProcess) => {
|
||||
Util.setTimeout(100,() => onSuccess(undefined));
|
||||
})).then(() => App.hostExecAsync("screen.screenshot"))
|
||||
.then((url) => {
|
||||
durl = url;
|
||||
return App.hostExecAsync("screen.show");
|
||||
}).then(() => durl);
|
||||
}
|
||||
|
||||
var c = rt.toScreenshotCanvas();
|
||||
try {
|
||||
var data = c ? c.toDataURL('image/png') : undefined;
|
||||
|
|
Загрузка…
Ссылка в новой задаче