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

feat(apps): add permission and method for opening external links #1315

Merged
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
35 changes: 26 additions & 9 deletions js/lib/apps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ var BastyonApps = function(app){
uniq : false,
session : true
},

'externallink': {
name: 'permissions_name_externallink',
description: 'permissions_descriptions_externallink',
level: 1
},
'zaddress' : {
name : 'permissions_name_zaddress',
description : 'permissions_descriptions_zaddress',
Expand Down Expand Up @@ -304,6 +308,25 @@ var BastyonApps = function(app){
return Promise.resolve(signature)
}
},
openExternalLink: {
parameters : ['url'],
permissions: ['externallink'],
action : function({ data }){
const url = data.url
if (window.cordova?.InAppBrowser) {
window.cordova.InAppBrowser.open(url, '_system');
return Promise.resolve()
}

if (electron?.shell?.openExternal) {
electron.shell.openExternal(url);
return Promise.resolve()
}

window.open(url, '_blank');
Promise.resolve()
}
},

authFetch: {
permissions : ['authFetch'],
Expand Down Expand Up @@ -771,8 +794,6 @@ var BastyonApps = function(app){
return Promise.reject(appsError(e))
})

//// TODO CHECK ELECTRON NODE SAFE
return app.api.rpc(data.method, data.parameters, data.options)
}
},

Expand Down Expand Up @@ -1290,7 +1311,7 @@ var BastyonApps = function(app){
}

var requestPermission = function(application, permission, data, p){

if (application.manifest.permissions.indexOf(permission) == -1){
return Promise.reject(appsError('permission:notexistinmanifest:' + permission))
}
Expand Down Expand Up @@ -1465,10 +1486,6 @@ var BastyonApps = function(app){

return

/// getapplication by info.id
install(/* getapplication by info.id, */ info.cached).catch(e => {

})
}))


Expand Down Expand Up @@ -1841,4 +1858,4 @@ var BastyonApps = function(app){
}

if(typeof module != "undefined"){ module.exports = {BastyonApps}; }
else { window.BastyonApps = BastyonApps; }
else { window.BastyonApps = BastyonApps; }
6 changes: 5 additions & 1 deletion js/lib/apps/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ var BastyonSdk = function(){
})
}

self.openExternalLink = function(url){
return action('openExternalLink', {url})
}

self.barteron = {
account : function(data){
return action('barteron.account', data)
Expand Down Expand Up @@ -451,4 +455,4 @@ var BastyonSdk = function(){


if(typeof module != "undefined"){ module.exports = {BastyonSdk}; }
else { window.BastyonSdk = BastyonSdk; }
else { window.BastyonSdk = BastyonSdk; }
3 changes: 3 additions & 0 deletions localization/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -2801,6 +2801,9 @@ _l.permissions_name_chat = appname + " chat"
_l.permissions_name_geolocation = "Access to location"
_l.permissions_descriptions_geolocation = "The application asks for permission to access your location"

_l.permissions_name_externallink = "Opening External Links";
_l.permissions_descriptions_externallink = "The application requests permission to open external links in the browser or other applications";

_l.limits = "Limits"
_l.pay = "Pay"
_l.external_prepareTransaction = 'Payment is being processed'
Expand Down
3 changes: 3 additions & 0 deletions localization/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -2605,6 +2605,9 @@ _l.permissions_name_chat = appname + " чат"
_l.permissions_name_geolocation = "Доступ к местоположению"
_l.permissions_descriptions_geolocation = "Приложение запрашивает разрешение к вашему местоположению"

_l.permissions_name_externallink = "Открытие внешних ссылок";
_l.permissions_descriptions_externallink = "Приложение запрашивает доступ на открытие внешних ссылок в браузере или других приложениях";


_l.limits = "Лимиты"
_l.pay = "Оплатить"
Expand Down