Skip to content

Commit

Permalink
patch: android configurations (#765)
Browse files Browse the repository at this point in the history
- Fix hooks added in PR #755
- Store script added in package
- Build process updates

Co-authored-by: Shpingalet007 <22795961+shpingalet007@users.noreply.github.com>
  • Loading branch information
maxgithubprofile and shpingalet007 authored Nov 18, 2022
1 parent 42ea33b commit 3e61edd
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 32 deletions.
14 changes: 14 additions & 0 deletions cordova/hooks/after-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { execSync } = require('child_process');

function androidAfterBuild() {
console.log('Running Android after build hook...');

console.log('Removing "cordova-plugin-apkupdater@4.0.0" needed by Android app');
execSync('cordova plugin remove cordova-plugin-apkupdater');
}

module.exports = function(context) {
switch (context.opts.platforms[0]) {
case 'android': return androidAfterBuild();
}
}
16 changes: 8 additions & 8 deletions cordova/hooks/before-build.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const { execSync } = require('child_process');

function androidPrebuild() {
console.log('Running Android prebuild hook...');
function androidBeforeBuild() {
console.log('Running Android before build hook...');

console.log('Installing "cordova-plugin-apkupdater@4.0.0" needed by Android app');
execSync('npm install cordova-plugin-apkupdater@4.0.0 --no-save');
execSync('cordova plugin add cordova-plugin-apkupdater@4.0.0');
}

function iosPrebuild() {
console.log('Running iOS prebuild hook...');
function iosBeforeBuild() {
console.log('Running iOS before build hook...');

console.log('Removing "cordova-plugin-apkupdater@4.0.0" needed by Android app');
execSync('npm remove cordova-plugin-apkupdater@4.0.0 --no-save');
execSync('cordova plugin remove cordova-plugin-apkupdater@4.0.0');
}

module.exports = function(context) {
switch (context.opts.platforms[0]) {
case 'android': return androidPrebuild();
case 'ios': return iosPrebuild();
case 'android': return androidBeforeBuild();
case 'ios': return iosBeforeBuild();
}
}
12 changes: 6 additions & 6 deletions cordova/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2601,7 +2601,7 @@ Application = function(p)
needmanage : false,
hasupdate : false,

playstore : false, ///// TODO
playstore : window.pocketnetstore || false, ///// TODO

downloadAndInstall : function(){

Expand Down
48 changes: 36 additions & 12 deletions minimize.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var mapJsPath = './js/_map.js';
console.log("run")
console.log(args)

var tpls = ['embedVideo.php', 'index_el.html', 'index.html', 'index.php', 'indexcordova.html', 'config.xml', 'openapi.html', /*'.htaccess',*/ 'service-worker.js', 'manifest.json', 'main.js']
var tpls = ['embedVideo.php', 'index_el.html', 'index.html', 'index.php', 'indexcordova.html', {name : 'config.xml', underscoreTemplate : true}, 'openapi.html', /*'.htaccess',*/ 'service-worker.js', 'manifest.json', 'main.js']

var tplspath = {

Expand All @@ -101,21 +101,27 @@ var vars = {
test : '<script>window.testpocketnet = true;</script>',
globaltest : 'global.TESTPOCKETNET = true;',
path : args.path,
project : args.project
project : args.project,
store : args.store || false
},
prod : {
proxypath : '"https://pocketnet.app:8899/"',
domain : _meta[args.project].url,
test : '',
globaltest : '',
path : args.path,
project : args.project
project : args.project,
store : args.store || false

}
}


var VARS = args.test ? vars.test : vars.prod

console.log('VARS', VARS)


var babelifycode = function(code){
var c = bablecore.transformSync(code, {
presets: [
Expand Down Expand Up @@ -832,6 +838,14 @@ fs.exists(mapJsPath, function (exists) {

var createTemplatedFile = function(tplname){
/*WORK WITH INDEX*/

var options = {}

if(_.isObject(tplname)) {
options = tplname
tplname = tplname.name
}

var pth = './tpls/' + tplname + '.tpl'

console.log("CREATING TEMPLATE: ", tplname)
Expand All @@ -854,23 +868,29 @@ fs.exists(mapJsPath, function (exists) {
var CACHED_FILES = "";

if(args.test){
JSENV += '<script>window.testpocketnet = true;</script>';
JSENV += '<script>window.testpocketnet = true;</script>\n';
}

if(args.path){
JSENV += '<script>window.pocketnetpublicpath = "'+args.path+'";</script>';
JSENV += '<script>window.pocketnetpublicpath = "'+args.path+'";</script>\n';
}

if(VARS.domain){
JSENV += '<script>window.pocketnetdomain = "' + VARS.domain + '";</script>';
JSENV += '<script>window.pocketnetdomain = "' + VARS.domain + '";</script>\n';
}

if(VARS.project){
JSENV += '<script>window.pocketnetproject = "' + VARS.project + '";</script>';
JSENV += '<script>window.pocketnetproject = "' + VARS.project + '";</script>\n';
}

JSENV += '<script>window.packageversion = "' + package.version + '";</script>';
JSENV += '<script>window.versionsuffix = "' + package.versionsuffix + '";</script>';
if(VARS.store){
JSENV += '<script>window.pocketnetstore = ' + VARS.store + ';</script>\n';
}


JSENV += '<script>window.packageversion = "' + package.version + '";</script>\n';
JSENV += '<script>window.versionsuffix = "' + package.versionsuffix + '";</script>\n';


vs = numfromreleasestring(package.version) + '_' + (package.versionsuffix || "0")

Expand All @@ -890,7 +910,7 @@ fs.exists(mapJsPath, function (exists) {
{


JSENV += '<script>window.design = true;</script>';
JSENV += '<script>window.design = true;</script>\n';

_.each(m.__sourcesfirst, function(source){

Expand Down Expand Up @@ -958,6 +978,12 @@ fs.exists(mapJsPath, function (exists) {
_.each(VARS, function(v, i){
index = index.replaceAll("__VAR__." + i, v);
})

if(options.underscoreTemplate){
var t = _.template(index)

index = t(VARS)
}

fs.writeFile('./' + tplname, index, function(err) {

Expand Down Expand Up @@ -1068,10 +1094,8 @@ var copycontent = function(options, clbk, nac) {
ncp(p.item, options.path + '/' + p.item, {
filter : function(name){

console.log('p.item', p.item, name)

if(options.filter){
console.log('filter', options.filter(p.item, name))
return options.filter(p.item, name)
}
else
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "pocketnet",

"version": "0.8.22",
"version": "0.8.32",
"versionsuffix": "5",
"cordovaversion": "1.8.22",
"cordovaversioncode": "180207",
"cordovaversion": "1.8.32",
"cordovaversioncode": "180320",

"description": "Bastyon desktop application",
"author": "Pocketnet Community <support@pocketnet.app>",
Expand All @@ -27,6 +27,7 @@
"dev": "node minimize.js -prodaction=false -path=/pocketnet/",
"dev:test": "node minimize.js -prodaction=false -test=true -path=/pocketnet/",
"minimize:cordova": "node minimize.js -prodaction=true -vendor=30068 -path=/pocketnet/ -project=Bastyon -composetemplates=true",
"minimize:cordova:store": "node minimize.js -prodaction=true -vendor=30068 -path=/pocketnet/ -project=Bastyon -composetemplates=true -store=true",
"minimize:cordova:test": "node minimize.js -prodaction=true -test=true -vendor=30068 -path=/pocketnet/ -project=Bastyon -composetemplates=true",
"minimize:bastyon": "node minimize.js -prodaction=true -vendor=30068 -path=/ -project=Bastyon",
"minimize:bastyon:test": "node minimize.js -prodaction=true -vendor=30068 -test=true -path=/ -project=Bastyon",
Expand Down
15 changes: 13 additions & 2 deletions tpls/config.xml.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<widget android-versionCode="__PACKAGE-CORDOVAVERSIONCODE__" android-packageName="pocketnet.app" ios-CFBundleIdentifier="app.pocketnet" version="__PACKAGE-CORDOVAVERSION__" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget android-versionCode="__PACKAGE-CORDOVAVERSIONCODE__" android-packageName="pocketnet.app" ios-CFBundleIdentifier="app.pocketnet" version="__PACKAGE-CORDOVAVERSION__" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:tools="http://schemas.android.com/tools">
<name>__VAR__.project</name>
<description>
__VAR__.project Application
Expand Down Expand Up @@ -165,6 +165,10 @@

<preference name="AndroidXEnabled" value="true" />

<edit-config file="AndroidManifest.xml" target="/manifest" mode="merge">
<manifest xmlns:tools="http://schemas.android.com/tools" />
</edit-config>

<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:usesCleartextTraffic="true" android:requestLegacyExternalStorage="true"/>
</edit-config>
Expand All @@ -176,6 +180,9 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<% if(store) {%>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" tools:node="remove" />
<% } %>
</config-file>

<edit-config file="AndroidManifest.xml" target="/manifest/application/activity[@android:name='MainActivity']" mode="merge">
Expand Down Expand Up @@ -206,6 +213,10 @@
</host>

</universal-links>
<% if(!store) {%>
<hook type="before_build" src="hooks/before-build.js" />
<hook type="after_build" src="hooks/after-build.js" />
<hook type="before_build" src="hooks/before-build.js" />
<% } %>
</widget>

0 comments on commit 3e61edd

Please sign in to comment.