Skip to content

Commit 3a7047a

Browse files
committed
Fixed bug where the screen wouldn't update when a button is pressed
1 parent 2d16472 commit 3a7047a

File tree

9 files changed

+136
-2
lines changed

9 files changed

+136
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ CXXFLAGS := $(CFLAGS) -std=c++17 -O2 -Wno-volatile
7272
ASFLAGS := -g $(ARCH)
7373
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
7474

75-
LIBS := -lnx
75+
LIBS := -lnx -lcurl
7676

7777
#---------------------------------------------------------------------------------
7878
# list of directories containing libraries, this must be the top level containing

include/constants.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#define CALCULATOR_NX_PATH "/switch/Calculator_NX"
4+
5+
#define CONFIG_PATH "/config/Calculator_NX"
6+
#define DOWNLOAD_PATH "/config/Calculator_NX/download"
7+
8+
#define TAGS_API_LINK "https://api.github.com/repos/EmreTech/Calculator_NX/tags"
9+
#define LATEST_RELEASE_API_LINK "https://api.github.com/repos/EmreTech/Calculator_NX/releases/latest"
10+
11+
#define BASE_DOWNLOAD_URL "https://github.com/EmreTech/Calculator_NX/releases/download/{}/Calculator_NX.nro"

include/download.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include <curl/curl.h>
4+
5+
#include <iostream>
6+
#include <fstream>
7+
#include <string>
8+
#include <cstdio>
9+
10+
#define API_AGENT "EmreTech"
11+
12+
CURLcode downloadFile(const std::string &url, const std::string &filename);
13+
14+
std::string getLatestTag(bool nightly);
15+
std::string getLatestDownload(bool nightly);

resources/i18n/en-US/text.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"title": "Calculator_NX Rewrite",
3+
"update_title": "Calculator_NX Updater",
34

45
"tabs": {
56
"calculator": "Calculator",
@@ -14,5 +15,11 @@
1415
"about": {
1516
"appname": "Calculator_NX",
1617
"developer": "Developed by EmreTech"
18+
},
19+
20+
"updater": {
21+
"starting_update": "Starting update...",
22+
"downloading_update": "Downloading the latest version...",
23+
"restarting_to_finish": "About to restart to finish the update."
1724
}
1825
}

resources/xml/activity/updater.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<brls:AppletFrame
2+
title="@i18n/text/update_title"
3+
icon="@res/icon/Calculator_NX_Icon_Alt.jpg">
4+
5+
<UpdaterTab />
6+
7+
</brls:AppletFrame>

resources/xml/tabs/updater.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<brls:Box
2+
width="auto"
3+
height="auto"
4+
alignItems="center"
5+
justifyContent="center">
6+
7+
<brls:Label
8+
width="auto"
9+
height="auto"
10+
horizontalAlign="center"
11+
fontSize="35"
12+
text="@i18n/text/updater/starting_update"/>
13+
14+
</brls:Box>

source/calculatorTab.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,5 @@ void CalculatorTab::updateScreenBufferFromExpStr()
9292
screenBuffer = expressionStr;
9393
if (expressionStr.length() >= 30)
9494
screenBuffer = expressionStr.substr(29);
95+
updateScreen();
9596
}

source/download.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include <download.hpp>
2+
3+
#include <nlohmann/json.hpp>
4+
#include <fmt/core.h>
5+
6+
#include <constants.hpp>
7+
8+
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
9+
{
10+
size_t written = fwrite(ptr, size, nmemb, stream);
11+
return written;
12+
}
13+
CURLcode downloadFile(const std::string &url, const std::string &filename)
14+
{
15+
CURL *curl;
16+
FILE *fp;
17+
CURLcode res;
18+
19+
curl = curl_easy_init();
20+
if (curl)
21+
{
22+
fp = fopen(filename.c_str(), "wb");
23+
24+
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
25+
26+
curl_easy_setopt(curl, CURLOPT_USERAGENT, API_AGENT);
27+
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
28+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
29+
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
30+
31+
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
32+
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
33+
34+
res = curl_easy_perform(curl);
35+
curl_easy_cleanup(curl);
36+
37+
fclose(fp);
38+
}
39+
40+
return res;
41+
}
42+
43+
std::string getLatestTag(bool nightly)
44+
{
45+
downloadFile(
46+
(nightly ? TAGS_API_LINK : LATEST_RELEASE_API_LINK), DOWNLOAD_PATH + std::string("/github_api.json")
47+
);
48+
49+
nlohmann::json api_data;
50+
std::ifstream api_file(DOWNLOAD_PATH + std::string("/github_api.json"));
51+
52+
api_file >> api_data;
53+
api_file.close();
54+
55+
if (nightly)
56+
return api_data[0]["name"].get<std::string>();
57+
58+
return api_data["tag_name"];
59+
}
60+
61+
std::string getLatestDownload(bool nightly)
62+
{
63+
if (nightly)
64+
{
65+
std::string latestTag = getLatestTag(nightly);
66+
return fmt::format(BASE_DOWNLOAD_URL, latestTag);
67+
}
68+
69+
downloadFile(
70+
LATEST_RELEASE_API_LINK, DOWNLOAD_PATH + std::string("/github_api_two.json")
71+
);
72+
73+
nlohmann::json api_data;
74+
std::ifstream api_file(DOWNLOAD_PATH + std::string("/github_api_two.json"));
75+
76+
api_file >> api_data;
77+
api_file.close();
78+
79+
return api_data["assets"][12/*"browser_download_url"*/];
80+
}

source/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <borealis.hpp>
2-
#include <nlohmann/json.hpp>
32

43
#include <calculatorTab.hpp>
54
#include <aboutTab.hpp>

0 commit comments

Comments
 (0)