Skip to content
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

[TIMOB-26015] Android/iOS: Refactored "app.js" launch handling #10112

Merged
merged 26 commits into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b5ec2df
[TIMOB-26015] Android/iOS: Refactored "app.js" launch handling.
jquick-axway Jun 16, 2018
1a2b85e
Merge branch 'master' into TIMOB-26015
jquick-axway Jun 16, 2018
807ca03
[TIMOB-26144] Android: Improved File.getDirectoryListing() performanc…
jquick-axway Jun 21, 2018
61218d8
Merge branch 'master' into TIMOB-26015
jquick-axway Jun 22, 2018
a4d9c4f
Resolved unit test collision with "Titanium.Filesystem.File"
jquick-axway Jun 22, 2018
4dbfb19
Updated [TIMOB-26015] based on review feedback.
jquick-axway Jun 23, 2018
b917b5b
Merge branch 'master' into TIMOB-26015
garymathews Jul 2, 2018
fe7cac8
Renamed directory "_ti" to "ti.internal" for [TIMOB-26015].
jquick-axway Jul 3, 2018
4f5e050
Merge branch 'master' into TIMOB-26015
sgtcoolguy Jul 12, 2018
8a05e47
Updated [TIMOB-26015] based on feedback
jquick-axway Jul 14, 2018
6cbee08
Merge branch 'master' into TIMOB-26015
sgtcoolguy Jul 17, 2018
db15c89
Merge branch 'master' into TIMOB-26015
garymathews Jul 17, 2018
afc75ad
[TIMOB-26217] iOS: Added "Ti.Filesystem.File" methods isFile() and is…
jquick-axway Jul 18, 2018
aa83bf5
[TIMOB-16678] Android: Added File.read() of encrypted assets support.
jquick-axway Jul 18, 2018
608dc18
Added "bootstrap.json" support to Android build for [TIMOB-26015]
jquick-axway Jul 18, 2018
325b396
Added "bootstrap.json" support to iOS build for [TIMOB-26015]
jquick-axway Jul 26, 2018
225ac11
Merge branch 'master' into TIMOB-26015
sgtcoolguy Aug 2, 2018
9b76d6e
Merge branch 'master' into TIMOB-26015
sgtcoolguy Aug 15, 2018
18054ea
Merge branch 'master' into TIMOB-26015
garymathews Sep 10, 2018
e594511
Merge branch 'master' into TIMOB-26015
sgtcoolguy Sep 13, 2018
a414030
Merge branch 'master' into TIMOB-26015
sgtcoolguy Sep 18, 2018
e7314e8
Merge branch 'master' into TIMOB-26015
hansemannn Sep 18, 2018
7c13086
Removed ES6 String methods from core introduced in [TIMOB-26015].
jquick-axway Sep 18, 2018
71920d5
Merge branch 'master' into TIMOB-26015
lokeshchdhry Sep 19, 2018
0d17b10
Fixed app startup error introduced in last [TIMOB-26015] commit.
jquick-axway Sep 19, 2018
7ba412b
Merge branch 'master' into TIMOB-26015
jquick-axway Sep 19, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 34 additions & 4 deletions android/cli/commands/_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2327,6 +2327,7 @@ AndroidBuilder.prototype.copyResources = function copyResources(next) {
drawableResources = {},
jsFiles = {},
jsFilesToEncrypt = this.jsFilesToEncrypt = [],
jsBootstrapFiles = [],
htmlJsFiles = this.htmlJsFiles = {},
symlinkFiles = process.platform !== 'win32' && this.config.get('android.symlinkResources', true),
_t = this;
Expand Down Expand Up @@ -2518,6 +2519,13 @@ AndroidBuilder.prototype.copyResources = function copyResources(next) {

if (!jsFiles[id] || !opts || !opts.onJsConflict || opts.onJsConflict(from, to, id)) {
jsFiles[id] = from;

// JS files that end with "*.bootstrap.js" are loaded before the "app.js".
// Add it as a require() compatible string to bootstrap array if it's a match.
const bootstrapPath = id.substr(0, id.length - 3); // Remove the ".js" extension.
if (bootstrapPath.endsWith('.bootstrap')) {
jsBootstrapFiles.push(bootstrapPath);
}
}

next();
Expand Down Expand Up @@ -2559,8 +2567,20 @@ AndroidBuilder.prototype.copyResources = function copyResources(next) {
}

const tasks = [
// first task is to copy all files in the Resources directory, but ignore
// any directory that is the name of a known platform
// First copy all of the Titanium SDK's core JS files shared by all platforms.
function (cb) {
const src = path.join(this.titaniumSdkPath, 'common', 'Resources');
warnDupeDrawableFolders.call(this, src);
_t.logger.debug(__('Copying %s', src.cyan));
copyDir.call(this, {
src: src,
dest: this.buildBinAssetsResourcesDir,
ignoreRootDirs: ti.allPlatformNames
}, cb);
},

// Next, copy all files in the project's Resources directory,
// but ignore any directory that is the name of a known platform.
function (cb) {
const src = path.join(this.projectDir, 'Resources');
warnDupeDrawableFolders.call(this, src);
Expand All @@ -2572,7 +2592,7 @@ AndroidBuilder.prototype.copyResources = function copyResources(next) {
}, cb);
},

// next copy all files from the Android specific Resources directory
// Last, copy all files from the Android specific Resources directory.
function (cb) {
const src = path.join(this.projectDir, 'Resources', 'android');
warnDupeDrawableFolders.call(this, src);
Expand Down Expand Up @@ -2774,7 +2794,8 @@ AndroidBuilder.prototype.copyResources = function copyResources(next) {
};
}), function () {
// write the properties file
const appPropsFile = path.join(this.encryptJS ? this.buildAssetsDir : this.buildBinAssetsResourcesDir, '_app_props_.json'),
const buildAssetsPath = this.encryptJS ? this.buildAssetsDir : this.buildBinAssetsResourcesDir,
appPropsFile = path.join(buildAssetsPath, '_app_props_.json'),
props = {};
Object.keys(this.tiapp.properties).forEach(function (prop) {
props[prop] = this.tiapp.properties[prop].value;
Expand All @@ -2786,6 +2807,14 @@ AndroidBuilder.prototype.copyResources = function copyResources(next) {
this.encryptJS && jsFilesToEncrypt.push('_app_props_.json');
delete this.lastBuildFiles[appPropsFile];

// Write the "bootstrap.json" file, even if the bootstrap array is empty.
// Note: An empty array indicates the app has no bootstrap files.
const bootstrapJsonRelativePath = path.join('ti.internal', 'bootstrap.json'),
bootstrapJsonAbsolutePath = path.join(buildAssetsPath, bootstrapJsonRelativePath);
fs.writeFileSync(bootstrapJsonAbsolutePath, JSON.stringify({ scripts: jsBootstrapFiles }));
this.encryptJS && jsFilesToEncrypt.push(bootstrapJsonRelativePath);
delete this.lastBuildFiles[bootstrapJsonAbsolutePath];

if (!jsFilesToEncrypt.length) {
// nothing to encrypt, continue
return next();
Expand Down Expand Up @@ -3991,6 +4020,7 @@ AndroidBuilder.prototype.packageApp = function packageApp(next) {
'-S', this.buildResDir,
'-I', this.androidCompileSDK.androidJar,
'-F', this.ap_File,
'--ignore-assets', '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a more complete list of things we ignore, check out https://github.com/appcelerator/titanium/blob/master/lib/config.js#L40-L41. It's probably overkill, but you did add picasa.ini for some reason.

Not sure if it helps, but you can get the regexes defined by those config settings by calling this.config.get('cli.ignoreDirs') and this.config.get('cli.ignoreFiles'). You'd need to convert it from a regex to that string with the negates which would be fun.

'--output-text-symbols', bundlesPath,
'--no-version-vectors'
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.appcelerator.titanium.ITiAppInfo;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.TiRootActivity;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiPlatformHelper;
Expand Down Expand Up @@ -54,8 +55,6 @@ public class AppModule extends KrollModule implements SensorEventListener
private boolean proximityState;
private int proximityEventListenerCount = 0;

private static final String APP_PATH = "Resources/app.js";

public AppModule()
{
super("App");
Expand Down Expand Up @@ -219,7 +218,18 @@ public boolean getAccessibilityEnabled()
@Kroll.method(name = "_restart")
public void restart()
{
KrollRuntime runtime = KrollRuntime.getInstance();
// Fetch the root activity hosting the JavaScript runtime.
TiRootActivity rootActivity = TiApplication.getInstance().getRootActivity();
if (rootActivity == null) {
return;
}

// Fetch a path to the main script that was last loaded.
String appPath = rootActivity.getUrl();
if (appPath == null) {
return;
}
appPath = "Resources/" + appPath;

// prevent termination of root activity via TiBaseActivity.shouldFinishRootActivity()
TiBaseActivity.canFinishRoot = false;
Expand All @@ -231,11 +241,12 @@ public void restart()
TiBaseActivity.canFinishRoot = true;

// restart kroll runtime
KrollRuntime runtime = KrollRuntime.getInstance();
runtime.doDispose();
runtime.initRuntime();

// manually re-launch app
runtime.doRunModule(KrollAssetHelper.readAsset(APP_PATH), APP_PATH, getActivityProxy());
runtime.doRunModule(KrollAssetHelper.readAsset(appPath), appPath, getActivityProxy());
}

@Kroll.method
Expand Down