Skip to content

Commit

Permalink
Merge pull request #433 from fperera123/fix/application-crashing
Browse files Browse the repository at this point in the history
Fix Crash
  • Loading branch information
CrazyMarvin authored Jan 12, 2025
2 parents 4891c27 + 8ed815c commit 41c421c
Show file tree
Hide file tree
Showing 13 changed files with 1,527 additions and 2,850 deletions.
1 change: 1 addition & 0 deletions flathub/rocks.poopjournal.librelinkupdesktop.metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
</keywords>

<releases>
<release version="0.1.12" date="2025-01-12"/>
<release version="0.1.11" date="2024-09-14"/>
<release version="0.1.10" date="2024-08-09"/>
<release version="0.1.9" date="2024-04-10"/>
Expand Down
4,168 changes: 1,408 additions & 2,760 deletions package-lock.json

Large diffs are not rendered by default.

67 changes: 34 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rocks.poopjournal.librelinkupdesktop",
"version": "0.1.11",
"version": "0.1.12",
"author": {
"name": "Yuran Fernando",
"email": "[email protected]"
Expand Down Expand Up @@ -70,89 +70,90 @@
}
},
"dependencies": {
"@diakem/libre-link-up-api-client": "^0.7.1",
"@diakem/libre-link-up-api-client": "^0.6.1",
"@hookform/resolvers": "^3.9.0",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-popover": "^1.1.1",
"@radix-ui/react-select": "^2.1.4",
"@radix-ui/react-separator": "^1.1.1",
"@radix-ui/react-select": "^2.1.1",
"@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0",
"axios": "^1.7.7",
"axios": "^1.7.3",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"electron-debug": "^4.1.0",
"electron-log": "^5.2.4",
"crypto-js": "^4.2.0",
"electron-debug": "^3.2.0",
"electron-log": "^5.1.7",
"electron-updater": "^6.3.2",
"framer-motion": "^11.3.31",
"framer-motion": "^11.3.21",
"i18next": "^23.12.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hook-form": "^7.53.0",
"react-i18next": "^15.4.0",
"react-router-dom": "^6.27.0",
"react-hook-form": "^7.52.2",
"react-i18next": "^15.0.0",
"react-router-dom": "^6.26.0",
"sonner": "^1.5.0",
"tailwind-merge": "^2.4.0",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.23.8",
"zustand": "^5.0.1"
"zustand": "^4.5.4"
},
"devDependencies": {
"@electron/notarize": "^2.4.0",
"@electron/packager": "^18.3.6",
"@electron/notarize": "^2.3.2",
"@electron/packager": "^18.3.3",
"@electron/rebuild": "^3.6.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
"@svgr/webpack": "^8.1.0",
"@teamsupercell/typings-for-css-modules-loader": "^2.5.2",
"@testing-library/jest-dom": "^6.4.8",
"@testing-library/react": "^16.1.0",
"@testing-library/react": "^16.0.0",
"@types/jest": "^29.5.12",
"@types/node": "22.1.0",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react-test-renderer": "^18.3.0",
"@types/terser-webpack-plugin": "^5.0.4",
"@types/webpack-bundle-analyzer": "^4.7.0",
"@typescript-eslint/eslint-plugin": "^8.0.1",
"@typescript-eslint/parser": "^8.8.0",
"@typescript-eslint/parser": "^8.0.1",
"autoprefixer": "^10.4.20",
"browserslist-config-erb": "^0.0.3",
"chalk": "^4.1.2",
"concurrently": "^9.0.1",
"concurrently": "^8.2.2",
"core-js": "^3.38.0",
"cross-env": "^7.0.3",
"css-loader": "^7.1.2",
"css-minimizer-webpack-plugin": "^7.0.0",
"detect-port": "^2.1.0",
"electron": "33.2.1",
"electron-builder": "^25.1.8",
"detect-port": "^1.6.1",
"electron": "^31.3.1",
"electron-builder": "^24.13.3",
"electron-devtools-installer": "^3.2.0",
"electronmon": "^2.0.3",
"eslint": "^9.8.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-erb": "^4.1.0",
"eslint-import-resolver-typescript": "^3.7.0",
"eslint-import-resolver-webpack": "^0.13.10",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-import-resolver-webpack": "^0.13.8",
"eslint-plugin-compat": "^6.0.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^28.8.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.7.0",
"eslint-plugin-jsx-a11y": "^6.9.0",
"eslint-plugin-promise": "^7.2.1",
"eslint-plugin-react": "^7.37.3",
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-promise": "^7.0.0",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react-hooks": "^4.6.2",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.6.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"mini-css-extract-plugin": "^2.9.2",
"npm-check-updates": "^17.1.13",
"mini-css-extract-plugin": "^2.9.0",
"npm-check-updates": "^17.0.3",
"postcss-loader": "^8.1.1",
"prettier": "^3.3.3",
"react-refresh": "^0.14.2",
"react-test-renderer": "^18.3.1",
"rimraf": "^6.0.1",
"sass": "^1.83.0",
"sass": "^1.77.8",
"sass-loader": "^16.0.0",
"style-loader": "^4.0.0",
"tailwindcss": "^3.4.7",
Expand All @@ -161,7 +162,7 @@
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"typescript": "^5.6.2",
"typescript": "^5.5.4",
"url-loader": "^4.1.1",
"webpack": "^5.93.0",
"webpack-bundle-analyzer": "^4.10.2",
Expand Down
4 changes: 2 additions & 2 deletions release/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "librelinkupdesktop",
"version": "0.1.11",
"version": "0.1.12",
"description": "This is a desktop application that fetches your blood sugar from LibreLinkUp",
"license": "Apache-2.0",
"author": "Crazy Marvin & Contributors (especially Yuran) <[email protected]> (https://crazymarvin.com/librelinkupdesktop/)",
Expand Down
2 changes: 1 addition & 1 deletion snap/gui/librelinkupdesktop.desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Desktop Entry]
Version=0.1.11
Version=0.1.12
Name=LibreLinkUpDesktop
Comment=This is a desktop application that fetches your blood sugar from LibreLinkUp
Exec=${SNAP}/librelinkupdesktop/librelinkupdesktop --no-sandbox
Expand Down
4 changes: 2 additions & 2 deletions snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: librelinkupdesktop
base: core22
version: '0.1.11'
version: '0.1.12'
summary: LibreLinkUpDesktop
description: |
This is a desktop application that fetches your blood sugar from LibreLinkUp.
Expand Down Expand Up @@ -58,7 +58,7 @@ parts:
npx cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.main.prod.ts
npx cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.renderer.prod.ts
npx electron-packager ./release/app librelinkupdesktop --overwrite --platform=linux --arch=x64 --out=release-build --prune=true --electron-version=31.3.1 --app-version=0.1.11
npx electron-packager ./release/app librelinkupdesktop --overwrite --platform=linux --arch=x64 --out=release-build --prune=true --electron-version=31.3.1 --app-version=0.1.12
cp -rv release-build/librelinkupdesktop-linux-x64 $SNAPCRAFT_PART_INSTALL/librelinkupdesktop
chmod -R 755 $SNAPCRAFT_PART_INSTALL/librelinkupdesktop
Expand Down
58 changes: 31 additions & 27 deletions src/renderer/lib/linkup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from "axios"
import axios from 'axios'
import { hash256 } from './utils'

