Skip to content

Commit

Permalink
feat: add screens folder
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbericoD committed Jan 5, 2024
1 parent 387db35 commit e9ae3ae
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 23 deletions.
26 changes: 11 additions & 15 deletions template/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { useEffect, useState, Suspense } from "react";
import { CurrentPage } from "./CurrentPage";
import { Loading } from "components/Loading";
import { WINDOW_NAMES } from "./constants";
import { getCurrentWindow } from "lib";
import { getCurrentWindow } from "lib/overwolf-essentials";
import { log } from "lib/log";
import "./App.css";

//This is the main component of the app, it is the root of the app
Expand All @@ -12,20 +13,15 @@ export const App = () => {
const [page, setPage] = useState<string>("");

useEffect(() => {
async function preLoad() {
if (process.env.NODE_ENV === "development") {
//you can set the current window to dev if you want to see the dev page <Normal Browser>
setPage(WINDOW_NAMES.DESKTOP);
} else {
const currentWindow = await getCurrentWindow();
setPage(currentWindow);
console.info(
"[🐺 overwolf-modern-react-boilerplate][🧰 src/app/App.tsx][🔧 useEffect - preLoad]",
JSON.stringify({ currentWindow }, null, 2)
);
}
}
preLoad();
(async function preLoad() {
const currentWindow = await getCurrentWindow();
setPage(currentWindow);
log(
JSON.stringify({ currentWindow }, null, 2),
"src/app/App.tsx",
"useEffect - preLoad"
);
})();
}, []);
//this is fallback for the loading current screen
return (
Expand Down
Empty file.
9 changes: 7 additions & 2 deletions template/src/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { log } from "./log";
import { isDev } from "./utils";

const enum ThirdPartyProvider {
Google = "google",
Spotify = "spotify",
Twitch = "twitch",
Custom = "custom",
//...
}

function createUrl(provider: ThirdPartyProvider): string {
Expand All @@ -16,8 +21,8 @@ function createUrl(provider: ThirdPartyProvider): string {

function loginWithThirdParty(provider: ThirdPartyProvider) {
const url = createUrl(provider);
if (process.env.NODE_ENV === "development") {
console.log(`Redirecting to ${url}`);
if (isDev) {
log(`Redirecting to ${url}`, "src/lib/auth.ts", "loginWithThirdParty");
window.open(url, "_blank");
}
overwolf.utils.openUrlInDefaultBrowser(url);
Expand Down
3 changes: 0 additions & 3 deletions template/src/lib/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions template/src/lib/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ const getFileSize = (data: string): string => {
* @param data The data to write to the file.
* @returns A promise that resolves to a message indicating the status of the write operation.
*/
const overwolfWriteFileContents = <T>(path: string, data: T): Promise<string> =>
new Promise((resolve) => {
const overwolfWriteFileContents = <T>(path: string, data: T) =>
new Promise<string>((resolve) => {
overwolf.io.writeFileContents(
path,
JSON.stringify(data),
Expand Down
8 changes: 8 additions & 0 deletions template/src/lib/log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const log = (message: string, component: string, method: string) => {
console.info(
`%c[🐺 overwolf-modern-react-boilerplate][🧰 ${component}][🔧 ${method}][📃 ${message} ]`,
"background: #222; color: #bada55; padding: 2px 0; border-radius: 2px; font-weight: bold;"
);
};

export { log };
24 changes: 23 additions & 1 deletion template/src/lib/overwolf-essentials.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { WINDOW_NAMES } from "app/constants";
import { isDev } from "./utils";

async function obtainDeclaredWindow(
windowName: string
): Promise<overwolf.windows.WindowInfo> {
Expand All @@ -11,6 +14,25 @@ async function obtainDeclaredWindow(
});
});
}

async function getCurrentWindow() {
if (isDev) {
console.log(
`Running in dev mode, returning ${WINDOW_NAMES.DESKTOP} window, you can change this in src/lib/overwolf-essentials.ts: getCurrent`
);
Promise.resolve(WINDOW_NAMES.DESKTOP);
}
return new Promise<string>((resolve, reject) => {
overwolf.windows.getCurrentWindow((result) => {
if (result.success) {
resolve(result.window);
} else {
reject(result.error);
}
});
});
}

function getMonitorsList(): Promise<overwolf.utils.Display[]> {
return new Promise<overwolf.utils.Display[]>((resolve) => {
overwolf.utils.getMonitorsList((result) => {
Expand All @@ -19,4 +41,4 @@ function getMonitorsList(): Promise<overwolf.utils.Display[]> {
});
}

export { obtainDeclaredWindow, getMonitorsList };
export { obtainDeclaredWindow, getMonitorsList, getCurrentWindow };
3 changes: 3 additions & 0 deletions template/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ const parseSafeJSON = <T>(data: string = ""): T | null => {
}
};

const isDev = process.env.NODE_ENV === "development";

export {
classNames,
formatDate,
Expand All @@ -102,4 +104,5 @@ export {
normalizeName,
parseSafeJSON,
sleep,
isDev,
};
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit e9ae3ae

Please sign in to comment.