Skip to content

Commit

Permalink
Update server.properties
Browse files Browse the repository at this point in the history
- Added a new gist for server.properties
- Added the server.properties link to the server status gist
- This way each time the user clicks start or launches it will paste over the server.properties.
- Need to improve this so it only does this when it requires updating.
  • Loading branch information
programmingKyle committed Feb 27, 2024
1 parent 74cec97 commit 637582f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/gist.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@ const serverPortText_el = document.getElementById('serverPortText');

let gist;

let gitServerPropLink;
let hasUpdatedProperties = false;

async function getGist(){
gist = await api.gistHandler({request: 'View', gistID: settings.gistID, accessToken: settings.accessToken});
isServerOnline();
await populateInfo(gist);
await handleServerProperties();
if (!hasUpdatedProperties){
await handleServerProperties();
}
}

async function handleServerProperties(){
hasUpdatedProperties = true;
await api.serverPropertiesHandler({gistLink: gist.serverPropertiesLink, directory: settings.directory, accessToken: settings.accessToken});

}

async function populateInfo(data){
gitServerPropLink = data.serverPropertiesLink;
serverStatusText_el.textContent = data.status;
if (data.status === 'ONLINE'){
serverStatusText_el.classList.add('online');
Expand All @@ -40,7 +46,8 @@ async function updateGist(){
"status": gist.status === 'OFFLINE' ? 'ONLINE' : 'OFFLINE',
"servername": gist.status === 'OFFLINE' ? settings.serverName : null,
"ip": gist.status === 'OFFLINE' ? settings.ip : null,
"port": gist.status === 'OFFLINE' ? '19132' : null
"port": gist.status === 'OFFLINE' ? '19132' : null,
"serverPropertiesLink": gitServerPropLink
}
const updateSuccess = await api.gistHandler({request: 'Update', gistID: settings.gistID, accessToken: settings.accessToken, updatedContent});
if (updateSuccess){
Expand Down
2 changes: 0 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ function updateServerProperties(directory, content){
fs.writeFile(filePath, content, 'utf8', (err) => {
if (err) {
console.error('Error updating server.properties:', err.message);
} else {
console.log('server.properties updated successfully.');
}
});
}
Expand Down
1 change: 1 addition & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ confirmStopButton_el.addEventListener('click', async () => {
stopServerButton_el.style.display = 'none';
api.checkAndCloseTerminal();
await getGist();
hasUpdatedProperties = false;
if (gist.status === 'ONLINE'){
await api.serverHandler({request: 'Stop'});
}
Expand Down

0 comments on commit 637582f

Please sign in to comment.