Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 515ceda

Browse files
divyanshu rawatdivyanshu rawat
divyanshu rawat
authored and
divyanshu rawat
committed
done with countdown
1 parent b1451d9 commit 515ceda

File tree

5 files changed

+51
-10
lines changed

5 files changed

+51
-10
lines changed

‎src/count.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11

22

3-
module.exports = function countdown(){
3+
module.exports = function countdown(tick){
44

55
let count = 10;
66
var interval = setInterval(_ => {
7-
count--;
8-
9-
console.log("count : ",count);
7+
tick(count--);
108
if(count == 0){
119

1210
clearInterval(interval);

‎src/index.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
h1{
33

44
font-family: sans-serif;
5-
color: red;
6-
}
5+
}
6+

‎src/index.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,22 @@
33
<html>
44
<head>
55

6-
<linkrel="stylesheet" type="text/css" href="index.css">
6+
77
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
8+
<link rel="stylesheet" type="text/css" href="index.css">
89
<!-- <script type="text/javascript" src = "count.js"></script> -->
910
</head>
1011
<body>
12+
13+
<div class="container">
1114
<h1> Welcome </h1>
15+
16+
<button id = "start" class="btn btn-success custom">click Me !</button>
17+
18+
<div>
19+
<p id = "dispCount"></p>
20+
</div>
21+
</div>
1222
</body>
1323

1424
<script>require('./render')</script>

‎src/main.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const app = electron.app;
44

55
const countdown = require('./count');
66

7+
const ipc = electron.ipcMain;
8+
79
let mainWindow;
810
// In order to see some UI in my electron application I have importing browserwindow module.
911

@@ -22,8 +24,6 @@ app.on('ready', _=> {
2224

2325
mainWindow.loadURL('file://' + __dirname + '/index.html');
2426

25-
countdown();
26-
2727
mainWindow.on('closed',_ =>{
2828

2929
console.log("Closed");
@@ -32,5 +32,19 @@ app.on('ready', _=> {
3232

3333
});
3434

35+
})
36+
37+
ipc.on('countdown-start', _=>{
38+
39+
countdown(count =>{
40+
41+
// webContents is a just a Event Emitter instance !
42+
mainWindow.webContents.send('count',count);
43+
44+
});
45+
46+
})
47+
48+
49+
3550

36-
})

‎src/render.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
3+
const electron = require('electron');
4+
5+
const ipc = electron.ipcRenderer;
6+
7+
document.getElementById('start').addEventListener('click',_ =>{
8+
9+
ipc.send('countdown-start');
10+
11+
})
12+
13+
14+
15+
ipc.on("count",(event,count)=>{
16+
17+
document.getElementById('dispCount').innerHTML = count;
18+
19+
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /