Skip to content

Commit 1458746

Browse files
add new powerMonitor API js file - fix formating
1 parent 6690b4a commit 1458746

File tree

8 files changed

+30
-43
lines changed

8 files changed

+30
-43
lines changed

ElectronNET.API/PowerMonitor.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
using ElectronNET.API.Entities;
2-
using ElectronNET.API.Extensions;
3-
using Newtonsoft.Json;
4-
using Newtonsoft.Json.Linq;
5-
using Newtonsoft.Json.Serialization;
6-
using System;
7-
using System.Collections.Generic;
8-
using System.Threading.Tasks;
1+
using System;
92

103
namespace ElectronNET.API
114
{
@@ -14,9 +7,6 @@ namespace ElectronNET.API
147
/// </summary>
158
public sealed class PowerMonitor
169
{
17-
18-
19-
2010
/// <summary>
2111
/// Emitted when the system is about to lock the screen.
2212
/// </summary>
@@ -74,9 +64,6 @@ public event Action OnUnLockScreen
7464
}
7565

7666
private event Action _unlockScreen;
77-
78-
79-
8067
private static PowerMonitor _powerMonitor;
8168
private static object _syncRoot = new object();
8269

@@ -100,8 +87,5 @@ internal static PowerMonitor Instance
10087
return _powerMonitor;
10188
}
10289
}
103-
104-
105-
10690
}
10791
}

ElectronNET.CLI/Commands/Actions/DeployEmbeddedElectronFiles.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public static void Do(string tempPath)
3030
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "clipboard.js", "api.");
3131
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "autoUpdater.js", "api.");
3232
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserView.js", "api.");
33+
EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "powerMonitor.js", "api.");
3334

3435
string splashscreenFolder = Path.Combine(tempPath, "splashscreen");
3536
if (Directory.Exists(splashscreenFolder) == false)

ElectronNET.CLI/ElectronNET.CLI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<EmbeddedResource Include="..\ElectronNET.Host\api\clipboard.js" Link="ElectronHost\api\clipboard.js" />
7272
<EmbeddedResource Include="..\ElectronNET.Host\api\autoUpdater.js" Link="ElectronHost\api\autoUpdater.js" />
7373
<EmbeddedResource Include="..\ElectronNET.Host\api\browserView.js" Link="ElectronHost\api\browserView.js" />
74+
<EmbeddedResource Include="..\ElectronNET.Host\api\powerMonitor.js" Link="ElectronHost\api\powerMonitor.js" />
7475
</ItemGroup>
7576

7677
<ItemGroup>

ElectronNET.Host/api/clipboard.js

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ElectronNET.Host/api/clipboard.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ElectronNET.Host/api/clipboard.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,22 @@ export = (socket: SocketIO.Socket) => {
6262
});
6363

6464
socket.on('clipboard-readImage', (type) => {
65-
var image = clipboard.readImage(type);
65+
const image = clipboard.readImage(type);
6666
electronSocket.emit('clipboard-readImage-Completed', { 1: image.toPNG().toString('base64') });
6767
});
6868

6969
socket.on('clipboard-writeImage', (data, type) => {
70-
var data = JSON.parse(data);
71-
const ni = nativeImage.createEmpty();
72-
for (var i in data) {
73-
var scaleFactor = i;
74-
var bytes = data[i];
75-
var buff = Buffer.from(bytes, 'base64');
76-
ni.addRepresentation({ scaleFactor: +scaleFactor, buffer: buff });
70+
const dataContent = JSON.parse(data);
71+
const image = nativeImage.createEmpty();
72+
73+
// tslint:disable-next-line: forin
74+
for (const key in dataContent) {
75+
const scaleFactor = key;
76+
const bytes = data[key];
77+
const buffer = Buffer.from(bytes, 'base64');
78+
image.addRepresentation({ scaleFactor: +scaleFactor, buffer: buffer });
7779
}
78-
79-
clipboard.writeImage(ni, type);
80+
81+
clipboard.writeImage(image, type);
8082
});
8183
};

ElectronNET.Host/main.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ function startSocketApiBridge(port) {
177177
browserView = require('./api/browserView')(socket);
178178
powerMonitor = require('./api/powerMonitor')(socket);
179179

180-
181-
182180
try {
183181
const hostHookScriptFilePath = path.join(__dirname, 'ElectronHostHook', 'index.js');
184182

ElectronNET.WebApp/Controllers/HomeController.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Microsoft.AspNetCore.Mvc;
22
using ElectronNET.API;
3-
using ElectronNET.API.Entities;
43
using System;
54

65
namespace ElectronNET.WebApp.Controllers
@@ -13,15 +12,16 @@ public IActionResult Index()
1312
{
1413
Electron.PowerMonitor.OnLockScreen += () =>
1514
{
16-
Console.WriteLine("Screen Locked detected from C #");
15+
Console.WriteLine("Screen Locked detected from C#");
1716
};
1817

1918
Electron.PowerMonitor.OnUnLockScreen += () =>
2019
{
21-
Console.WriteLine("Screen unlocked detected from C # ");
20+
Console.WriteLine("Screen unlocked detected from C# ");
2221
};
2322
}
24-
return View();
23+
24+
return View();
2525
}
2626
}
2727
}

0 commit comments

Comments
 (0)