Skip to content

Commit

Permalink
feat(merge): #53 & #54
Browse files Browse the repository at this point in the history
  • Loading branch information
verysillycat committed Jan 18, 2025
1 parent d0a3f93 commit d8fe37a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules
.env
.DS_Store
.idea/
.pnpm-store/
.pnpm-store/
.direnv
13 changes: 12 additions & 1 deletion src/main/mainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { isTruthy } from "shared/utils/guards";
import { once } from "shared/utils/once";
import type { SettingsStore } from "shared/utils/SettingsStore";

import { sleep } from "../shared/utils/sleep";
import { createAboutWindow } from "./about";
import { initArRPC } from "./arrpc";
import {
Expand Down Expand Up @@ -482,7 +483,17 @@ function createMainWindow() {
: "";

addSplashLog();
win.loadURL(`https://${subdomain}discord.com/app`);
const loadDiscord = async (iteration: number = 0) => {
try {
await win.loadURL(`https://${subdomain}discord.com/app`);
} catch (error) {
console.error((error as Error).message);
await sleep(2000 * iteration); // Slow down if connection fails multiple times
await loadDiscord(iteration++);
}
};

loadDiscord();

return win;
}
Expand Down
32 changes: 28 additions & 4 deletions src/renderer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,32 @@ export const isFirstRun = (() => {
return true;
})();

const { platform } = navigator;
export type NavigatorUAData = {
platform: string;
brands: Array<{ brand: string; version: string }>;
mobile: boolean;
};

export const isWindows = platform.startsWith("Win");
export const isMac = platform.startsWith("Mac");
export const isLinux = platform.startsWith("Linux");
export interface NavigatorExtended extends Navigator {
userAgentData?: NavigatorUAData;
}

const getPlatform = (): string => {
const navigatorExtended = navigator as NavigatorExtended;

if (navigatorExtended.userAgentData) {
return navigatorExtended.userAgentData.platform;
}

return navigator.userAgent; // Fallback for older browsers
};

const platform = getPlatform().toLowerCase();

export const isWindows = platform.includes("win");
export const isMac = platform.includes("mac");
export const isLinux = platform.includes("linux");

// console.log("Is Windows?", isWindows);
// console.log("Is Mac?", isMac);
// console.log("Is Linux?", isLinux);

0 comments on commit d8fe37a

Please sign in to comment.