Skip to content

Commit

Permalink
Fix 'add folder' button not being added sometimes
Browse files Browse the repository at this point in the history
Fixes #281
  • Loading branch information
canton7 committed Jul 3, 2016
1 parent a08ba3c commit 1e3a100
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions src/SyncTrayzor/Pages/ViewerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,38 @@ private void InitializeBrowser(ChromiumWebBrowser webBrowser)
{
if (e.Frame.IsMain && e.Url != "about:blank")
{
var addOpenFolder =
@"$('#folders .panel-footer .pull-right').prepend(" +
@" '<button class=""btn btn-sm btn-default"" onclick=""callbackObject.openFolder(angular.element(this).scope().folder.id)"">" +
@" <span class=""fa fa-folder-open""></span>" +
@" <span style=""margin-left: 3px"">" + Resources.ViewerView_OpenFolder + @"</span>" +
@" </button>')";
webBrowser.ExecuteScriptAsync(addOpenFolder);

var addFolderBrowse =
// I tried to do this using Syncthing's events, but it's very painful - the DOM is updated some time
// after the event is fired. It's a lot easier to just watch for changes on the DOM.
var addOpenFolderButton =
@"var syncTrayzorAddOpenFolderButton = function(elem) {" +
@" var $folder = elem.find('.panel-footer .pull-right');" +
@" $folder.find('.panel-footer .synctrayzor-add-folder-button').remove();" +
@" $folder.prepend(" +
@" '<button class=""btn btn-sm btn-default synctrayzor-add-folder-button"" onclick=""callbackObject.openFolder(angular.element(this).scope().folder.id)"">" +
@" <span class=""fa fa-folder-open""></span>" +
@" <span style=""margin-left: 3px"">" + Resources.ViewerView_OpenFolder + @"</span>" +
@" </button>');" +
@"};" +
@"new MutationObserver(function(mutations, observer) {" +
@" console.log('MUTATION!');"+
@" for (var i = 0; i < mutations.length; i++) {" +
@" for (var j = 0; j < mutations[i].addedNodes.length; j++) {" +
@" console.log('Mutating', mutations[i].addedNodes[j]);" +
@" syncTrayzorAddOpenFolderButton($(mutations[i].addedNodes[j]));" +
@" }" +
@" }" +
@"}).observe(document.getElementById('folders'), {" +
@" childList: true" +
@"});" +
@"syncTrayzorAddOpenFolderButton($('#folders'));" +
@"";
webBrowser.ExecuteScriptAsync(addOpenFolderButton);

var addFolderBrowse =
@"$('#folderPath').wrap($('<div/>').css('display', 'flex'));" +
@"$('#folderPath').after(" +
@" $('<button>').attr('id', 'folderPathBrowseButton')" +
@" .addClass('btn btn-sm btn-default')" +
@" .addClass('btn btn-sm btn-default')" +
@" .html('" + Resources.ViewerView_BrowseToFolder + @"')" +
@" .css({'flex-grow': 1, 'margin': '0 0 0 5px'})" +
@" .on('click', function() { callbackObject.browseFolderPath() })" +
Expand Down

0 comments on commit 1e3a100

Please sign in to comment.