Skip to content

Commit 2c87cb9

Browse files
server.properties file sync
- This will make sure that the server.properties file is the same for all hosts. This will simply grab the gist information and then write it to the server.properties file - This will happen when the app is opened
1 parent 7d47784 commit 2c87cb9

6 files changed

Lines changed: 40 additions & 9 deletions

File tree

src/autoUpdater.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const quitUpdateButton_el = document.getElementById('quitUpdateButton');
44
const updateControlDiv_el = document.getElementById('updateControlDiv');
55

66
api.autoUpdaterCallback((status) => {
7-
console.log(status);
87
if (status === 'Update Available'){
98
updateOverlay_el.style.display = 'flex';
109
if (selectUserTypeOverlay_el.style.display !== 'none'){

src/checkGitExists.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ async function checkifGitExists(){
77
if (!checkGit){
88
gitOverlay_el.style.display = 'flex';
99
const installStatus = await api.installGit();
10-
console.log(installStatus);
1110
gitStatusText_el.textContent = 'Git Installation Complete. Thank you!'
1211
gitOKButton_el.style.display = 'block';
1312
}

src/gist.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ async function getGist(){
99
gist = await api.gistHandler({request: 'View', gistID: settings.gistID, accessToken: settings.accessToken});
1010
isServerOnline();
1111
await populateInfo(gist);
12+
await handleServerProperties();
13+
}
14+
15+
async function handleServerProperties(){
16+
await api.serverPropertiesHandler({gistLink: gist.serverPropertiesLink, directory: settings.directory, accessToken: settings.accessToken});
17+
1218
}
1319

1420
async function populateInfo(data){

src/index.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { app, BrowserWindow, ipcMain, dialog, globalShortcut, clipboard } = require('electron');
22
const { autoUpdater } = require('electron-updater');
3+
const { URL } = require('url');
34

45
const path = require('path');
56
const fs = require('fs-extra');
@@ -75,7 +76,37 @@ app.on('ready', () => {
7576
*/
7677
});
7778

78-
const { exec } = require('child_process');
79+
ipcMain.handle('server-properties-handler', async (req, data) => {
80+
if (!data || !data.gistLink || !data.directory || !data.accessToken) return;
81+
try {
82+
const gistUrl = new URL(data.gistLink);
83+
const gistId = gistUrl.pathname.split('/').pop();
84+
const gistResponse = await axios.get(`https://api.github.com/gists/${gistId}`, {
85+
headers: {
86+
Authorization: `Bearer ${data.accessToken}`,
87+
},
88+
});
89+
const files = gistResponse.data.files;
90+
if (!files || !files['server.properties']) {
91+
return { error: 'Gist does not contain server.properties file' };
92+
}
93+
const content = files['server.properties'].content;
94+
updateServerProperties(data.directory, content);
95+
} catch (error) {
96+
console.error('Error fetching Gist:', error.message);
97+
}
98+
});
99+
100+
function updateServerProperties(directory, content){
101+
const filePath = path.join(directory, 'server.properties');
102+
fs.writeFile(filePath, content, 'utf8', (err) => {
103+
if (err) {
104+
console.error('Error updating server.properties:', err.message);
105+
} else {
106+
console.log('server.properties updated successfully.');
107+
}
108+
});
109+
}
79110

80111
ipcMain.handle('install-git', async (event, args) => {
81112
return new Promise((resolve, reject) => {
@@ -97,7 +128,6 @@ ipcMain.handle('install-git', async (event, args) => {
97128
return;
98129
}
99130
} else {
100-
console.log('Git installed:', stdout.trim());
101131
resolve(stdout.trim());
102132
return;
103133
}
@@ -113,8 +143,6 @@ ipcMain.handle('check-git-exists', () => {
113143
resolve(false);
114144
return;
115145
}
116-
117-
console.log('Git version:', stdout.trim());
118146
resolve(true);
119147
});
120148
});

src/preload.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ contextBridge.exposeInMainWorld('api', {
88
selectDirectory: () => ipcRenderer.invoke('select-directory'),
99
onServerStatusUpdate: (callback) => {
1010
ipcRenderer.on('server-status', (_, status) => {
11-
console.log(status);
1211
callback(status);
1312
});
1413
},
@@ -32,4 +31,5 @@ contextBridge.exposeInMainWorld('api', {
3231
getZerotierIP: () => ipcRenderer.invoke('get-zerotier-ip'),
3332
checkGitExists: () => ipcRenderer.invoke('check-git-exists'),
3433
installGit: () => ipcRenderer.invoke('install-git'),
35-
});
34+
35+
serverPropertiesHandler: (data) => ipcRenderer.invoke('server-properties-handler', data),});

src/settings.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ specificUserDataButton_el.addEventListener('click', () => {
211211

212212
function toggleHostInputs(display){
213213
hideHostSettings = display === 'none' ? true : false;
214-
console.log(hideHostSettings);
215214
const hostInputs = [serverTitleInput_el, repoLinkInput_el, ipInput_el, selectedDirectoryText_el, selectDirectoryButton_el]
216215
hostInputs.forEach(element => {
217216
element.style.display = display;

0 commit comments

Comments
 (0)