Skip to content

Commit

Permalink
modified: appnativefy.js
Browse files Browse the repository at this point in the history
	modified:   script.sh
  • Loading branch information
sarweshparajuli committed Feb 20, 2021
1 parent c0b3485 commit b8de3df
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 89 deletions.
132 changes: 48 additions & 84 deletions appnativefy.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
#!/usr/bin/env node

const fs = require('fs');

var yargs = require('yargs');

var nativefier = require('nativefier').default;

var process = require('process');

const request = require('request')


const {
exec
} = require("child_process");


var blankstr = ""


console.log(__dirname);
const dirname = __dirname;
var style = blankstr.concat(__dirname, "/style.css");
console.log(style)

console.log(__dirname);
var argv = require('yargs/yargs')(process.argv.slice(2))
.usage('Make executable AppImages from any Website URL\n\nUsage: $0 [options]')
.help('help').alias('help', 'h')
.version('version', '1.3.0').alias('version', 'V')
.version('version', '2.0.0').alias('version', 'V')
.options({
name: {
alias: 'n',
Expand Down Expand Up @@ -51,15 +54,11 @@ var argv = require('yargs/yargs')(process.argv.slice(2))
requiresArg: true,
required: false
},
electronVersion: {
alias: 'e',
description: "<value> Electron version without the 'v'",
requiresArg: true,
required: false
},

})
.options({
blockexternalurls: {
description: "Block URLs that do not match internal URLs",
},
saveAs: {
description: "Show a 'Save as' dialog, while downloading items",
},
Expand Down Expand Up @@ -97,44 +96,26 @@ var name = str.replace(/\s+/g, '-')
var url = argv.url

var appnativefydir = blankstr.concat(process.env['HOME'], "/appnativefy");
console.log(appnativefydir);
try {
if (!fs.existsSync(appnativefydir)) {
fs.mkdirSync(appnativefydir);
console.log("Directory is created.");
} else {
console.log("Directory already exists.");
}
} catch (err) {
console.log(err);
}


if (argv.arch === undefined) {
var arch = "x64";
} else {
var arch = argv.arch
}

if (argv.appCopyright === undefined) {
var appcopyright = "";
} else {
var appcopyright = blankstr.concat("--app-copyright", " ", '"', argv.appCopyright, '"')
var appcopyright = argv.appCopyright
}

if (argv.appVersion === undefined) {
var appversion = "1.0.0";
} else {
var appversion = blankstr.concat("--app-version", " ", '"', argv.appVersion, '"')
var appversion = argv.appVersion
}

if (argv.electronVersion === undefined) {
var electronversion = "";
} else {
var electronversion = blankstr.concat("--electron-version", " ", '"', argv.electronVersion, '"')
}


if (argv.widevine === true) {
var widevine = true
} else {
Expand All @@ -143,29 +124,28 @@ if (argv.widevine === true) {

const download = (favicongen, icon, callback) => {
request.head(favicongen, (err, res, body) => {
request(favicongen)
.pipe(fs.createWriteStream(icon))
.on('close', callback)
request(favicongen)
.pipe(fs.createWriteStream(icon))
.on('close', callback)
})
}
}

if (argv.favicon === true) {
var favicongen = blankstr.concat("https://www.google.com/s2/favicons?sz=64&domain_url=", argv.url);
var icon = appnativefydir.concat("/icon.png");
var customicon = blankstr.concat('"', icon, '"')
download(favicongen, icon, () => {
console.log('✅ Done!')
})
var favicon = "true"
} else {
var favicongen = ""
var icon = ""
var favicon = "false"
}

if (argv.services === true) {
var honest = false
var services = '"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0"';
if (argv.internalurls === undefined) {
var internalurls = '(.*)';
if (argv.blockexternalurls === true) {
var blockexternalurls = true;
} else {
var blockexternalurls = false
}
} else {
var internalurls = argv.internalurls
}
Expand Down Expand Up @@ -203,36 +183,22 @@ if (argv.counter === true) {
var counter = false
}


if (argv.singleinstance === true) {
var singleinstance = true;
} else {
var singleinstance = false
}


console.log('Inspecting options');

console.log("name:", name);
console.log("url:", url);
console.log("app copyright:", argv.appCopyright);
console.log("app version:", argv.appVersion);
console.log("electron version:", argv.electronVersion);
console.log("widevine support:", widevine);
console.log("services:", argv.services);
console.log("internal urls:", argv.internalurls)
console.log("no overwrite:", argv.noOverwrite);
console.log("conceal:", argv.conceal);
console.log("counter:", argv.counter);
console.log("single instance:", argv.singleinstance)
console.log("css/js injection:", style);

var options = {
name: name, // will be inferred if not specified
targetUrl: url, // required
platform: 'linux', // defaults to the current system
arch: 'x64', // defaults to the current system
copyright: appcopyright,
version: appversion,
icon: customicon,
inject: style,
out: appnativefydir,
overwrite: overwrite,
asar: conceal, // see conceal
Expand All @@ -247,13 +213,13 @@ var options = {
ignoreGpuBlacklist: false,
enableEs3Apis: false,
internalUrls: internalurls, // defaults to URLs on same second-level domain as app
blockExternalUrls: true,
blockExternalUrls: blockexternalurls,
insecure: false,
honest: honest,
widevine: widevine,
zoom: 1.0,
singleInstance: singleinstance,
verbose: true,
verbose: false,
clearCache: false,
fileDownloadOptions: {
saveAs: downloaddialog, // always show "Save As" dialog
Expand All @@ -265,58 +231,56 @@ nativefier(options, function (error, appPath) {
console.error(error);
return;
}
console.log('App has been nativefied to', appPath);
var apptempdir = appnativefydir.concat("/.appimage-temp");
var appimagetooldir = appnativefydir.concat("/.appimagetool");

console.log(appnativefydir);
try {
if (!fs.existsSync(apptempdir)) {
fs.mkdirSync(apptempdir);
} else {
}
} else {}
} catch (err) {
console.log(err);

}

try {
if (!fs.existsSync(appimagetooldir)) {
fs.mkdirSync(appimagetooldir);
} else {
}
fs.mkdirSync(appimagetooldir);
} else {}
} catch (err) {
console.log(err);

}

var oldPath = appnativefydir.concat("/", name, "-linux-x64")
var newPath = apptempdir.concat("/", name, ".AppDir")

fs.rename(oldPath, newPath, function (err) {
if (err) throw err
console.log('Successfully moved file.')
})

var scriptsource = blankstr.concat(__dirname, "/script.sh")
var scriptout = blankstr.concat(appnativefydir, "/.script.sh")
fs.copyFile(scriptsource, scriptout, (err) => {
if (err) throw err;
console.log(scriptsource, 'was copied to', scriptout);
process.chdir(appnativefydir);
commandscript = blankstr.concat("chmod 755 ~/appnativefy/.script.sh && ~/appnativefy/.script.sh", " ", name, " ", dirname, " ", "&& rm -rf ~/appnativefy/.script.sh && rm -rf ~/appnativefy/.icon.png")
{
exec(commandscript, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
commandscript = blankstr.concat("chmod 755 ~/appnativefy/.script.sh && ~/appnativefy/.script.sh", " ", name, " ", dirname, " ", favicon, " ", url, "&& rm -rf ~/appnativefy/.script.sh && rm -rf ~/appnativefy/.icon.png"); {
exec(commandscript, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});
};
});



var appPath = appnativefydir.concat("/", name, "-x86_64.AppImage")
console.log('AppImage has been made to', appPath);
});
20 changes: 15 additions & 5 deletions script.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /bin/bash
#!/usr/bin/env bash
name=$1
dirname=$2
favicon=$3
mkdir -p ~/appnativefy && cd ~/appnativefy && mkdir -p .appimage-temp
cd .appimage-temp
(
Expand All @@ -13,6 +14,14 @@ cd .appimage-temp
echo
anotherfile=/usr/local/lib/node_modules/appnativefy/icon.png
FILE=resources/app/icon.png
b="true"

if [ "$favicon" = "$b" ]; then
favicon="https://www.google.com/s2/favicons?sz=64&domain_url="
faviconlink=$favicon$4

wget $faviconlink -O resources/app/icon.png
fi

if [ -f "$FILE" ]; then
echo "$FILE exists."
Expand All @@ -24,7 +33,10 @@ cd .appimage-temp
fi
fi


cp $dirname/style.css resources/app/inject/inject.css



cp resources/app/icon.png icon.png


Expand Down Expand Up @@ -53,6 +65,4 @@ cp *.AppImage ../
cd ..
rm -r ~/appnativefy/.appimage-temp
rm -r ~/appnativefy/.script.sh
if [ -f "~/appnativefy/icon.png" ]; then
rm ~/appnativefy/icon.png
fi
rm -rf ~/appnativefy/icon.png

0 comments on commit b8de3df

Please sign in to comment.