mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 19:57:22 +08:00
rename webview to engine
This commit is contained in:
@ -1,8 +1,6 @@
|
|||||||
import {Component, View as NgView, bootstrap} from 'angular2/angular2'
|
import {Component, View as NgView, bootstrap} from 'angular2/angular2'
|
||||||
import {View, Tabs, Tab} from 'ionic/ionic'
|
import {View, Tabs, Tab} from 'ionic/ionic'
|
||||||
import {webview} from 'ionic/webview/webview'
|
import {engine} from 'ionic/engine/engine'
|
||||||
import {cordova} from 'ionic/webview/cordova/cordova'
|
|
||||||
import {nodeWebkit} from 'ionic/webview/node-webkit/node-webkit'
|
|
||||||
import * as util from 'ionic/util'
|
import * as util from 'ionic/util'
|
||||||
|
|
||||||
|
|
||||||
@ -13,23 +11,23 @@ import * as util from 'ionic/util'
|
|||||||
})
|
})
|
||||||
class IonicApp {
|
class IonicApp {
|
||||||
constructor() {
|
constructor() {
|
||||||
console.log('IonicApp Start')
|
console.log('IonicApp Start');
|
||||||
|
|
||||||
console.log(webview.getName(), webview.is('cordova'))
|
console.log(engine.getName(), engine.is('cordova'));
|
||||||
|
|
||||||
webview.ready().then(() => {
|
engine.ready().then(() => {
|
||||||
console.log('webviewready')
|
console.log('engine ready')
|
||||||
})
|
});
|
||||||
|
|
||||||
webview.fullScreen(true).then((isShown) => {
|
engine.fullScreen(true).then((isShown) => {
|
||||||
console.log('fullScreen', isShown)
|
console.log('fullScreen', isShown)
|
||||||
})
|
});
|
||||||
|
|
||||||
webview.showStatusBar(true).then((isShown) => {
|
engine.showStatusBar(true).then((isShown) => {
|
||||||
console.log('showStatusBar', isShown)
|
console.log('showStatusBar', isShown)
|
||||||
})
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstrap(IonicApp)
|
bootstrap(IonicApp);
|
||||||
|
@ -1,32 +1,33 @@
|
|||||||
import {webview} from '../webview'
|
import {engine} from '../engine';
|
||||||
|
|
||||||
webview.register({
|
|
||||||
|
engine.register({
|
||||||
name: 'cordova',
|
name: 'cordova',
|
||||||
isMatch() {
|
isMatch() {
|
||||||
return !(!window.cordova && !window.PhoneGap && !window.phonegap)
|
return !(!window.cordova && !window.PhoneGap && !window.phonegap);
|
||||||
},
|
},
|
||||||
ready() {
|
ready() {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
setTimeout(resolve, 1000)
|
setTimeout(resolve, 1000);
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
fullScreen(shouldShow) {
|
fullScreen(shouldShow) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
resolve(shouldShow)
|
resolve(shouldShow);
|
||||||
}, 1000)
|
}, 1000);
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
showStatusBar(shouldShow) {
|
showStatusBar(shouldShow) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
resolve(shouldShow)
|
resolve(shouldShow);
|
||||||
}, 1000)
|
}, 1000);
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
exitApp() {
|
exitApp() {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
setTimeout(resolve, 1000)
|
setTimeout(resolve, 1000);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
})
|
});
|
37
ionic/engine/electron/electron.js
Normal file
37
ionic/engine/electron/electron.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import * as util from 'ionic/util';
|
||||||
|
import {engine} from '../engine';
|
||||||
|
|
||||||
|
|
||||||
|
engine.register({
|
||||||
|
name: 'electron',
|
||||||
|
isMatch() {
|
||||||
|
try {
|
||||||
|
return util.isDefined(process) && util.isDefined(require) && util.isDefined(require('nw.gui'));
|
||||||
|
} catch (e) {}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
ready() {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
setTimeout(resolve, 1000);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
fullScreen(shouldShow) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
setTimeout(function() {
|
||||||
|
resolve(shouldShow);
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
showStatusBar(shouldShow) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
setTimeout(function() {
|
||||||
|
resolve(shouldShow);
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
exitApp() {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
setTimeout(resolve, 1000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
73
ionic/engine/engine.js
Normal file
73
ionic/engine/engine.js
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
import * as util from 'ionic/util';
|
||||||
|
|
||||||
|
|
||||||
|
let registry = {};
|
||||||
|
let defaultEngine;
|
||||||
|
let activeEngine;
|
||||||
|
|
||||||
|
class EngineController {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
let self = this;
|
||||||
|
let proxyMethods = 'ready fullScreen showStatusBar exitApp'.split(' ');
|
||||||
|
for (let x = 0; x < proxyMethods.length; x++) {
|
||||||
|
this[proxyMethods[x]] = function() {
|
||||||
|
return self.proxy(proxyMethods[x], arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
proxy(target, args) {
|
||||||
|
let eng = this.get()
|
||||||
|
if (eng && eng[target]) {
|
||||||
|
return eng[target].apply(this, args);
|
||||||
|
}
|
||||||
|
return new Promise(resolve => {}, reject => {
|
||||||
|
reject();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
is(name) {
|
||||||
|
return this.name === name;
|
||||||
|
}
|
||||||
|
|
||||||
|
getName() {
|
||||||
|
return this.get().name;
|
||||||
|
}
|
||||||
|
|
||||||
|
get() {
|
||||||
|
if (util.isUndefined(activeEngine)) {
|
||||||
|
this.set(this.detect());
|
||||||
|
}
|
||||||
|
return activeEngine || defaultEngine;
|
||||||
|
}
|
||||||
|
|
||||||
|
set(eng) {
|
||||||
|
activeEngine = eng;
|
||||||
|
}
|
||||||
|
|
||||||
|
setDefault(eng) {
|
||||||
|
defaultEngine = eng;
|
||||||
|
}
|
||||||
|
|
||||||
|
register(eng) {
|
||||||
|
registry[eng.name] = eng;
|
||||||
|
}
|
||||||
|
|
||||||
|
detect() {
|
||||||
|
for (let name in registry) {
|
||||||
|
if (registry[name].isMatch()) {
|
||||||
|
return registry[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export let engine = new EngineController();
|
||||||
|
|
||||||
|
engine.setDefault({
|
||||||
|
name: 'default',
|
||||||
|
ready: util.dom.windowLoad
|
||||||
|
});
|
@ -19,8 +19,9 @@ Object.defineProperties(ViewContainer.prototype, {
|
|||||||
export * from 'ionic/components'
|
export * from 'ionic/components'
|
||||||
export * from 'ionic/platform/platform'
|
export * from 'ionic/platform/platform'
|
||||||
export * from 'ionic/routing/router'
|
export * from 'ionic/routing/router'
|
||||||
export * from 'ionic/webview/webview'
|
|
||||||
export * from 'ionic/webview/cordova/cordova'
|
|
||||||
export * from 'ionic/webview/node-webkit/node-webkit'
|
|
||||||
export * from 'ionic/util/focus'
|
export * from 'ionic/util/focus'
|
||||||
export * from 'ionic/collide/animation'
|
export * from 'ionic/collide/animation'
|
||||||
|
|
||||||
|
export * from 'ionic/engine/engine'
|
||||||
|
export * from 'ionic/engine/cordova/cordova'
|
||||||
|
export * from 'ionic/engine/electron/electron'
|
||||||
|
@ -78,7 +78,3 @@
|
|||||||
"components/icon/icon";
|
"components/icon/icon";
|
||||||
|
|
||||||
|
|
||||||
// Web View Adaptors
|
|
||||||
@import
|
|
||||||
"webview/cordova/cordova",
|
|
||||||
"webview/node-webkit/node-webkit";
|
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
import {webview} from '../webview'
|
|
||||||
|
|
||||||
webview.register({
|
|
||||||
name: 'node-webkit',
|
|
||||||
isMatch() {
|
|
||||||
try {
|
|
||||||
return util.isDefined(process) && util.isDefined(require) && util.isDefined(require('nw.gui'))
|
|
||||||
} catch (e) {}
|
|
||||||
return false
|
|
||||||
},
|
|
||||||
ready() {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
setTimeout(resolve, 1000)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
fullScreen(shouldShow) {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
setTimeout(function() {
|
|
||||||
resolve(shouldShow)
|
|
||||||
}, 1000)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
exitApp() {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
setTimeout(resolve, 1000)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
@ -1,89 +0,0 @@
|
|||||||
|
|
||||||
import * as util from 'ionic/util'
|
|
||||||
|
|
||||||
class WebView {
|
|
||||||
constructor(options) {
|
|
||||||
util.extend(this, options)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let registry = {}
|
|
||||||
let defaultWebView;
|
|
||||||
let activeWebView;
|
|
||||||
|
|
||||||
class WebViewController {
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
let self = this
|
|
||||||
let proxyMethods = 'ready fullScreen showStatusBar exitApp'.split(' ')
|
|
||||||
for (let x = 0; x < proxyMethods.length; x++) {
|
|
||||||
this[proxyMethods[x]] = function() {
|
|
||||||
return self.proxy(proxyMethods[x], arguments)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
proxy(target, args) {
|
|
||||||
let webview = this.get()
|
|
||||||
if (webview && webview[target]) {
|
|
||||||
return webview[target].apply(this, args)
|
|
||||||
}
|
|
||||||
return new Promise(resolve => {}, reject => {
|
|
||||||
reject()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
is(name) {
|
|
||||||
return this.getName() === name
|
|
||||||
}
|
|
||||||
|
|
||||||
isWebView() {
|
|
||||||
return !!this.get().isWebView
|
|
||||||
}
|
|
||||||
|
|
||||||
getName() {
|
|
||||||
return this.get().name
|
|
||||||
}
|
|
||||||
|
|
||||||
get() {
|
|
||||||
if (util.isUndefined(activeWebView)) {
|
|
||||||
this.set(this.detect())
|
|
||||||
}
|
|
||||||
return activeWebView || defaultWebView
|
|
||||||
}
|
|
||||||
|
|
||||||
set(webview) {
|
|
||||||
activeWebView = webview
|
|
||||||
}
|
|
||||||
|
|
||||||
setDefault(webview) {
|
|
||||||
if (!webview instanceof WebView) webview = new WebView(webview)
|
|
||||||
defaultWebView = webview
|
|
||||||
}
|
|
||||||
|
|
||||||
register(webview) {
|
|
||||||
if (!webview instanceof WebView) webview = new WebView(webview)
|
|
||||||
webview.isWebView = true
|
|
||||||
registry[webview.name] = webview
|
|
||||||
}
|
|
||||||
|
|
||||||
detect() {
|
|
||||||
for (let name in registry) {
|
|
||||||
if (registry[name].isMatch()) {
|
|
||||||
return registry[name]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export let webview = new WebViewController()
|
|
||||||
|
|
||||||
|
|
||||||
webview.setDefault({
|
|
||||||
name: 'default',
|
|
||||||
ready: util.dom.windowLoad
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user