Skip to content

Commit

Permalink
fix: re-add changes to support sound as resource (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
OS-martacarlos authored May 23, 2024
1 parent e68ff2d commit 3f66cbb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 37 deletions.
31 changes: 10 additions & 21 deletions hooks/unzipSound.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,35 +62,24 @@ module.exports = function(context) {
let soundFolderPath = platformConfig.getSoundDestinationFolder();
soundFolderPath = path.join(context.opts.projectRoot, soundFolderPath);

let soundZipFile = path.join(sourcePath, constants.soundZipFile);
let zipFile = utils.getFileName(sourcePath, "sounds", ".zip");

let promises = [];
if(utils.checkIfFileOrFolderExists(soundZipFile)){
let zip = new AdmZip(soundZipFile);
zip.extractAllTo(sourcePath, true);

if(zipFile != ""){
let soundZipFilePath = path.join(sourcePath, zipFile);
let zip = new AdmZip(soundZipFilePath);
let zipFolder = sourcePath + "/sounds"
zip.extractAllTo(zipFolder, true);

let entriesNr = zip.getEntries().length;
console.log(`FCM_LOG: Sound zip file has ${entriesNr} entries`);
if(entriesNr == 0) {
throw new Error (`OUTSYSTEMS_PLUGIN_ERROR: Sound zip file is empty, either delete it or add one or more files.`)
}

let zipFolder = sourcePath + "/sounds"

if(!utils.checkIfFileOrFolderExists(zipFolder)){
console.log(`FCM_LOG: No new folder unzipping.`)
/**
* to deal with the following case:
* iOS + one file in zip + O11
**/
if(sourcePath != soundFolderPath){
console.log(`FCM_LOG: ${sourcePath} != ${soundFolderPath} so we need to copy files.`)
promises = copyWavFiles(platformConfig, sourcePath, soundFolderPath, defer)
} else {
console.log(`FCM_LOG: ${sourcePath} == ${soundFolderPath} so we don't need to copy files.`)
}
} else {
promises = copyWavFiles(platformConfig, zipFolder, soundFolderPath, defer)
}
promises = copyWavFiles(platformConfig, zipFolder, soundFolderPath, defer)

}
return promises.length > 0 ? q.all(promises) : defer.resolve();
}
28 changes: 12 additions & 16 deletions hooks/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var constants = {
return "platforms/android/app/src/main/res/raw";
},
getWWWFolder: function() {
return "www";
return "platforms/android/app/src/main/assets/www";
}
},
ios: {
Expand All @@ -33,6 +33,14 @@ function checkIfFileOrFolderExists(path) {
return fs.existsSync(path);
}


function getFileName(dir, searchString, withExtension){
const files = fs.readdirSync(dir);
const matchingFiles = files.filter(file => file.includes(searchString) && file.endsWith(withExtension));
// return true if there are matching files, false otherwise
return matchingFiles.length > 0 ?matchingFiles[0] : "";
}

function removeFile(path){
fs.unlinkSync(path)
}
Expand Down Expand Up @@ -61,20 +69,7 @@ function getPlatformConfigs(platform) {

function getPlatformSoundPath(context, platformConfig){
let projectRoot = context.opts.projectRoot;
let platformPath;

if(platformConfig === constants.android){
platformPath = path.join(projectRoot, `platforms/android/www`);
} else {
let appName = getAppName(context)
platformPath = path.join(projectRoot, `platforms/ios/${appName}/Resources/www`);
}

if(!fs.existsSync(platformPath)){
platformPath = path.join(projectRoot, platformConfig.getWWWFolder());
}

return platformPath
return path.join(projectRoot, platformConfig.getWWWFolder());
}

function isCordovaAbove(context, version) {
Expand Down Expand Up @@ -116,5 +111,6 @@ module.exports = {
removeFolder,
isAndroid,
getAppName,
getPlatformSoundPath
getPlatformSoundPath,
getFileName
};

0 comments on commit 3f66cbb

Please sign in to comment.