Skip to content

Commit 35f7cac

Browse files
committed
todo
1 parent ba152b1 commit 35f7cac

22 files changed

+86
-0
lines changed
28.4 KB
Loading
11.2 KB
Loading
35 KB
Loading
23.1 KB
Loading
34.3 KB
Loading
34.3 KB
Loading
39.2 KB
Loading
33.4 KB
Loading
38.9 KB
Loading
38.9 KB
Loading
37.3 KB
Loading
33.8 KB
Loading
41.4 KB
Loading
41.4 KB
Loading
33.1 KB
Loading
33.1 KB
Loading
15.5 KB
Loading
16.4 KB
Loading
27.8 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from "react";
2+
import { Image } from "../../../src/index";
3+
import path from "path";
4+
import { AspectRatioMode } from "@nodegui/nodegui";
5+
6+
const assetUrl =
7+
"/Users/atulr/Project/personal/react-desktop/examples/weather-widget/assets/icons";
8+
9+
type WeatherIconProps = {
10+
icon: string;
11+
};
12+
export const WeatherIcon = React.memo<WeatherIconProps>(props => {
13+
const iconId = props.icon || "na";
14+
const imageUrl = `${path.resolve(assetUrl, `${iconId}.png`)}`;
15+
return (
16+
<Image src={imageUrl} aspectRatioMode={AspectRatioMode.KeepAspectRatio} />
17+
);
18+
});

examples/weather-widget/index.tsx

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { Renderer, Window } from "../../src/index";
2+
import React, { useEffect, useRef, useState, useCallback } from "react";
3+
import { QMainWindow, WidgetAttribute, WindowType } from "@nodegui/nodegui";
4+
import { getCurrentWeather } from "./services/weather";
5+
import { WeatherIcon } from "./components/WeatherIcon";
6+
7+
const windowAttribures = [
8+
WidgetAttribute.WA_TranslucentBackground
9+
// WidgetAttribute.WA_NoSystemBackground
10+
// WidgetAttribute.WA_TransparentForMouseEvents
11+
];
12+
const windowFlags: WindowType[] = [
13+
// WindowType.FramelessWindowHint
14+
];
15+
16+
const App = () => {
17+
const winRef = useRef<QMainWindow>(null);
18+
const [weather, setWeather] = useState({
19+
icon: "na"
20+
});
21+
useEffect(() => {
22+
if (winRef.current) {
23+
winRef.current.resize(800, 450);
24+
}
25+
getWeather();
26+
}, []);
27+
28+
const getWeather = useCallback(async () => {
29+
try {
30+
const data = await getCurrentWeather();
31+
const weatherData = data.weather[0];
32+
setWeather({ icon: "01d" });
33+
} catch (err) {
34+
console.log(err);
35+
}
36+
}, []);
37+
38+
return (
39+
<Window
40+
id="win"
41+
attributes={windowAttribures}
42+
windowFlags={windowFlags}
43+
ref={winRef}
44+
>
45+
<WeatherIcon icon={weather.icon} />
46+
</Window>
47+
);
48+
};
49+
50+
const styleSheet = `
51+
52+
`;
53+
54+
Renderer.render(<App />, {
55+
onRender: () => {
56+
console.log("Yo");
57+
},
58+
enableDevtools: true
59+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import axios from "axios";
2+
3+
export const getCurrentWeather = async () => {
4+
let apiKey = "15e768797b4bf44b49979df29e6da67a";
5+
let city = "Stockholm";
6+
let url = `http://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}`;
7+
const response = await axios({ url, method: "get" });
8+
return response.data;
9+
};

0 commit comments

Comments
 (0)