Skip to content

Commit

Permalink
fix: ios universal links plugin change, file opener, matrix device fix (
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgithubprofile authored Nov 20, 2023
1 parent 7c8189d commit e35f31b
Show file tree
Hide file tree
Showing 32 changed files with 1,250 additions and 447 deletions.
2 changes: 1 addition & 1 deletion chat/matrix-element.12.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion chat/matrix-element.12.min.js.map

Large diffs are not rendered by default.

261 changes: 151 additions & 110 deletions chat/matrix-element.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion chat/matrix-element.js.map

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions chat/matrix-element.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion chat/matrix-element.min.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions cordova/configs/en.lproj/InfoPlist.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"NSMicrophoneUsageDescription" = "The application uses a microphone to create voice messages in chat";
"NSCameraUsageDescription" = "The app uses a camera so you can take a photo and post it to your news feed.";
"NSPhotoLibraryUsageDescription" = "The app uses a photo gallery, so you can select photos from the gallery to post on your feed.";
Empty file.
49 changes: 26 additions & 23 deletions cordova/cordova-universal-links-plugin/hooks/afterPrepareHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ It will inject required preferences in the platform-specific projects, based on
data you have specified in the projects config.xml file.
*/

var configParser = require('./lib/configXmlParser.js');
var androidManifestWriter = require('./lib/android/manifestWriter.js');
var androidWebHook = require('./lib/android/webSiteHook.js');
var iosProjectEntitlements = require('./lib/ios/projectEntitlements.js');
var iosAppSiteAssociationFile = require('./lib/ios/appleAppSiteAssociationFile.js');
var iosProjectPreferences = require('./lib/ios/xcodePreferences.js');
var ANDROID = 'android';
var IOS = 'ios';
var { readPreferences } = require("./lib/util.js");
var androidManifestWriter = require("./lib/android/manifestWriter.js");
var androidWebHook = require("./lib/android/webSiteHook.js");
var iosProjectEntitlements = require("./lib/ios/projectEntitlements.js");
var iosAppSiteAssociationFile = require("./lib/ios/appleAppSiteAssociationFile.js");
var iosProjectPreferences = require("./lib/ios/xcodePreferences.js");
var ANDROID = "android";
var IOS = "ios";

module.exports = function(ctx) {
module.exports = function (ctx) {
run(ctx);
};

Expand All @@ -24,7 +24,7 @@ module.exports = function(ctx) {
* @param {Object} cordovaContext - cordova context object
*/
function run(cordovaContext) {
var pluginPreferences = configParser.readPreferences(cordovaContext);
var pluginPreferences = readPreferences(cordovaContext);
var platformsList = cordovaContext.opts.platforms;

// if no preferences are found - exit
Expand All @@ -34,22 +34,22 @@ function run(cordovaContext) {

// if no host is defined - exit
if (pluginPreferences.hosts == null || pluginPreferences.hosts.length == 0) {
console.warn('No host is specified in the config.xml. Universal Links plugin is not going to work.');
console.warn(
"No host is specified in the config.xml. Universal Links plugin is not going to work."
);
return;
}

platformsList.forEach(function(platform) {
platformsList.forEach(function (platform) {
switch (platform) {
case ANDROID:
{
activateUniversalLinksInAndroid(cordovaContext, pluginPreferences);
break;
}
case IOS:
{
activateUniversalLinksInIos(cordovaContext, pluginPreferences);
break;
}
case ANDROID: {
activateUniversalLinksInAndroid(cordovaContext, pluginPreferences);
break;
}
case IOS: {
activateUniversalLinksInIos(cordovaContext, pluginPreferences);
break;
}
}
});
}
Expand Down Expand Up @@ -79,7 +79,10 @@ function activateUniversalLinksInIos(cordovaContext, pluginPreferences) {
iosProjectPreferences.enableAssociativeDomainsCapability(cordovaContext);

// generate entitlements file
iosProjectEntitlements.generateAssociatedDomainsEntitlements(cordovaContext, pluginPreferences);
iosProjectEntitlements.generateAssociatedDomainsEntitlements(
cordovaContext,
pluginPreferences
);

// generate apple-site-association-file
iosAppSiteAssociationFile.generate(cordovaContext, pluginPreferences);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,23 @@ module.exports = {
* @param {Object} pluginPreferences - plugin preferences as JSON object; already parsed
*/
function writePreferences(cordovaContext, pluginPreferences) {
var pathToManifest = path.join(cordovaContext.opts.projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'AndroidManifest.xml');
var pathToManifest = path.join(cordovaContext.opts.projectRoot, 'platforms', 'android', 'AndroidManifest.xml');
var manifestSource = xmlHelper.readXmlAsJson(pathToManifest);
var cleanManifest;
var updatedManifest;

/**
* Cordova-Android 7.0+ FIX
*
* cordova-android 7.0+ changes the path to AndroidManifest
* So if manifestSource/manifestData is empty (or undefined) we assume is cordova-android 7.0+
* @see http://cordova.apache.org/announcements/2017/12/04/cordova-android-7.0.0.html
*/
if (!manifestSource) {
pathToManifest = path.join(cordovaContext.opts.projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'AndroidManifest.xml');
manifestSource = xmlHelper.readXmlAsJson(pathToManifest);
}

// remove old intent-filters
cleanManifest = removeOldOptions(manifestSource);

Expand Down Expand Up @@ -186,13 +198,9 @@ function injectOptions(manifestData, pluginPreferences) {
launchActivity = activitiesList[launchActivityIndex];

// generate intent-filters

ulIntentFilters.push(createIntentReceiver());

pluginPreferences.hosts.forEach(function(host) {
host.paths.forEach(function(hostPath) {
ulIntentFilters.push(createIntentFilter(host.name, host.scheme, hostPath));

});
});

Expand Down Expand Up @@ -290,47 +298,6 @@ function createIntentFilter(host, scheme, pathName) {

injectPathComponentIntoIntentFilter(intentFilter, pathName);


return intentFilter;
}

function createIntentReceiver() {
var intentFilter = {

'data': [
{
'$': {
'android:mimeType':'audio/*'
}
}, {
'$': {
'android:mimeType':'application/*'
}
},
{
'$': {
'android:mimeType':'image/*'
}
}, {
'$': {
'android:mimeType':'text/*'
}
}
],
'action': [{
'$': {
'android:name': 'android.intent.action.SEND'
}
}],
'category': [{
'$': {
'android:name':'android.intent.category.DEFAULT'
}
}]
};

injectPathComponentIntoIntentFilter(intentFilter, '*');

return intentFilter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,26 @@ More documentation on that can be found here:
https://developer.android.com/training/app-indexing/enabling-app-indexing.html
*/

var fs = require('fs');
var path = require('path');
var mkpath = require('mkpath');
var ConfigXmlHelper = require('../configXmlHelper.js');
var WEB_HOOK_FILE_PATH = path.join('ul_web_hooks', 'android', 'android_web_hook.html');
var WEB_HOOK_TPL_FILE_PATH = path.join('plugins', 'cordova-universal-links-plugin', 'ul_web_hooks', 'android_web_hook_tpl.html');
var LINK_PLACEHOLDER = '[__LINKS__]';
var LINK_TEMPLATE = '<link rel="alternate" href="android-app://<package_name>/<scheme>/<host><path>" />';
var fs = require("fs");
var path = require("path");
var ConfigXmlHelper = require("../configXmlHelper.js");
var WEB_HOOK_FILE_PATH = path.join(
"ul_web_hooks",
"android",
"android_web_hook.html"
);
var WEB_HOOK_TPL_FILE_PATH = path.join(
"plugins",
"cordova-wtto00-universal-link",
"ul_web_hooks",
"android_web_hook_tpl.html"
);
var LINK_PLACEHOLDER = "[__LINKS__]";
var LINK_TEMPLATE =
'<link rel="alternate" href="android-app://<package_name>/<scheme>/<host><path>" />';

module.exports = {
generate: generateWebHook
generate: generateWebHook,
};

// region Public API
Expand All @@ -31,7 +40,7 @@ module.exports = {
function generateWebHook(cordovaContext, pluginPreferences) {
var projectRoot = cordovaContext.opts.projectRoot;
var configXmlHelper = new ConfigXmlHelper(cordovaContext);
var packageName = configXmlHelper.getPackageName('android');
var packageName = configXmlHelper.getPackageName("android");
var template = readTemplate(projectRoot);

// if template was not found - exit
Expand All @@ -40,7 +49,11 @@ function generateWebHook(cordovaContext, pluginPreferences) {
}

// generate hook content
var linksToInsert = generateLinksSet(projectRoot, packageName, pluginPreferences);
var linksToInsert = generateLinksSet(
projectRoot,
packageName,
pluginPreferences
);
var hookContent = template.replace(LINK_PLACEHOLDER, linksToInsert);

// save hook
Expand All @@ -62,9 +75,9 @@ function readTemplate(projectRoot) {
var tplData = null;

try {
tplData = fs.readFileSync(filePath, 'utf8');
tplData = fs.readFileSync(filePath, "utf8");
} catch (err) {
console.warn('Template file for android web hook is not found!');
console.warn("Template file for android web hook is not found!");
console.warn(err);
}

Expand All @@ -80,12 +93,13 @@ function readTemplate(projectRoot) {
* @return {String} list of <link /> tags
*/
function generateLinksSet(projectRoot, packageName, pluginPreferences) {
var linkTpl = LINK_TEMPLATE.replace('<package_name>', packageName);
var content = '';
var linkTpl = LINK_TEMPLATE.replace("<package_name>", packageName);
var content = "";

pluginPreferences.hosts.forEach(function(host) {
host.paths.forEach(function(hostPath) {
content += generateLinkTag(linkTpl, host.scheme, host.name, hostPath) + '\n';
pluginPreferences.hosts.forEach(function (host) {
host.paths.forEach(function (hostPath) {
content +=
generateLinkTag(linkTpl, host.scheme, host.name, hostPath) + "\n";
});
});

Expand All @@ -102,22 +116,22 @@ function generateLinksSet(projectRoot, packageName, pluginPreferences) {
* @return {String} <link /> tag
*/
function generateLinkTag(linkTpl, scheme, host, path) {
linkTpl = linkTpl.replace('<scheme>', scheme).replace('<host>', host);
if (path == null || path === '*') {
return linkTpl.replace('<path>', '');
linkTpl = linkTpl.replace("<scheme>", scheme).replace("<host>", host);
if (path == null || path === "*") {
return linkTpl.replace("<path>", "");
}

// for android we need to replace * with .* for pattern matching
if (path.indexOf('*') >= 0) {
path = path.replace(/\*/g, '.*');
if (path.indexOf("*") >= 0) {
path = path.replace(/\*/g, ".*");
}

// path should start with /
if (path.indexOf('/') != 0) {
path = '/' + path;
if (path.indexOf("/") != 0) {
path = "/" + path;
}

return linkTpl.replace('<path>', path);
return linkTpl.replace("<path>", path);
}

/**
Expand All @@ -136,9 +150,9 @@ function saveWebHook(projectRoot, hookContent) {

// write data to file
try {
fs.writeFileSync(filePath, hookContent, 'utf8');
fs.writeFileSync(filePath, hookContent, "utf8");
} catch (err) {
console.warn('Failed to create android web hook!');
console.warn("Failed to create android web hook!");
console.warn(err);
isSaved = false;
}
Expand All @@ -153,7 +167,9 @@ function saveWebHook(projectRoot, hookContent) {
*/
function createDirectoryIfNeeded(dir) {
try {
mkpath.sync(dir);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
} catch (err) {
console.log(err);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Additional documentation regarding apple-app-site-association file can be found


var path = require('path');
var mkpath = require('mkpath');
var fs = require('fs');
var rimraf = require('rimraf');
var ConfigXmlHelper = require('../configXmlHelper.js');
Expand Down Expand Up @@ -128,7 +127,9 @@ function saveContentToFile(filePrefix, content) {
*/
function createDirectoriesIfNeeded(dirPath) {
try {
mkpath.sync(dirPath);
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}
} catch (err) {
console.log(err);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Script only generates content. File it self is included in the xcode project in
var path = require('path');
var fs = require('fs');
var plist = require('plist');
var mkpath = require('mkpath');
var ConfigXmlHelper = require('../configXmlHelper.js');
var ASSOCIATED_DOMAINS = 'com.apple.developer.associated-domains';
var context;
Expand Down Expand Up @@ -52,7 +51,10 @@ function saveContentToEntitlementsFile(content) {
var filePath = pathToEntitlementsFile();

// ensure that file exists
mkpath.sync(path.dirname(filePath));
const dirPath = path.dirname(filePath)
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}

// save it's content
fs.writeFileSync(filePath, plistContent, 'utf8');
Expand Down
Loading

0 comments on commit e35f31b

Please sign in to comment.