Skip to content

Commit 9ce3b13

Browse files
authored
feat: add samples (#12)
* feat: add samples
1 parent d074072 commit 9ce3b13

File tree

8 files changed

+70
-16
lines changed

8 files changed

+70
-16
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
"graceful-updater": "1",
2323
"lodash": "4",
2424
"moment": "^2.29.4",
25-
"network-interface": "18",
2625
"semver": "^7.3.8"
2726
},
27+
"optionalDependencies": {
28+
"network-interface": "18",
29+
"windows-verify-trust": "1"
30+
},
2831
"devDependencies": {
2932
"@applint/spec": "^1.2.3",
3033
"@electron/asar": "3",

scripts/electron.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const nodemon = require('gulp-nodemon');
66
function startElectron(done) {
77
const stream = nodemon({
88
script: path.resolve(__dirname, 'launcher.js'),
9-
ext: 'ts js json',
9+
ext: 'ts js json html',
1010
ignore: [],
1111
watch: [
1212
'src',

src/app.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
import { ipcMain } from 'electron';
1+
import { ipcMain, dialog } from 'electron';
22

33
export default class App {
44
init() {
5+
this.isWin = process.platform === 'win32';
56
require('./window-manager')(this);
67
this.bindIPC();
78
}
89

10+
alertWindows() {
11+
dialog.showErrorBox('error', 'only windows');
12+
}
13+
914
bindIPC() {
15+
const { isWin } = this;
1016
ipcMain.on('start-action', (_, action) => {
1117
if (action === 'electrom') {
1218
require('./electrom')(this);
@@ -17,7 +23,23 @@ export default class App {
1723
} else if (action === 'electron-webview-schedule') {
1824
require('./webview-schedule')(this);
1925
} else if (action === 'electron-windows-titlebar') {
20-
require('./windows-titlebar')(this);
26+
if (isWin) {
27+
require('./windows-titlebar')(this);
28+
return;
29+
}
30+
this.alertWindows();
31+
} else if (action === 'network-interface') {
32+
if (isWin) {
33+
require('./network-interface')(this);
34+
return;
35+
}
36+
this.alertWindows();
37+
} else if (action === 'windows-verify-trust') {
38+
if (isWin) {
39+
require('./windows-verify-trust')(this);
40+
return;
41+
}
42+
this.alertWindows();
2143
}
2244
});
2345
}

src/network-interface/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
import networkInterface from 'network-interface';
4+
5+
module.exports = (app: any) => {
6+
networkInterface.addEventListener('wlan-status-changed', (error, data) => {
7+
if (error) {
8+
throw error;
9+
return;
10+
}
11+
console.log('event fired: wlan-status-changed');
12+
console.log(data);
13+
});
14+
};

src/renderer/main.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,27 @@
1010
}
1111
html,
1212
body {
13-
background-color: white;
1413
width: 100%;
1514
height: 100%;
1615
margin: 0;
1716
padding: 0;
17+
overflow: hidden;
1818
}
1919
hr {
20-
margin: 12px 0;
20+
margin: 8px 0;
2121
border: none;
2222
height: 1px;
2323
background-color: #ebebeb;
2424
}
25-
h2, ol {
25+
h3, ol {
2626
margin: 0;
2727
padding: 0;
2828
}
2929
ol {
3030
padding-left: 20px;
3131
}
3232
li {
33-
margin: 16px 0;
33+
margin: 8px 0;
3434
padding: 4px;
3535
cursor: pointer;
3636
background-color: aliceblue;
@@ -43,11 +43,15 @@
4343
.wrapper {
4444
padding: 12px;
4545
}
46+
.wrapper a {
47+
font-size: 14px;
48+
margin: 4px 0;
49+
}
4650
</style>
4751
</head>
4852
<body>
4953
<div class="wrapper">
50-
<h2>Electron Modules</h2>
54+
<h3>Electron Modules</h3>
5155
<a href="https://github.com/electron-modules" target="_blank">
5256
https://github.com/electron-modules
5357
</a>
@@ -59,6 +63,7 @@ <h2>Electron Modules</h2>
5963
<li data-action="electron-webview-schedule">📚 Electron Webview Schedule</li>
6064
<li data-action="electron-windows-titlebar">🌓 Electron Windows Titlebar</li>
6165
<li data-action="network-interface">💻 Network Interface</li>
66+
<li data-action="windows-verify-trust">🛡 Windows Verify Trust</li>
6267
<ol>
6368
</div>
6469
<script src="./main.js"></script>

src/window-manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ module.exports = (app) => {
2222
url: loadingUrl,
2323
},
2424
browserWindow: {
25-
width: 640,
26-
height: 420,
25+
width: 580,
26+
height: 390,
2727
webPreferences: {
2828
enableRemoteModule: false,
2929
nodeIntegration: false,

src/windows-titlebar/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

3-
const url = require('url');
4-
const path = require('path');
5-
const _ = require('lodash');
6-
const { ipcMain } = require('electron');
7-
const windowTitleBar = require('electron-windows-titlebar');
3+
import url from 'url';
4+
import path from 'path';
5+
import _ from 'lodash';
6+
import { ipcMain } from 'electron';
7+
import windowTitleBar from 'electron-windows-titlebar';
88

99
module.exports = (app: any) => {
1010
const windowUrl = url.format({

src/windows-verify-trust/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
import { isLibExist, getLibPath, verifyTrust } from 'windows-verify-trust';
4+
5+
module.exports = (app: any) => {
6+
const targetFileName = 'wlanapi.dll';
7+
console.log('isLibExist: %s', isLibExist(targetFileName));
8+
console.log('getLibPath: %s', getLibPath(targetFileName));
9+
console.log('verifyTrust: %s', verifyTrust(targetFileName));
10+
};

0 commit comments

Comments
 (0)