This repository has been archived by the owner on Mar 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
108 lines (96 loc) · 3.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// 모듈 불러오기
const { app, BrowserWindow, ipcMain, dialog } = require('electron')
let request = require('request')
var cheerio = require('cheerio');
const { autoUpdater } = require("electron-updater");
const log = require('electron-log');
var fs = require('fs')
function createWindow() {
const win = new BrowserWindow({
width: 300,
height: 450,
frame: false,
resizable: false,
autoHideMenuBar: true,
transparent: true,
icon: __dirname + '/asset/icon/icon.icns',
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
devTools: false,
}
})
win.loadFile('index.html');
ipcMain.on('getLocale', (event, data) => {
var language = app.getLocaleCountryCode() === 'KR'? 'ko' : 'en';
console.log(language)
fs.readFile('./asset/language/' + language + '.json', (err, data) => {
const jsonData = data ? JSON.parse(data) : '';
event.reply('getLocaleReply', { locale: app.getLocaleCountryCode(), json: jsonData })
})
});
autoUpdater.on('checking-for-update', () => {
log.info('업데이트 확인 중...');
});
autoUpdater.on('update-available', () => {
dialog
.showMessageBox({
type: 'info',
title: 'Update available',
message:
'A new version of Project is available. Do you want to update now?',
buttons: ['Update', 'Later'],
})
.then((result) => {
const buttonIndex = result.response;
if (buttonIndex === 0) autoUpdater.downloadUpdate();
});
});
autoUpdater.on('update-not-available', (info) => {
log.info('현재 최신버전입니다.');
});
autoUpdater.on('error', (err) => {
log.info('에러가 발생하였습니다. 에러내용 : ' + err);
});
autoUpdater.on('download-progress', (progressObj) => {
let log_message = "다운로드 속도: " + progressObj.bytesPerSecond;
log_message = log_message + ' - 현재 ' + progressObj.percent + '%';
log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')';
log.info(log_message);
})
autoUpdater.on('update-downloaded', (info) => {
log.info('업데이트가 완료되었습니다.');
});
ipcMain.on('minimizeApp', () => {
win.minimize();
})
ipcMain.on('closeApp', () => {
win.close();
})
}
ipcMain.on('init', (event, data) => {
request({ url: 'https://github.com/' + data }, function (err, response, body) {
event.reply('reply', body)
});
});
ipcMain.on('appVersion', (event, data) => {
event.reply('reply', app.getVersion())
});
ipcMain.on('checkGithubAcc', (event, data) => {
request({
url: 'https://api.github.com/users/' + data,
headers: {
'User-Agent': 'MY IPHINE 7s'
}
}, function (err, response, body) {
response.statusCode === 404 ? event.reply('reply', '404') : JSON.parse(body).type === 'User' ? event.reply('reply', JSON.parse(body)) : event.reply('reply', 'Organization')
});
});
app.whenReady().then(() => {
createWindow();
autoUpdater.checkForUpdates();
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})