Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit 100caff

Browse files
committed
rewrote ajax request, added view option for existing addons
1 parent 04df256 commit 100caff

File tree

4 files changed

+115
-48
lines changed

4 files changed

+115
-48
lines changed

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ <h3>What would you like to do?</h3>
4242
<div class="top">
4343
<button id="back_button_existing_addon" class="back_button" data-backwards="#addon_management_prompt" data-forwards="#update_existing_addon" data-resize="500, 175">◀ Back</button>
4444
<h3>Your addons</h3>
45+
<p id="refresh_addons"><a href="#">Refresh</a></p>
4546
</div>
4647
<div id="yourAddons"></div>
4748
</div>

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function createWindow() {
3030
backgroundColor: "#262626",
3131
titleBarStyle: "hidden",
3232
frame: false,
33-
icon: "src/img/icon.png",
33+
icon: "src/img/icon.ico",
3434
webPreferences: {
3535
nodeIntegration: true
3636
}
@@ -96,8 +96,10 @@ function sendClientAddonInfo() {
9696
fixedArray[i] = fixedArray[i].replace('/r', '');
9797
ADDON_IDS.push([fixedArray[i].substr(0, 11).replace(/\s/g, '').toString()])
9898
}
99+
100+
console.log(ADDON_IDS)
99101
console.log('Sent to client!')
100-
mainWindow.webContents.send('message', ADDON_IDS);
102+
mainWindow.webContents.send('addonInfo', ADDON_IDS);
101103
});
102104
}
103105

src/css/style.css

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,49 @@ header {
176176
padding: 15px 10px;
177177
}
178178

179-
#update_existing_addon .top h3, #create_new_addon .top h3 {
179+
#create_new_addon .top h3 {
180180
display: inline-block;
181181
margin: 0;
182182
font-weight: 300;
183183
transform: translateY(2px)
184-
}y
184+
}
185185

186186
#update_existing_addon .top button, #create_new_addon .top button {
187187
display: inline-block;
188188
background-color: rgb(219, 68, 68);
189189
margin-right: 5px;
190190
}
191191

192+
#update_existing_addon .top {
193+
background-color: #0f0f0f;
194+
padding: 5px 10px;
195+
display: flex;
196+
align-items: center;
197+
}
198+
199+
#update_existing_addon .top h3 {
200+
/* display: inline-block; */
201+
flex: 1;
202+
margin: 0;
203+
text-align: left;
204+
font-weight: 300;
205+
}
206+
207+
#update_existing_addon .top button {
208+
/* display: inline-block; */
209+
background-color: rgb(219, 68, 68);
210+
margin-right: 5px;
211+
}
212+
213+
#refresh_addons {
214+
margin-left: auto;
215+
padding-right: 15px;
216+
}
217+
218+
#refresh_addons a {
219+
color: white;
220+
}
221+
192222
#yourAddons {
193223
overflow-y: scroll;
194224
height: 65%;
@@ -219,7 +249,6 @@ header {
219249
font-weight: 500;
220250
background-color: #161616;
221251
padding: 10px 0;
222-
cursor: pointer;
223252
transition: ease 0.5s all;
224253
}
225254

@@ -232,11 +261,14 @@ header {
232261
margin: 0
233262
}
234263

