Skip to content

Commit 7d58b0e

Browse files
authored
Update index.js
1 parent 09efa07 commit 7d58b0e

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

index.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
console.log('🕖 Starting...')
22

33
import { join, dirname } from 'path'
4-
import { createRequire } from "module"
4+
import { createRequire } from 'module'
55
import { fileURLToPath } from 'url'
66
import { setupMaster, fork } from 'cluster'
77
import { watchFile, unwatchFile } from 'fs'
@@ -15,6 +15,13 @@ const require = createRequire(__dirname)
1515
const { say } = cfonts
1616
const rl = createInterface(process.stdin, process.stdout)
1717

18+
function isWIBMidnight() {
19+
const now = new Date()
20+
const utc = now.getTime() + now.getTimezoneOffset() * 60000
21+
const wib = new Date(utc + 7 * 3600000)
22+
return wib.getHours() === 0
23+
}
24+
1825
async function runUpdater() {
1926
const originalLog = console.log
2027
const logs = []
@@ -30,8 +37,17 @@ async function runUpdater() {
3037
try {
3138
const updaterPath = new URL('./lib/system.js', import.meta.url)
3239
const { default: checkUpdate } = await import(updaterPath)
33-
await checkUpdate()
40+
41+
if (global.config.cekupdate && isWIBMidnight()) {
42+
await checkUpdate()
43+
} else {
44+
await checkUpdate()
45+
}
3446
} catch (e) {
47+
logs.push({
48+
waktu: new Date().toLocaleTimeString(),
49+
pesan: 'NODE CHECK FAILED ' + e.message
50+
})
3551
originalLog('[SYSTEM] Gagal menjalankan updater:', e.message)
3652
}
3753

@@ -41,8 +57,6 @@ async function runUpdater() {
4157
originalLog('\n=== UPDATE LOG TABLE ===')
4258
console.table(logs)
4359
originalLog('=== END UPDATE LOG ===\n')
44-
} else {
45-
originalLog('\n=== TIDAK ADA UPDATE ===\n')
4660
}
4761
}
4862

@@ -130,6 +144,14 @@ function start(file) {
130144
}
131145
}
132146

147+
async function countdown(sec) {
148+
for (let i = sec; i >= 1; i--) {
149+
process.stdout.write(`\r⏳ Starting in ${i}... `)
150+
await new Promise(r => setTimeout(r, 1000))
151+
}
152+
console.log('\n')
153+
}
154+
133155
await runUpdater()
134-
await new Promise(resolve => setTimeout(resolve, 5000))
156+
await countdown(7)
135157
start('main.js')

0 commit comments

Comments
 (0)