Skip to content

Commit

Permalink
Fix opening external links
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadwey committed Feb 3, 2024
1 parent deeb6b6 commit 8237976
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 16 deletions.
4 changes: 3 additions & 1 deletion electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ nsis:
installerSidebar: "build/installerSidebar.bmp"
linux:
target: [AppImage, tar.gz, deb, rpm]
artifactName: ${name}-${version}-${os}-${arch}.${ext}
maintainer: Nadwey
category: Utility
category: Game
executableName: "SE3 Launcher"
appImage:
artifactName: ${name}-${version}.${ext}
npmRebuild: false
5 changes: 5 additions & 0 deletions electron.vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@ export default defineConfig({
},
},
plugins: [react()],
build: {
rollupOptions: {
external: "@tabler/icons-react"
},
}
},
});
18 changes: 9 additions & 9 deletions package-lock.json

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

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"name": "se3-launcher",
"version": "3.0.2",
"description": "An Electron application with React",
"main": "./out/main/index.js",
"author": "example.com",
"homepage": "https://electron-vite.org",
"author": {
"name": "Nadwey",
"email": "[email protected]",
"url": "https://nadwey.pl"
},
"homepage": "https://se3.page",
"private": true,
"license": "MIT",
"scripts": {
"format": "prettier --write .",
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
Expand All @@ -22,7 +27,7 @@
"@mantine/core": "^7.5.1",
"@mantine/modals": "^7.5.1",
"@mantine/notifications": "^7.5.1",
"@tabler/icons-react": "^2.47.0",
"@tabler/icons-react": "3.0.0-alpha.0",
"axios": "^1.6.7",
"compressing": "^1.10.0",
"electron-store": "^8.1.0",
Expand Down
3 changes: 3 additions & 0 deletions src/common/IpcMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const IpcMessages = {

RUN_VERSION: "version-manager-run-version", // renderer -> main | (versionTag)
},
UTILS: {
OPEN_EXTERNAL: "utils-open-external", // renderer -> main | (url)
}
}

export default IpcMessages;
1 change: 1 addition & 0 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { app, BrowserWindow, ipcMain, dialog, nativeTheme } from "electron";
import path from "path";
require("electron-store").initRenderer(); // TODO: remove electron-store from the codebase
import { areInstallationsRunning } from "./renderer_bridge/versionManager";
import "./renderer_bridge/utils";
import { is } from "@electron-toolkit/utils";

const isDev = !app.isPackaged;
Expand Down
7 changes: 7 additions & 0 deletions src/main/renderer_bridge/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ipcMain, shell } from "electron";
import IpcMessages from "../../common/IpcMessages";

ipcMain.handle(IpcMessages.UTILS.OPEN_EXTERNAL, async(e, href) => {
if (!["https:", "http:"].includes(new URL(href).protocol)) return;
shell.openExternal(href);
});
5 changes: 3 additions & 2 deletions src/preload/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { contextBridge, ipcRenderer } from "electron";
import { contextBridge, ipcRenderer, shell } from "electron";
import "./versionManager";
import IpcMessages from "../common/IpcMessages";

window.addEventListener("DOMContentLoaded", () => {
// Open external links in browser
Expand All @@ -9,7 +10,7 @@ window.addEventListener("DOMContentLoaded", () => {
const absoluteUrl = new RegExp("^(?:[a-z]+:)?//", "i");
event.preventDefault();
if (!absoluteUrl.test(event.target.href)) return;
electron.shell.openExternal(event.target.href);
ipcRenderer.invoke(IpcMessages.UTILS.OPEN_EXTERNAL, event.target.href);
}
});
});
Expand Down

0 comments on commit 8237976

Please sign in to comment.