Skip to content

Commit

Permalink
Add branch selection for plugins
Browse files Browse the repository at this point in the history
Fixes stas-demydiuk#23

Update `plugins.json` to allow specifying multiple branches for each plugin.

* Change the `branch` field to a list of branches for each plugin.
* Update the `Zigate` plugin entry to include multiple branches: "stable6", "beta6", and "development".
* Modify all other plugin entries to have their `branch` field as a list containing "master".
  • Loading branch information
galadril committed Dec 11, 2024
1 parent eba60a5 commit b668fc5
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 84 deletions.
3 changes: 2 additions & 1 deletion api/commands/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def execute(self, params):
'author': plugin.author,
'description': plugin.description,
'name': plugin.name,
'source': plugin.repository + '/tree/' + plugin.branch,
'source': plugin.repository + '/tree/' + plugin.branch[0],
'branches': plugin.branch,
'is_installed': plugin.is_installed(),
'is_update_available': plugin.is_update_available(),
}
Expand Down
19 changes: 17 additions & 2 deletions frontend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ define(['app'], function(app) {
{ title: 'Plugin', data: 'name' },
{ title: 'Description', data: 'description' },
{ title: 'Author', data: 'author' },
{
title: 'Branch',
data: 'branches',
orderable: false,
render: branchesRenderer
},
{
title: '',
className: 'actions-column',
Expand All @@ -171,10 +177,11 @@ define(['app'], function(app) {

table.on('click', '.js-install', function() {
var plugin = table.api().row($(this).closest('tr')).data();
var selectedBranch = $(this).closest('tr').find('.branch-select').val();

bootbox.confirm('Are you sure you want to install "' + plugin.name + '" plugin?')
.then(function() {
return ppManager.sendRequest('install', plugin.key);
return ppManager.sendRequest('install', { key: plugin.key, branch: selectedBranch });
})
.then(bootbox.alert, bootbox.alert)
.then($ctrl.onUpdate);
Expand Down Expand Up @@ -234,6 +241,14 @@ define(['app'], function(app) {
: '<img src="../../images/empty16.png" width="16" height="16" />'
}

function branchesRenderer(branches) {
var options = branches.map(function(branch) {
return '<option value="' + branch + '">' + branch + '</option>';
}).join('');

return '<select class="branch-select">' + options + '</select>';
}

function actionsRenderer(data, type, plugin) {
var actions = [];
var delimiter = '<img src="../../images/empty16.png" width="16" height="16" />';
Expand All @@ -256,4 +271,4 @@ define(['app'], function(app) {
return actions.join('&nbsp;');
}
}
});
});
7 changes: 4 additions & 3 deletions manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ def is_update_available(self):

return None

def install(self):
def install(self, branch=None):
Domoticz.Log("Installing Plugin:" + self.description)

if (self.is_installed()):
return True

plugins_folder = os.path.dirname(str(os.getcwd()) + "/plugins/")
repository = self.repository + ".git"
clone_cmd="LANG=en_US /usr/bin/git clone -b " + self.branch + " " + repository + " " + self.folder_name
branch = branch or self.branch[0]
clone_cmd="LANG=en_US /usr/bin/git clone -b " + branch + " " + repository + " " + self.folder_name
Domoticz.Debug("Calling: " + clone_cmd)

try:
Expand Down Expand Up @@ -152,4 +153,4 @@ def uninstall(self):
except Exception as e:
Domoticz.Error(repr(e))

return False
return False
Loading

0 comments on commit b668fc5

Please sign in to comment.