Skip to content

Commit 5ea94e1

Browse files
some fix
1 parent de198ad commit 5ea94e1

3 files changed

Lines changed: 72 additions & 8 deletions

File tree

main.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ ipcMain.on('close-window', () => {
3030

3131
ipcMain.on('show-context-menu', (event) => {
3232
const menu = Menu.buildFromTemplate([
33+
{
34+
label: 'Open',
35+
click: () => {
36+
win.show();
37+
win.focus();
38+
}
39+
},
3340
{
3441
label: 'Settings',
3542
click: () => event.sender.send('toggle-settings')
@@ -90,6 +97,13 @@ function createWindow() {
9097
tray.setToolTip('GitHub Contributions');
9198

9299
const trayMenu = Menu.buildFromTemplate([
100+
{
101+
label: 'Open',
102+
click: () => {
103+
win.show();
104+
win.focus();
105+
}
106+
},
93107
{
94108
label: 'Settings',
95109
click: () => win.webContents.send('toggle-settings')

package.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "github-contributions",
3-
"version": "1.0.0",
3+
"version": "1.0.8",
44
"main": "main.js",
55
"scripts": {
66
"start": "electron . --no-sandbox",
7-
"build": "electron-builder",
7+
"build": "electron-builder --x64",
88
"build:deb": "electron-builder --linux deb",
99
"build:appimage": "electron-builder --linux AppImage",
1010
"release": "electron-builder --publish always",
@@ -27,10 +27,15 @@
2727
"electron": "^33.0.0",
2828
"electron-builder": "^26.0.0"
2929
},
30+
"dependencies": {},
3031
"icon": "icon.png",
3132
"build": {
3233
"appId": "com.github-contributions.app",
3334
"icon": "icon.png",
35+
"compression": "maximum",
36+
"extraResources": [],
37+
"extraFiles": [],
38+
"asar": true,
3439
"files": [
3540
"main.js",
3641
"renderer.js",
@@ -42,11 +47,15 @@
4247
"target": [
4348
{
4449
"target": "deb",
45-
"arch": ["x64"]
50+
"arch": [
51+
"x64"
52+
]
4653
},
4754
{
4855
"target": "AppImage",
49-
"arch": ["x64"]
56+
"arch": [
57+
"x64"
58+
]
5059
}
5160
],
5261
"category": "Utility",

renderer.js

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,28 @@ function applyTheme() {
6161
document.body.style.backgroundColor = settings.theme === 'Dark' ? 'rgba(43, 43, 43, 0)' : 'rgba(255, 255, 255, 0)';
6262
}
6363

64+
function checkOnlineStatus() {
65+
return navigator.onLine;
66+
}
67+
68+
function showMessage(message, type = 'info') {
69+
const graph = document.getElementById('graph');
70+
const yearLabel = document.getElementById('year-label');
71+
graph.innerHTML = '<div style="text-align: right; width: 400px ; color: #81ffe4ff;">GitHub contribution info!</div>';
72+
yearLabel.innerHTML = `<div style="text-align: center; color: ${type === 'error' ? '#ff6b6b' : '#666'};">${message}</div>`;
73+
}
74+
6475
function fetchContributions() {
65-
if (!settings.username) return;
76+
if (!settings.username) {
77+
showMessage('Please go to Settings and add your username and token', 'error');
78+
return;
79+
}
80+
81+
if (!checkOnlineStatus()) {
82+
showMessage('You are offline. Please check your internet connection', 'error');
83+
return;
84+
}
85+
6686
const query = `
6787
query($userName:String!) {
6888
user(login: $userName) {
@@ -86,7 +106,10 @@ function fetchContributions() {
86106
headers,
87107
body: JSON.stringify({ query, variables: { userName: settings.username } })
88108
})
89-
.then(res => res.json())
109+
.then(res => {
110+
if (!res.ok) throw new Error('Network response was not ok');
111+
return res.json();
112+
})
90113
.then(data => {
91114
console.log('API Response:', data);
92115
const calendar = data.data?.user?.contributionsCollection?.contributionCalendar;
@@ -95,10 +118,17 @@ function fetchContributions() {
95118
renderGraph(parseCalendar(calendar));
96119
} else {
97120
console.log('No calendar data');
98-
alert('No contribution data found. Check username and token.');
121+
showMessage('No contribution data found. Check username and token.', 'error');
99122
}
100123
})
101-
.catch(err => console.error('Fetch error:', err));
124+
.catch(err => {
125+
console.error('Fetch error:', err);
126+
if (!checkOnlineStatus()) {
127+
showMessage('You are offline. Please check your internet connection', 'error');
128+
} else {
129+
showMessage('Failed to fetch contributions. Please check your settings.', 'error');
130+
}
131+
});
102132
}
103133

104134
function parseCalendar(calendar) {
@@ -145,6 +175,17 @@ function getLevel(count) {
145175
return 4;
146176
}
147177

178+
// Listen for online/offline events
179+
window.addEventListener('online', () => {
180+
if (settings.username) {
181+
fetchContributions();
182+
}
183+
});
184+
185+
window.addEventListener('offline', () => {
186+
showMessage('You are offline. Please check your internet connection', 'error');
187+
});
188+
148189
// Load settings on start
149190
const saved = localStorage.getItem('settings');
150191
const panel = document.getElementById('settings-panel');

0 commit comments

Comments
 (0)