-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compatibility for better simulator reloads #35
base: master
Are you sure you want to change the base?
Changes from 12 commits
def3895
282953d
120f7cb
9fb2e4f
132bc03
a4e2677
48b50ee
f500a0a
8059d06
64fc51b
8ddc085
86a4226
3ec9fd5
e655fa4
2b88f49
9132381
b859881
7b4cdbc
473350d
0bbfc52
8620a31
c83a22d
9e8b8fd
91f11c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,36 +4,6 @@ function bootstrap(initialImport, target) { | |
var loc = w.location; | ||
var q = loc.search + loc.hash; | ||
|
||
// check to see if we need chrome frame | ||
// if (target && (target=="desktop" || target=="facebook") && /MSIE/i.test(navigator.userAgent) && !d.createElement('canvas').getContext) { | ||
// var chromeframe_url = 'chromeframe.html' + (loc.search ? loc.search + "&" : "?") + "target="+ target; | ||
// bootstrap = function() {}; | ||
// try { | ||
// var obj = new ActiveXObject('ChromeTab.ChromeFrame'); | ||
// if (!obj) { | ||
// throw "bad object"; | ||
// } | ||
// loc.replace(chromeframe_url); | ||
// } catch(e) { | ||
// w.onload = function() { | ||
// var e = d.createElement('script'); | ||
// e.async = true; | ||
// e.src = "http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"; | ||
// e.onreadystatechange= function () { | ||
// if (this.readyState == 'loaded') { | ||
// CFInstall.check({ | ||
// mode: "overlay", | ||
// oninstall: function() { loc.replace(chromeframe_url) }, | ||
// url: "http://www.google.com/chromeframe/eula.html?user=true" | ||
// }); | ||
// } | ||
// } | ||
// d.getElementsByTagName('head')[0].appendChild(e); | ||
// } | ||
// } | ||
// return; | ||
// } | ||
|
||
// for tracking when the page started loading | ||
w.__initialTime = +new Date(); | ||
|
||
|
@@ -75,18 +45,6 @@ function bootstrap(initialImport, target) { | |
var mobile = (/(iPod|iPhone|iPad)/i.test(ua) ? 'ios' : /BlackBerry/.test(ua) ? 'blackberry' : /Mobile Safari/.test(ua) ? 'android' : ''); | ||
var isKik = /Kik\/\d/.test(ua); | ||
|
||
// if (loc.search.match(/exportSettings=true/)) { | ||
// // just export localStorage | ||
// exportSettings(); | ||
// } else if (mobile != 'blackberry' && !w.CONFIG.noRedirect) { | ||
// // redirect based on device | ||
// if (mobile && target != 'browser-mobile') { | ||
// return loc.replace('//' + loc.host + '/browser-mobile/' + loc.hash); | ||
// } else if (!mobile && target == 'browser-mobile') { | ||
// return loc.replace('//' + loc.host + '/browser-desktop/' + loc.hash); | ||
// } | ||
// } | ||
|
||
// set the viewport | ||
if (mobile == 'ios') { | ||
// Using initial-scale on android makes everything blurry! I think only IOS | ||
|
@@ -134,11 +92,39 @@ function bootstrap(initialImport, target) { | |
|
||
var loaded = false; | ||
w._continueLoad = function() { | ||
if (!loaded) { | ||
loaded = true; | ||
var el = d.createElement('script'); | ||
el.src = target + '.js'; | ||
d.getElementsByTagName('head')[0].appendChild(el); | ||
var doThings = function() { | ||
if (!loaded) { | ||
loaded = true; | ||
// Include the game code | ||
var el = d.createElement('script'); | ||
el.src = target + '.js'; | ||
d.getElementsByTagName('head')[0].appendChild(el); | ||
} | ||
}; | ||
|
||
var _continueLoadDefer; | ||
|
||
w.addEventListener('message', function(event) { | ||
if (event.data === 'partialLoadContinue') { | ||
if (_continueLoadDefer) { | ||
_continueLoadDefer.resolve(); | ||
_continueLoadDefer = undefined; | ||
} | ||
} | ||
}); | ||
// Preload suggestions and then tell the parent bootstrapping is complete | ||
jsio.__env.preloadModules(function() { | ||
w.parent.postMessage('bootstrapping', '*'); | ||
}); | ||
|
||
var partialLoadKey = jsio.__env.getNamespace('partialLoad'); | ||
if (localStorage && localStorage.getItem(partialLoadKey)) { | ||
localStorage.removeItem(partialLoadKey); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would mean that jsio functionality is reliant on devkit? Did it this way so that these changes would work with any jsio app There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I can tell, your proposed changes make jsio reliant on devkit functionality since it makes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made the namespace calls not dependent on devkit. I think we probably should still leave them in there just to make sure they don't collide with some other project. |
||
|
||
_continueLoadDefer = Promise.defer(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think we have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty decent: http://caniuse.com/#feat=promises There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. by pretty decent you mean absolutely awful? check the android browser column: less than 20% of that column has promises, and that's only android 4.1+ (not including users on 4.0 and lower). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, i was wrong, it's still pretty bad though -- adding in chrome for android you get: chrome android: 13.77% so according to that particular website, about a 1 in 4 chance it fails on an arbitrary android device? i'd maybe buy the argument that devkit games only run on chrome for android and that we don't support the old android webkit, but chrome doesn't ship with android (oem's can choose to ship it i think) and I'm not sure which devices we'd actually expect to have chrome these days. Until Chrome is default on android or we have usage numbers of 90-95%+ chrome on android, I don't think it's wise to drop support for older browsers, and I'd definitely prefer some kind of nice you-need-to-upgrade message, not just have it throw an exception on load with a white screen. |
||
_continueLoadDefer.promise.then(doThings); | ||
} else { | ||
doThings(); | ||
} | ||
}; | ||
|
||
|
@@ -173,72 +159,21 @@ function bootstrap(initialImport, target) { | |
|
||
if (mobile && supportedOrientations) { | ||
checkOrientation(); | ||
// if (!orientationOk) { | ||
// var el = d.body.appendChild(d.createElement('div')); | ||
// el.innerHTML = 'please rotate your phone<br><span style="font-size:200%">\u21bb</span>'; | ||
// var width = d.body.offsetWidth; | ||
// el.style.cssText = 'opacity:0;z-index:9000;color:#FFF;background:rgba(40,40,40,0.8);border-radius:25px;text-align:center;padding:' + width / 10 + 'px;font-size:' + width / 20 + 'px;position:absolute;left:50%;width:' + width * 5 / 8 + 'px;margin-left:-' + width * 5 / 16 + 'px;margin-top:80px;pointer-events:none'; | ||
// w.addEventListener('resize', function () { | ||
// checkOrientation(); | ||
// el.style.display = orientationOk ? 'none': 'block'; | ||
// }); | ||
// } | ||
} | ||
|
||
var appCache = window.applicationCache; | ||
['cached', 'checking', 'downloading', 'error', 'noupdate', 'obsolete', 'progress', 'updateready'].forEach(function (evt) { | ||
appCache.addEventListener(evt, handleCacheEvent, false); | ||
}); | ||
|
||
// status 0 == UNCACHED | ||
// if (appCache.status) { | ||
|
||
// appCache.update(); // Attempt to update the user's cache. | ||
// } | ||
|
||
function handleCacheEvent(evt) { | ||
if (evt.type == 'updateready') { | ||
// var el = d.body.appendChild(d.createElement('div')); | ||
// el.style.cssText = 'opacity:0;position:absolute;z-index:9900000;top:-20px;margin:0px auto' | ||
// + 'height:20px;width:200px;' | ||
// + '-webkit-border-radius:0px 0px 5px 5px;' | ||
// + '-webkit-transition:all 0.7s ease-in-out;' | ||
// + '-webkit-transform:scale(' + w.devicePixelRatio + ');' | ||
// + '-webkit-transform-origin:50% 0%;' | ||
// + '-webkit-box-shadow:0px 2px 3px rgba(0, 0, 0, 0.4);' | ||
// + 'background:rgba(0,0,0,0.7);color:#FFF;' | ||
// + 'padding:10px 15px;' | ||
// + 'font-size: 15px;'; | ||
// + 'text-align: center;'; | ||
// + 'cursor:pointer;'; | ||
|
||
// if (CONFIG.embeddedFonts && CONFIG.embeddedFonts.length) { | ||
// el.style.fontFamily = CONFIG.embeddedFonts[0]; | ||
// } | ||
|
||
// el.innerText = 'game updated! tap here'; | ||
// el.style.left = (d.body.offsetWidth - 200) / 2 + 'px'; | ||
|
||
// el.setAttribute('noCapture', true); // prevent DevKit from stopping clicks on this event | ||
// el.addEventListener('click', reload, true); | ||
// el.addEventListener('touchstart', reload, true); | ||
|
||
// setTimeout(function () { | ||
// el.style.top='0px'; | ||
// el.style.opacity='1'; | ||
// }, 0); | ||
|
||
// setTimeout(function () { | ||
// el.style.top='-20px'; | ||
// el.style.opacity='0'; | ||
// }, 30000); | ||
console.log("update ready"); | ||
|
||
// reload immediately if splash is still visible | ||
var splash = d.getElementById('_GCSplash'); | ||
if (splash && splash.parentNode) { | ||
try { appCache.swapCache(); } catch (e) {} | ||
//location.reload(); | ||
} | ||
} | ||
} | ||
|
@@ -284,6 +219,6 @@ function bootstrap(initialImport, target) { | |
if (h > min) { increased = true; } | ||
min = h; | ||
// } | ||
}, 50); | ||
}, 20); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we not call this
doThings
? :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ugh