Skip to content

Commit

Permalink
Fixed issue with badge handler.
Browse files Browse the repository at this point in the history
Added remove project button functionality.
Removed "EDIT" button as it was useless.
  • Loading branch information
Naphier committed Jan 28, 2019
1 parent 61370a1 commit d971894
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 27 deletions.
11 changes: 7 additions & 4 deletions GitMon.njsproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
<Name>GitMon</Name>
<RootNamespace>GitMon</RootNamespace>
<SaveNodeJsSettingsInProjectFile>True</SaveNodeJsSettingsInProjectFile>
<NodeExePath>C:\Program Files\nodejs\node.exe</NodeExePath>
<NodeExeArguments>
</NodeExeArguments>
<NodeExePath>D:\@Documents\My Open Source Repos\GitMon\node_modules\electron\dist\electron.exe</NodeExePath>
<NodeExeArguments>main.js</NodeExeArguments>
<JavaScriptTestFramework>ExportRunner</JavaScriptTestFramework>
<ScriptArguments>--inspect-brk</ScriptArguments>
<DebuggerPort>5858</DebuggerPort>
<NodejsPort>
</NodejsPort>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand All @@ -24,7 +27,7 @@
<OutputPath>.</OutputPath>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<ProjectTypeGuids>{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}</ProjectTypeGuids>
<StartWebBrowser>False</StartWebBrowser>
<StartWebBrowser>True</StartWebBrowser>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@
<br>
<b>Legend:</b><br />
<img src="media/legend.png" style="width:100%" />
<p>
Node JS Version: <script>document.write(process.versions.node)</script><br>
Chrome Version: <script>document.write(process.versions.chrome)</script><br>
Electron Version: <script>document.write(process.versions.electron)</script>
</p>
</div>
</div>
</div>
Expand Down
43 changes: 28 additions & 15 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function onReady() {
}

ipcMain.on('zoomSet', function (event, newZoom) {
console.log('newZoom: '.concat(newZoom));
//console.log('newZoom: '.concat(newZoom));
store.set('zoomAdjustment', newZoom - 1);
});

Expand Down Expand Up @@ -179,14 +179,22 @@ ipcMain.on('scanDirectory', function (event, data) {
}
});

// TODO - handle remove project call
ipcMain.on('removeProject', function (event, data) {

});

// TODO - handle edit directory call
ipcMain.on('editDirectory', function (event, data) {

ipcMain.on('removeProject', function (event, status) {
dialog.showMessageBox(
null,
{
buttons: ['Yes', 'No'],
title: 'Confirm Removal',
type: 'info',
message: 'Are you sure you want to remove ' + status.proj + '?'
},
function (response, checkBoxChecked) {
if (response === 0) {
delete resultsCache[status.dir];
refreshStatusListUi();
updateBadge();
}
});
});

// TODO - handle set new interval call
Expand All @@ -213,6 +221,9 @@ function refreshStatusListUi() {


for (var key in resultsCache) {
if (!key || !resultsCache[key])
continue;

win.webContents.send(
'setGitStatus',
JSON.stringify(resultsCache[key])
Expand Down Expand Up @@ -279,32 +290,34 @@ function sortResultsCache() {
}
}

/*
for (var key in resultsCache) {
console.log(resultsCache[key].proj + ' '.concat(resultsCache[key].outOfDate));
}

*/
}
}

// TODO schedule runs
function mainLoop() {
console.log('mainLoop');
//console.log('mainLoop');
// if we loop through and do fetches then refresh is not needed
refreshStatusListUi();
updateBadge();
}

function updateBadge() {
if (resultsCache && resultsCache.length > 0) {
if (resultsCache) {
for (var key in resultsCache) {
if (resultsCache[key] && resultsCache[key].outOfDate) {
win.webContents.send('setBadge', true);
console.log('should set badge');
return;
}
}

win.webContents.send('setBadge', false);
}
//console.log('should unset badge');
win.webContents.send('setBadge', false);
}

// TODO: handle --show-stash
Expand All @@ -321,7 +334,7 @@ function runGitFetch(dir, onSuccess, onError) {
} else {
onError(new GitError(
GitErrType.Unknown,
'Unkown error at directory: \''.concat(dir).concat('\'')));
'Unknown error at directory: \''.concat(dir).concat('\'')));
}

console.error('runGitFetch child-process err: \r\n'.concat(err));
Expand Down
5 changes: 3 additions & 2 deletions renderer/badgeHandler.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
ipcRenderer.on('setBadge', function (event, on) {
//console.log('setBadge: '.concat(on));
var image = null;
if (on) {
var nativeImage = remoteR.nativeImage;
var nativeImage = remote.nativeImage;
image = nativeImage.createFromPath('./media/icon-overlay.png');
}
remoteR.getCurrentWindow().setOverlayIcon(image, '');
remote.getCurrentWindow().setOverlayIcon(image, '');
});
12 changes: 6 additions & 6 deletions renderer/gitStatusResultDOMHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ ipcRenderer.on('setGitStatus', function (event, gitStatusResult) {
var status = JSON.parse(gitStatusResult);
var statusDivNode = document.getElementById(status.proj);
if (statusDivNode) {
//TODO update element
console.log('update element');
document.removeChild(statusDivNode);
} else {
// create element and insert into dom
statusDivNode = document.createElement('span');
Expand Down Expand Up @@ -68,24 +67,25 @@ ipcRenderer.on('setGitStatus', function (event, gitStatusResult) {
statusDivNode.appendChild(untrackedNode);
}

// delete and modify buttons
// delete button
var trashNode = document.createElement('span');
trashNode.classList.add('trashButton');
trashNode.innerHTML = '<i class="far fa-trash-alt"></i>';
trashNode.addEventListener('click', function () {
// TODO remove project handler
console.log('trash clicked for: ' + status.proj);
ipcRenderer.send('removeProject', status);
//console.log('trash clicked for: ' + status.proj);
});
statusDivNode.appendChild(trashNode);

/*
var editNode = document.createElement('span');
editNode.classList.add('editButton');
editNode.innerHTML = '<i class="far fa-edit"></i>';
editNode.addEventListener('click', function () {
// TODO edit project handler
console.log('edit clicked for: ' + status.proj);
});
statusDivNode.appendChild(editNode);
*/

document.getElementById('home').appendChild(statusDivNode);
}
Expand Down

0 comments on commit d971894

Please sign in to comment.