235-
.addon_existing a {
236-
color: white;
264+
.addon_link {
237265
display: none;
238266
}
239267

268+
.addon_link a {
269+
color: white;
270+
}
271+
240272
.removeBackOption {
241273
width: 100px;
242274
}

src/js/script.js

Lines changed: 73 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const shell = require("electron").shell;
99
let win = remote.getCurrentWindow();
1010

1111
addon_data = [];
12+
api_data = {
13+
"itemcount": "0",
14+
};
1215
okToProcessAddonList = false;
1316
donePopulatingAddonList = false;
1417
currentNewAddon = "";
@@ -38,37 +41,45 @@ $(document).on("click", "a[href^='http']", function(event) {
3841

3942
$(document).ready(() => {
4043
// Try and recieve data from gmpublish about user's addons
41-
ipcRenderer.on("message", (event, message) => {
42-
var arrayOfAddonIds = message;
43-
for (let index = 0; index < arrayOfAddonIds.length; index++) {
44-
$.ajax({
45-
type: 'POST',
46-
url: 'https://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v1/',
47-
data: {
48-
'itemcount': 1,
49-
'publishedfileids[0]': parseInt(arrayOfAddonIds[index])
50-
},
51-
success: function success(data) {
52-
var addon = data.response.publishedfiledetails["0"];
53-
if (addon.result == 1) {
54-
for (let i = 0; i < Object.keys(data).length; i++) {
55-
var addonObject = {
56-
"title": addon.title,
57-
"id": addon.publishedfileid
58-
}
59-
addon_data.push(addonObject);
44+
ipcRenderer.on("addonInfo", (event, message) => {
45+
getAddonInfoFromSteam(message)
46+
});
47+
48+
function getAddonInfoFromSteam(message) {
49+
arrayOfAddonIds = message;
50+
51+
api_data['itemcount'] = arrayOfAddonIds.length;
52+
53+
54+
for (let i = 0; i < arrayOfAddonIds.length; i++) {
55+
// const element = arrayOfAddonIds[i];
56+
api_data["publishedfileids[" + i + "]"] = parseInt(arrayOfAddonIds[i]);
57+
}
58+
$.ajax({
59+
type: 'POST',
60+
url: 'https://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v1/',
61+
data: api_data,
62+
dataType: 'json',
63+
}).done((data) => {
64+
var response = data.response;
65+
if (response.result == 1) {
66+
for (let i = 0; i < response.resultcount; i++) {
67+
if (response.publishedfiledetails[i].result == 1) {
68+
var addon = response.publishedfiledetails[i];
69+
var addonObject = {
70+
"title": addon.title,
71+
"id": addon.publishedfileid
6072
}
73+
addon_data.push(addonObject);
6174
}
62-
},
63-
error: function (err) {
64-
console.log(err)
65-
},
66-
dataType: 'json',
67-
});
68-
}
69-
okToProcessAddonList = true;
70-
$('#update_existing_addon_button').text('Update existing addon');
71-
});
75+
}
76+
}
77+
// console.log(data.response);
78+
var addon = data.response.publishedfiledetails["0"];
79+
okToProcessAddonList = true;
80+
$('#update_existing_addon_button').text('Update existing addon');
81+
});
82+
}
7283

7384
// If user has already defined their Garrysmod directory, just skip ahead to #addon_management
7485
if (settings.get('gmodDirectory') != null) {
@@ -214,33 +225,51 @@ $(document).ready(() => {
214225
})
215226
}
216227

228+
// Check if user needs to refresh their addons
229+
// TODO: Hopefully I can remove this later on as it really isn't needed (except in the case of Steam being down)
230+
$('#refresh_addons').click(() => {
231+
console.log("Attempting to refresh addons...");
232+
$('#yourAddons').children().remove();
233+
getAddonInfoFromSteam();
234+
populateAddonList();
235+
236+
});
237+
217238
// Get array of addon infomation and append their names to #yourAddons
218239
function populateAddonList() {
219240
// This check is done to make sure this only gets executed once
220241
if (!donePopulatingAddonList) {
221242
for (let i = 0; i < addon_data.length; i++) {
222-
$('#yourAddons').append("<div class='addon_existing'><p>" + addon_data[i].title + "</p><a href='steam://url/CommunityFilePage/" + addon_data[i].id + "'>View on Steam</a></div>");
243+
$('#yourAddons').append("<div class='addon_existing'><p>" + addon_data[i].title + "</p><p class='addon_link'><a href='steam://url/CommunityFilePage/" + addon_data[i].id + "'>View</a> <a href='#'>Update</a></p></div>");
223244
donePopulatingAddonList = true;
245+
224246
}
225247
// Make sure if nothing is returned to let the user know
226248
// TODO: Allow for multiple error codes such as 429 (too many requests)
227249
// if (apiError == 400) {
228250
// $('#yourAddons').append("<p style='background-color: #0f0f0f; padding: 15px 10px; margin: 10px 15px; border-radius: 5px;'><b>Steam Web API Error!</b><br/><br/>Error 400. Maybe</p>");
229251
// donePopulatingAddonList = true;
230252
// }
253+
254+
console.log(addon_data, arrayOfAddonIds)
255+
256+
$('.addon_existing').hover((event) => {
257+
var target = $(event.target);
258+
var targetLink = $(target).find('.addon_link');
259+
$(targetLink).css('opacity', 0).slideDown('fast').animate({ opacity: 1 }, { queue: false, duration: 'slow' });
260+
}, (event) => {
261+
var target = $(event.target);
262+
var targetLink = $(target).find('.addon_link');
263+
$(targetLink).slideUp('fast').animate({ opacity: 0 }, { queue: false, duration: 'slow' });
264+
});
265+
231266
if (0 == addon_data.length) {
232267
$('#yourAddons').append("<p style='background-color: #0f0f0f; padding: 15px 10px; margin: 10px 15px; border-radius: 5px;'><b>No addons found!</b><br/><br/>Either you don't have Steam open or haven't uploaded anything.</p>");
233268
donePopulatingAddonList = true;
234269
}
235270
}
236271
}
237272

238-
// $('.addon_existing').hover((event) => {
239-
// console.log('hello')
240-
// var target = $(event.target);
241-
// $(this).find('a:last').fadeIn();
242-
// })
243-
244273
$('.typeCheckbox').on('click', (event) => {
245274
var target = $(event.target);
246275
if (jsonCheckboxCount < 2 && target.is(":checked")) {
@@ -314,7 +343,10 @@ $(document).ready(() => {
314343
}
315344

316345
$("#resetAddonCreation").click(() => {
346+
resetAddonCreation();
347+
});
317348

349+
function resetAddonCreation() {
318350
jsonCheckboxCount = 0;
319351

320352
// Clear the old data we used to make addon.json
@@ -347,7 +379,7 @@ $(document).ready(() => {
347379

348380
// Hide any div that may still be displayed
349381
$('#addonjsonPrompt, #jsonCreator, #gmaPrep, #createGMA').css('display', 'none');
350-
});
382+
}
351383

352384
$("#createGMAFile").click(() => {
353385
$('#gmaPrep').fadeOut(() => {
@@ -370,15 +402,15 @@ $(document).ready(() => {
370402
win.setBounds({height: 200})
371403
$('#new_addon_link').attr('href', 'steam://url/CommunityFilePage/' + newAddonID)
372404
$('#new_addon').fadeIn()
373-
})
374-
})
405+
});
406+
});
375407

376408
ipcRenderer.on('addonGMALocation', (event, addonGMA) => {
377409
addonGMADir = addonGMA;
378410
$('#createGMA').fadeOut(() => {
379411
win.setBounds({height: 200})
380412
$("#uploadToWorkshopPrompt").fadeIn();
381-
})
382-
})
413+
});
414+
});
383415

384416
});

0 commit comments

Comments
 (0)