const BASE_URL = 'https://api-COUNTRY_CODE.libreview.io/llu'

Expand All @@ -15,9 +16,12 @@ type LoginAttemptRequest = {
type GetGeneralRequest = {
token: string
country: string
accountId: string
}

export async function getAuthToken(request: LoginAttemptRequest): Promise<string|null> {
export async function getAuthToken(request: LoginAttemptRequest): Promise<{
token: string, accountId: string
}|null> {
try {
const response = await axios({
method: 'post',
Expand All @@ -28,16 +32,19 @@ export async function getAuthToken(request: LoginAttemptRequest): Promise<string
password: request.password,
},
headers: {
"product": "llu.android",
"version": "4.7",
"Pragma": "no-cache",
"Cache-Control": "no-cache",
"Accept-Encoding": "gzip",
"Connection": "keep-alive",
}
product: 'llu.android',
version: '4.12.0',
Pragma: 'no-cache',
'Cache-Control': 'no-cache',
'Accept-Encoding': 'gzip',
Connection: 'keep-alive',
},
})

return response.data?.data?.authTicket?.token
return {
token: response.data?.data?.authTicket?.token,
accountId: response.data?.data?.user?.id,
}
} catch (error) {
console.log("Unable to get the token: ", error)
}
Expand All @@ -49,13 +56,12 @@ export async function getCGMData(request: GetGeneralRequest): Promise<string|nul
try {
const baseURL = getBaseUrl(request.country)
const headers = {
"product": "llu.android",
"version": "4.7",
"Pragma": "no-cache",
"Cache-Control": "no-cache",
"Accept-Encoding": "gzip",
"Connection": "keep-alive",
"Authorization": `Bearer ${request.token}`,
product: 'llu.android',
version: '4.12.0',
Pragma: 'no-cache',
'Cache-Control': 'no-cache',
Authorization: `Bearer ${request.token}`,
'Account-Id': hash256(request.accountId),
}

const connResponse = await axios({
Expand Down Expand Up @@ -83,7 +89,7 @@ export async function getCGMData(request: GetGeneralRequest): Promise<string|nul

return graphResponse?.data?.data?.connection
} catch (error) {
console.log("Unable to get the token: ", error)
console.log('Unable to getCGMData: ', error)
}

return null
Expand All @@ -93,13 +99,12 @@ export async function getConnection(request: GetGeneralRequest): Promise<string|
try {
const baseURL = getBaseUrl(request.country)
const headers = {
"product": "llu.android",
"version": "4.7",
"Pragma": "no-cache",
"Cache-Control": "no-cache",
"Accept-Encoding": "gzip",
"Connection": "keep-alive",
"Authorization": `Bearer ${request.token}`,
product: 'llu.android',
version: '4.12.0',
Pragma: 'no-cache',
'Cache-Control': 'no-cache',
Authorization: `Bearer ${request.token}`,
'Account-Id': hash256(request.accountId),
}

const response = await axios({
Expand All @@ -111,9 +116,8 @@ export async function getConnection(request: GetGeneralRequest): Promise<string|

return response?.data?.data[0]
} catch (error) {
console.log("Unable to get the token: ", error)
console.log('Unable to getConnection: ', error)
}

return null
}

5 changes: 5 additions & 0 deletions src/renderer/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
import { useAuthStore } from '../stores/auth'
import CryptoJS from 'crypto-js';

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
Expand Down Expand Up @@ -74,3 +75,7 @@ export function getUserUnit(): string {

return resultUnit
}

export function hash256(input: string): string {
return CryptoJS.SHA256(input).toString(CryptoJS.enc.Hex);
}
28 changes: 17 additions & 11 deletions src/renderer/pages/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,28 @@ export default function DashboardPage() {
const navigate = useNavigate();
const token = useAuthStore((state) => state.token);
const country = useAuthStore((state) => state.country);
const accountId = useAuthStore((state) => state.accountId);
const [graphData, setGraphData] = useState({});
const [isReady, setIsReady] = useState(false);

const populateGraphData = async () => {
const data = await getCGMData({
token: token ?? '',
country: country ?? '',
});

if (data === null) {
clearSession();
return;
}
try {
const data = await getCGMData({
token: token ?? '',
country: country ?? '',
accountId: accountId ?? '',
});

if (data === null) {
clearSession();
return;
}

setGraphData(data);
setIsReady(true);
setGraphData(data);
setIsReady(true);
} catch (error) {
console.log('Unable to getCGMData: ', error);
}
};

const getColor = (
Expand Down
8 changes: 5 additions & 3 deletions src/renderer/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ export default function LoginPage() {
const login = useAuthStore((state) => state.login)

const onSubmit = async (values: z.infer<typeof formSchema>) => {
const authToken = await getAuthToken({
const authData = await getAuthToken({
country: values.country,
username: values.username,
password: values.password,
})

if (authToken) {
login(authToken, values.country, values.language)
if (authData) {
const token = authData?.token || ''
const accountId = authData?.accountId || ''
login(token, values.country, values.language, accountId)
navigate('/dashboard')
} else {
toast.error("Invalid credentials.")
Expand Down
Loading

0 comments on commit 41c421c

Please sign in to comment.