Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Support for Gluroo #105

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
tabWidth: 2
semi: true
{
"tabWidth": 2,
"semi": true,
"endOfLine": "crlf"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "glucose-ticker",
"productName": "Glucose Ticker",
"version": "1.1.0",
"version": "1.2.0-beta.2",
"description": "Live blood sugar on the Windows Taskbar",
"main": "tmp/dist/index.js",
"scripts": {
Expand Down
11 changes: 11 additions & 0 deletions src/electron-app/components/nightscout-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@ import { API_PATH, Unit, MGDL_TO_MMOLL } from "../../shared/constants";

export default class NightscoutAPI {
private url: URL;
private apiSecret?: string;
constructor(
_url: string,
private unit: Unit,
) {
this.url = new URL(_url);
// If url has a username, we're using api-secret auth
if (this.url.username) {
const decoded = decodeURIComponent(this.url.username);
const hash = require("crypto").createHash("sha1");
const authSecret = hash.update(decoded).digest("hex");
this.apiSecret = authSecret;
this.url.username = "";
}
this.url.pathname = API_PATH;
}

Expand All @@ -20,6 +29,8 @@ export default class NightscoutAPI {
httpsAgent: new https.Agent({
rejectUnauthorized: false,
}),
// If we have an api secret, use it as a header
headers: this.apiSecret ? { "api-secret": this.apiSecret } : {},
});
} catch (error) {
console.error("Error fetching current glucose", error);
Expand Down
2 changes: 1 addition & 1 deletion src/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export enum IPC {
}

export const STORAGE_KEY = "app-settings";
export const API_PATH = "/api/v1/entries/current.json";
export const API_PATH = "/api/v1/entries.json";
//export const ICON_SIZE = 128;
//export const ICON_TEXT_MARGIN = 10;
export const MGDL_TO_MMOLL = 18;
Expand Down
15 changes: 13 additions & 2 deletions src/web-app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const App = () => {
});
};

const isGluroo = settings?.nsUrl?.includes("ns.gluroo.com");

// Renders the Splash component at first,
// then redirects to Nightscout after countdown hits 0.
const renderCountdown = () => (
Expand All @@ -70,14 +72,23 @@ const App = () => {
if (!props.completed) {
return (
<Splash
isGluroo={isGluroo}
s={props.seconds}
ms={props.milliseconds}
total={props.total}
></Splash>
);
} else {
window.location.href = settings.nsUrl;
return <p>Getting Nightscout ...</p>;
// Remove username (api secret) from URL before redirecting
let href = settings.nsUrl;
if (isGluroo) href = "https://app.gluroo.com";
else if (href.includes("@")) {
const url = new URL(href);
url.username = "";
href = url.toString();
}
window.location.href = href;
return <p>Getting {isGluroo ? "Gluroo" : "Nightscout"} ...</p>;
}
}}
></Countdown>
Expand Down
4 changes: 3 additions & 1 deletion src/web-app/components/Splash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ export default (props: any) => {
});

const [latestVersion, setLatestVersion] = React.useState(version);
const targetApp = props.isGluroo ? "Gluroo" : "Nightscout";
const timeLeft = getTimeLeft(props);

return (
<div>
<h2>Nightscout will be here in {getTimeLeft(props)}</h2>
<h2>{`${targetApp} will be here in ${timeLeft}`}</h2>
<hr />
<p>Need to change your settings? Click the button below:</p>
<button onClick={resetSettings}>Open settings</button>
Expand Down