Skip to content

Commit

Permalink
[#33] Replaced hard coded "www" by Capacitor's "public" path
Browse files Browse the repository at this point in the history
Signed-off-by: Clovis Durand <[email protected]>
  • Loading branch information
Clovel committed Jun 14, 2021
1 parent 3631196 commit b6d61a8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions android/src/main/java/com/microsoft/capacitor/CodePush.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CodePush extends Plugin {
private static final String DEPLOYMENT_KEY_PREFERENCE = "ANDROID_DEPLOY_KEY";
private static final String PUBLIC_KEY_PREFERENCE = "ANDROID_PUBLIC_KEY";
private static final String SERVER_URL_PREFERENCE = "SERVER_URL";
private static final String WWW_ASSET_PATH_PREFIX = "file:///android_asset/www/";
private static final String WWW_ASSET_PATH_PREFIX = "file:///android_asset/public/";
private static final String NEW_LINE = System.getProperty("line.separator");
private static boolean ShouldClearHistoryOnLoad = false;
private CodePushPackageManager codePushPackageManager;
Expand Down Expand Up @@ -189,7 +189,7 @@ public void getPackageHash(final PluginCall call) {
protected Void doInBackground(Void... params) {
try {
// TODO: fix client side
String binaryHash = UpdateHashUtils.getHashForPath(getActivity(), call.getString("path") + "/www");
String binaryHash = UpdateHashUtils.getHashForPath(getActivity(), call.getString("path") + "/public");
call.resolve(jsObjectValue(binaryHash));
} catch (Exception e) {
call.reject("An error occurred when trying to get the hash of the binary contents. " + e.getMessage());
Expand Down Expand Up @@ -509,7 +509,7 @@ public void run() {

private File getStartPageForPackage(String packageLocation) {
if (packageLocation != null) {
File startPage = new File(this.bridge.getContext().getFilesDir() + "/" + packageLocation, "www/index.html");
File startPage = new File(this.bridge.getContext().getFilesDir() + "/" + packageLocation, "public/index.html");
if (startPage.exists()) {
return startPage;
}
Expand All @@ -520,7 +520,7 @@ private File getStartPageForPackage(String packageLocation) {

private String getBasePathForPackage(String packageLocation) {
if (packageLocation != null) {
return new File(this.bridge.getContext().getFilesDir() + "/" + packageLocation, "www").toString();
return new File(this.bridge.getContext().getFilesDir() + "/" + packageLocation, "public").toString();
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public static String getBinaryHash(Activity activity) throws IOException, NoSuch
public static String getHashForPath(Activity activity, String path) throws IOException, NoSuchAlgorithmException, ClassNotFoundException {
ArrayList<String> manifestEntries = new ArrayList<String>();
if (path == null) {
addFolderEntriesToManifestFromAssets(manifestEntries, activity.getAssets(), "www");
addFolderEntriesToManifestFromAssets(manifestEntries, activity.getAssets(), "public");
} else {
File basePath = activity.getApplicationContext().getFilesDir();
File fullPath = new File(basePath, path);
addFolderEntriesToManifest(manifestEntries, "www", fullPath.getPath());
addFolderEntriesToManifest(manifestEntries, "public", fullPath.getPath());
}
Collections.sort(manifestEntries);
JSONArray manifestJSONArray = new JSONArray();
Expand Down
6 changes: 3 additions & 3 deletions ios/Plugin/CodePush.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ - (void)getPackageHash:(CAPPluginCall *)call {
} else {
path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]
stringByAppendingPathComponent:path]
stringByAppendingPathComponent:@"www"];
stringByAppendingPathComponent:@"public"];
NSError *error;
NSString *hash = [UpdateHashUtils getHashForPath:path error:&error];
if (error) {
Expand Down Expand Up @@ -406,7 +406,7 @@ - (void) setServerBasePath:(NSString*)serverPath {
- (void)loadStoreVersion {
NSString* mainBundlePath = [[NSBundle mainBundle] bundlePath];
NSString* configStartPage = [self getConfigLaunchUrl];
NSArray* realLocationArray = @[mainBundlePath, @"www", configStartPage];
NSArray* realLocationArray = @[mainBundlePath, @"public", configStartPage];
NSString* mainPageLocation = [NSString pathWithComponents:realLocationArray];
if ([[NSFileManager defaultManager] fileExistsAtPath:mainPageLocation]) {
NSURL* mainPagePath = [NSURL fileURLWithPath:mainPageLocation];
Expand All @@ -430,7 +430,7 @@ - (NSString*)getConfigLaunchUrl
- (NSURL *)getStartPageURLForLocalPackage:(NSString*)packageLocation {
if (packageLocation) {
NSString* libraryLocation = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSArray* realLocationArray = @[libraryLocation, packageLocation, @"www/index.html"];
NSArray* realLocationArray = @[libraryLocation, packageLocation, @"public/index.html"];
NSString* realStartPageLocation = [NSString pathWithComponents:realLocationArray];
if ([[NSFileManager defaultManager] fileExistsAtPath:realStartPageLocation]) {
// Fixes WKWebView unable to load start page from CodePush update directory
Expand Down
4 changes: 2 additions & 2 deletions ios/Plugin/UpdateHashUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ + (NSArray *)ignoredFilenames {

+ (NSString*)binaryAssetsPath
{
return [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"www"];
return [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"public"];
}

+ (void)addFolderEntriesToManifest:(NSString*)folderPath
Expand Down Expand Up @@ -94,7 +94,7 @@ + (NSString*)getHashForPath:(NSString*)path error:(NSError**)error
{
NSMutableArray* manifestEntries = [NSMutableArray array];
[self addFolderEntriesToManifest:path
pathPrefix:@"www"
pathPrefix:@"public"
manifestEntries:manifestEntries
error:error];
return [self computeFinalHashFromManifestEntries:manifestEntries error:error];
Expand Down
6 changes: 3 additions & 3 deletions src/localPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class LocalPackage extends Package implements ILocalPackage {

private async getSignatureFromUpdate(deployDir: string, callback: Callback<string>){

const filePath = deployDir + "/www/.codepushrelease";
const filePath = deployDir + "/public/.codepushrelease";

if (!await FileUtil.fileExists(Directory.Data, filePath)) {
// signature absents in the bundle
Expand Down Expand Up @@ -375,10 +375,10 @@ export class LocalPackage extends Package implements ILocalPackage {
LocalPackage.getPackage(LocalPackage.PackageInfoFile, (currentPackage: LocalPackage) => resolve(currentPackage.localPath), () => resolve());
});

newPackageLocation = currentPackagePath ? newPackageLocation : newPackageLocation + "/www";
newPackageLocation = currentPackagePath ? newPackageLocation : newPackageLocation + "/public";

// https://github.com/ionic-team/capacitor/pull/2514 Directory.Application variable was removed. (TODO - for check)
const source: GetUriOptions = currentPackagePath ? {directory: Directory.Data, path: currentPackagePath} : {directory: Directory.Data, path: "www"};
const source: GetUriOptions = currentPackagePath ? {directory: Directory.Data, path: currentPackagePath} : {directory: Directory.Data, path: "public"};
const target: GetUriOptions = {directory: Directory.Data, path: newPackageLocation};

return FileUtil.copyDirectoryEntriesTo(source, target, ignoreList);
Expand Down
2 changes: 1 addition & 1 deletion src/nativeAppInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class NativeAppInfo {
}

/**
* Gets a hash of the `www` folder contents compiled in the app store binary.
* Gets a hash of the `public` folder contents compiled in the app store binary.
*/
public static async getBinaryHash(): Promise<string> {
try {
Expand Down
10 changes: 5 additions & 5 deletions test/projectManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class ProjectManager {
}
mkdirp.sync(projectDirectory);

const indexHtml = "www/index.html";
const indexHtml = "public/index.html";
const destinationIndexPath = path.join(projectDirectory, indexHtml);
const packageFile = path.join(templatePath, "package.json");
const destinationPackageFile = path.join(projectDirectory, "package.json");
Expand All @@ -62,11 +62,11 @@ export class ProjectManager {
* Sets up the scenario for a test in an already existing Cordova project.
*/
public static setupScenario(projectDirectory: string, appId: string, templatePath: string, jsPath: string, targetPlatform: platform.IPlatform, build: boolean = true, version: string = ProjectManager.DEFAULT_APP_VERSION): Q.Promise<string> {
const indexHtml = "www/index.html";
const indexHtml = "public/index.html";
const templateIndexPath = path.join(templatePath, indexHtml);
const destinationIndexPath = path.join(projectDirectory, indexHtml);

const scenarioJs = "www/" + jsPath;
const scenarioJs = "public/" + jsPath;
const templateScenarioJsPath = path.join(templatePath, scenarioJs);
const destinationScenarioJsPath = path.join(projectDirectory, scenarioJs);

Expand Down Expand Up @@ -134,10 +134,10 @@ export class ProjectManager {
});

if (isDiff) {
archive.append(`{"deletedFiles":[]}`, { name: "www/hotcodepush.json" });
archive.append(`{"deletedFiles":[]}`, { name: "public/hotcodepush.json" });
}

archive.directory(targetFolder, "www");
archive.directory(targetFolder, "public");
archive.pipe(writeStream);
archive.finalize();

Expand Down

0 comments on commit b6d61a8

Please sign in to comment.