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

Fix(TiShadow): Android service dont working in tishadow #6698

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
import org.appcelerator.titanium.proxy.IntentProxy;
import org.appcelerator.titanium.proxy.ServiceProxy;
import org.appcelerator.titanium.util.TiBindingHelper;
import org.appcelerator.titanium.util.TiShadowHelper;

import android.app.Service;
import android.content.Intent;
import android.os.Bundle;

public class TiJSIntervalService extends TiJSService
{
protected TiShadowHelper tiShadowHelper;
protected Boolean isTishadow = tiShadowHelper.isTishadow();
private static final String TAG = "TiJSIntervalService";
private List<IntervalServiceRunner> runners = null;

Expand Down Expand Up @@ -72,11 +75,19 @@ protected void executeServiceCode(ServiceProxy proxy)
}

if (fullUrl.startsWith(TiC.URL_APP_PREFIX)) {
fullUrl = fullUrl.replaceAll("app:/", "Resources");
if(isTishadow){
fullUrl = fullUrl.replaceAll("app://", "");
}else{
fullUrl = fullUrl.replaceAll("app:/", "Resources");
}

} else if (fullUrl.startsWith(TiC.URL_ANDROID_ASSET_RESOURCES)) {
fullUrl = fullUrl.replaceAll("file:///android_asset/", "");
}

if(isTishadow){
fullUrl = tiShadowHelper.getDataDirectory()+fullUrl;
}

IntervalServiceRunner runner = new IntervalServiceRunner(this, proxy, interval, fullUrl);
runners.add(runner);
Expand Down Expand Up @@ -152,7 +163,11 @@ private class IntervalServiceRunner
this.proxy = proxy;
this.interval = interval;
this.url = url;
this.source = KrollAssetHelper.readAsset(url);
if(isTishadow){
this.source = KrollAssetHelper.readFile(url);
}else{
this.source = KrollAssetHelper.readAsset(url);
}
this.serviceSimpleName = service.getClass().getSimpleName();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
import org.appcelerator.titanium.TiBaseService;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.ServiceProxy;
import org.appcelerator.titanium.util.TiShadowHelper;

import android.content.Intent;

public class TiJSService extends TiBaseService
{
protected String url = null;
protected TiShadowHelper tiShadowHelper;
protected Boolean isTishadow = tiShadowHelper.isTishadow();
private static final String TAG = "TiJSService";

public TiJSService(String url)
Expand Down Expand Up @@ -64,14 +67,26 @@ protected void executeServiceCode(ServiceProxy proxy)
}

if (fullUrl.startsWith(TiC.URL_APP_PREFIX)) {
fullUrl = fullUrl.replaceAll("app:/", "Resources");
if(isTishadow){
fullUrl = fullUrl.replaceAll("app://", "");
}else{
fullUrl = fullUrl.replaceAll("app:/", "Resources");
}

} else if (fullUrl.startsWith(TiC.URL_ANDROID_ASSET_RESOURCES)) {
fullUrl = fullUrl.replaceAll("file:///android_asset/", "");
}

if(isTishadow){
fullUrl = tiShadowHelper.getDataDirectory()+fullUrl;
}

proxy.fireEvent(TiC.EVENT_RESUME, new KrollDict());
KrollRuntime.getInstance().runModule(KrollAssetHelper.readAsset(fullUrl), fullUrl, proxy);
if(isTishadow){
KrollRuntime.getInstance().runModule(KrollAssetHelper.readFile(fullUrl), fullUrl, proxy);
}else{
KrollRuntime.getInstance().runModule(KrollAssetHelper.readAsset(fullUrl), fullUrl, proxy);
}
proxy.fireEvent(TiC.EVENT_PAUSE, new KrollDict());
proxy.fireEvent(TiC.EVENT_STOP, new KrollDict()); // this basic JS Service class only runs once.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ protected static String getURLClassName(String url, String appendage)
int start = 0;
if (parts.get(0).equals("app:") && parts.size() >= 3) {
start = 2;
}else if(parts.get(0).equals("appdata-private:") && parts.size() >= 5){
start = 4;
}

String className = TextUtils.join("_", parts.subList(start, parts.size()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Dev by rotorgames
* Email: rotorgames@bk.ru
* Git: https://github.com/rotorgames
* Branch: https://github.com/rotorgames/titanium_mobile/tree/3_5_X_TiShadow_service
*/
package org.appcelerator.titanium.util;

import org.appcelerator.titanium.TiProperties;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.io.TiFileFactory;
import org.appcelerator.kroll.common.Log;

public class TiShadowHelper {

private static final String TAG = "TiShadowHelper";

protected static TiFileFactory tiFileFactory;
protected static TiApplication tiApp = TiApplication.getInstance();
protected static TiProperties tiProp = tiApp.getAppProperties();

public static Boolean isTishadow()
{
String tiShadowVersion = tiProp.getString("tishadow:version", "");
if(tiShadowVersion != ""){
Log.i(TAG, "Tishadow "+tiShadowVersion+": enabled");
return true;
}else{
Log.i(TAG, "Tishadow: disabled");
return false;
}
}

public static String getDataDirectory()
{
String appName = tiApp.getAppInfo().getName().replaceAll(" ", "_");
String dataDirectory = tiFileFactory.getDataDirectory(true).toString();
String path = dataDirectory+"/"+appName+"/android/";

Log.i(TAG, "Use path: "+path);

return path;
}
}