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

RMET-3347 :: Re-add sound as resource #97

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
};
Loading