mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-24 07:25:52 +00:00
Replace the old support for window.update_progress with OBJJ_PROGRESS_CALLBACK.
Function gets passed float from 0 to 1, the total size, and the last loaded bundle path, in that order.
This commit is contained in:
1 parent
555b83a359
commit
68d30c8802
3 files changed
+92
-7
No files matched your search
@@ -62,6 +62,8 @@ function resolveCWD()
|
||||
});
|
||||
}
|
||||
|
||||
var documentLoaded = NO;
|
||||
|
||||
function afterDocumentLoad(/*Function*/ aFunction)
|
||||
{
|
||||
if (documentLoaded)
|
||||
@@ -74,8 +76,6 @@ function afterDocumentLoad(/*Function*/ aFunction)
|
||||
window.attachEvent("onload", aFunction);
|
||||
}
|
||||
|
||||
var documentLoaded = NO;
|
||||
|
||||
afterDocumentLoad(function()
|
||||
{
|
||||
documentLoaded = YES;
|
||||
|
||||
+38
-2
@@ -29,7 +29,9 @@ var CFBundleUnloaded = 0,
|
||||
|
||||
var CFBundlesForPaths = { },
|
||||
CFBundlesForClasses = { },
|
||||
CFCacheBuster = new Date().getTime();
|
||||
CFCacheBuster = new Date().getTime(),
|
||||
CFTotalBytesLoaded = 0,
|
||||
CPApplicationSizeInBytes = 0;
|
||||
|
||||
GLOBAL(CFBundle) = function(/*String*/ aPath)
|
||||
{
|
||||
@@ -220,6 +222,9 @@ CFBundle.prototype.load = function(/*BOOL*/ shouldExecute)
|
||||
return;
|
||||
}
|
||||
|
||||
if (self === CFBundle.mainBundle() && self.valueForInfoDictionary("CPApplicationSize"))
|
||||
CPApplicationSizeInBytes = self.valueForInfoDictionary("CPApplicationSize").valueForKey("executable") || 0;
|
||||
|
||||
loadExecutableAndResources(self, shouldExecute);
|
||||
}
|
||||
|
||||
@@ -274,6 +279,12 @@ function loadExecutableAndResources(/*Bundle*/ aBundle, /*BOOL*/ shouldExecute)
|
||||
|
||||
function success()
|
||||
{
|
||||
if ((typeof CPApp === "undefined" || !CPApp || !CPApp._finishedLaunching) &&
|
||||
typeof OBJJ_PROGRESS_CALLBACK === "function" && CPApplicationSizeInBytes)
|
||||
{
|
||||
OBJJ_PROGRESS_CALLBACK(MAX(MIN(1.0, CFTotalBytesLoaded / CPApplicationSizeInBytes), 0.0), CPApplicationSizeInBytes, aBundle.path())
|
||||
}
|
||||
|
||||
if (aBundle._loadStatus === CFBundleLoading)
|
||||
aBundle._loadStatus = CFBundleLoaded;
|
||||
else
|
||||
@@ -285,13 +296,13 @@ function loadExecutableAndResources(/*Bundle*/ aBundle, /*BOOL*/ shouldExecute)
|
||||
|
||||
function complete()
|
||||
{
|
||||
|
||||
aBundle._eventDispatcher.dispatchEvent(
|
||||
{
|
||||
type:"load",
|
||||
bundle:aBundle
|
||||
});
|
||||
}
|
||||
|
||||
if (shouldExecute)
|
||||
executeBundle(aBundle, complete);
|
||||
else
|
||||
@@ -310,6 +321,7 @@ function loadExecutableForBundle(/*Bundle*/ aBundle, success, failure)
|
||||
{
|
||||
try
|
||||
{
|
||||
CFTotalBytesLoaded += anEvent.request.responseText().length;
|
||||
decompileStaticFile(aBundle, anEvent.request.responseText(), aBundle.executablePath());
|
||||
aBundle._loadStatus &= ~CFBundleLoadingExecutable;
|
||||
success();
|
||||
@@ -346,6 +358,7 @@ function loadSpritedImagesForBundle(/*Bundle*/ aBundle, success, failure)
|
||||
{
|
||||
try
|
||||
{
|
||||
CFTotalBytesLoaded += anEvent.request.responseText().length;
|
||||
decompileStaticFile(aBundle, anEvent.request.responseText(), spritedImagesPath);
|
||||
aBundle._loadStatus &= ~CFBundleLoadingSpritedImages;
|
||||
success();
|
||||
@@ -379,6 +392,29 @@ function CFBundleTestSpriteSupport(/*String*/ MHTMLPath, /*Function*/ aCallback)
|
||||
if (CFBundleSpriteSupportListeners.length > 1)
|
||||
return;
|
||||
|
||||
CFBundleSpriteSupportListeners.push(function()
|
||||
{
|
||||
var size = 0,
|
||||
sizeDictionary = CFBundle.mainBundle().valueForInfoDictionary("CPApplicationSize");
|
||||
|
||||
if (!sizeDictionary)
|
||||
return;
|
||||
|
||||
switch (CFBundleSupportedSpriteType)
|
||||
{
|
||||
case CFBundleDataURLSpriteType:
|
||||
size = sizeDictionary.valueForKey("data");
|
||||
break;
|
||||
|
||||
case CFBundleMHTMLSpriteType:
|
||||
case CFBundleMHTMLUncachedSpriteType:
|
||||
size = sizeDictionary.valueForKey("mhtml");
|
||||
break;
|
||||
}
|
||||
|
||||
CPApplicationSizeInBytes += size;
|
||||
})
|
||||
|
||||
CFBundleTestSpriteTypes([
|
||||
CFBundleDataURLSpriteType,
|
||||
"data:image/gif;base64,R0lGODlhAQABAIAAAMc9BQAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==",
|
||||
|
||||
+52
-3
@@ -81,11 +81,15 @@ function press(rootPath, outputPath, options) {
|
||||
stream.print("Application root: \0green(" + rootPath + "\0)");
|
||||
stream.print("Output directory: \0green(" + outputPath + "\0)");
|
||||
|
||||
var outputFiles = {};
|
||||
var outputFiles = {},
|
||||
totalBytes = {executable:0, data:0, mhtml:0};
|
||||
|
||||
// analyze and gather files for each environment:
|
||||
options.environments.forEach(function(environment) {
|
||||
pressEnvironment(rootPath, outputFiles, environment, options);
|
||||
var returnedBytes = pressEnvironment(rootPath, outputFiles, environment, options);
|
||||
|
||||
for (var i in returnedBytes)
|
||||
totalBytes[i] += returnedBytes[i];
|
||||
});
|
||||
|
||||
// phase 4: copy everything and write out the new files
|
||||
@@ -110,6 +114,34 @@ function press(rootPath, outputPath, options) {
|
||||
FILE.write(file, outputFiles[path], { charset : "UTF-8" });
|
||||
}
|
||||
|
||||
// phase 4a: update the info.plist to contain meta information about the app
|
||||
stream.print("\0red(PHASE 4a:\0) Add application size data to Info.plist");
|
||||
|
||||
var outputInfoPlistPath = FILE.join(outputPath, "Info.plist"),
|
||||
outputInfoPlistContents = FILE.read(outputInfoPlistPath, { charset:"UTF-8" }),
|
||||
format = CFPropertyList.sniffedFormatOfString(outputInfoPlistContents),
|
||||
outputInfoPlist = CFPropertyList.propertyListFromString(outputInfoPlistContents);
|
||||
|
||||
// read in the default theme name, and attempt to get its size
|
||||
var themeName = outputInfoPlist.valueForKey("CPDefaultTheme") || "Aristo",
|
||||
themePath = FILE.join(outputPath, options.frameworks, "AppKit", "Resources", themeName+".blend");
|
||||
|
||||
if (FILE.exists(themePath))
|
||||
{
|
||||
var themeEnvPath = FILE.join(themePath, options.environments[0] + ".environment"),
|
||||
themeExecutablePath = FILE.join(themeEnvPath, themeName+".blend.sj"),
|
||||
themeDataPath = FILE.join(themeEnvPath, "dataURLs.txt"),
|
||||
themeMHTMLPath = FILE.join(themeEnvPath, "MHTMLPaths.txt");
|
||||
|
||||
totalBytes.executable += FILE.read(themeExecutablePath, {charset : "UTF-8"}).length;
|
||||
totalBytes.data += FILE.read(themeDataPath, {charset : "UTF-8"}).length;
|
||||
totalBytes.mhtml += FILE.read(themeMHTMLPath, {charset : "UTF-8"}).length;
|
||||
}
|
||||
|
||||
outputInfoPlist.setValueForKey("CPApplicationSize", [CPDictionary dictionaryWithJSObject:totalBytes]);
|
||||
|
||||
FILE.write(outputInfoPlistPath, CFPropertyList.stringFromPropertyList(outputInfoPlist, format), { charset:"UTF-8" });
|
||||
|
||||
// strip known unnecessary files
|
||||
// outputPath.glob("**/Frameworks/Debug").forEach(function(debugFramework) {
|
||||
// outputPath.join(debugFramework).rmtree();
|
||||
@@ -193,7 +225,7 @@ function pressEnvironment(rootPath, outputFiles, environment, options) {
|
||||
});
|
||||
|
||||
var included = 0, total = 0;
|
||||
var includedBytes = 0, totalBytes = 0;
|
||||
var includedBytes = 0, totalBytes = 0, dataBytes = 0, mhtmlBytes = 0;
|
||||
|
||||
_OBJJ.FileExecutable.allFileExecutables().forEach(function(aFileExecutable) {
|
||||
var path = aFileExecutable.path();
|
||||
@@ -224,6 +256,8 @@ function pressEnvironment(rootPath, outputFiles, environment, options) {
|
||||
// phase 3b: rebuild .sj files with correct imports, copy .j files
|
||||
stream.print("\0red(PHASE 3b:\0) Rebuild .sj files");
|
||||
|
||||
var processedBundles = {};
|
||||
|
||||
for (var path in requiredFiles)
|
||||
{
|
||||
var executable = analyzer.executableForImport(path),
|
||||
@@ -289,10 +323,25 @@ function pressEnvironment(rootPath, outputFiles, environment, options) {
|
||||
{
|
||||
stream.print("Passing .j through: \0green(" + rootPath.relative(path) + "\0)");
|
||||
}
|
||||
|
||||
if (!processedBundles[bundle.path()] && bundle.hasSpritedImages())
|
||||
{
|
||||
processedBundles[bundle.path()] = bundle;
|
||||
stream.print("Sizing bundle's sprited resources \0green(" + bundle.path() + "\0)");
|
||||
|
||||
var bundlePath = FILE.join(bundle.path(), environment+".environment"),
|
||||
bundleDataPath = FILE.join(bundlePath, "dataURLs.txt"),
|
||||
bundleMHTMLPath = FILE.join(bundlePath, "MHTMLPaths.txt");
|
||||
|
||||
dataBytes += FILE.read(bundleDataPath, {charset : "UTF-8"}).length;
|
||||
mhtmlBytes += FILE.read(bundleMHTMLPath, {charset : "UTF-8"}).length;
|
||||
}
|
||||
}
|
||||
else
|
||||
CPLog.warn("No bundle (or info dictionary for) " + rootPath.relative(path));
|
||||
}
|
||||
|
||||
return {executable:includedBytes, data:dataBytes, mhtml:mhtmlBytes};
|
||||
}
|
||||
|
||||
function pngcrushDirectory(directory) {
|
||||
|
||||
Reference in new issue
Block a user