diff --git a/forge.config.ts b/forge.config.ts index 290eae55d..de5bce546 100644 --- a/forge.config.ts +++ b/forge.config.ts @@ -62,7 +62,12 @@ const config: ForgeConfig = { appBundleId: "is.follow", icon: "resources/icon", extraResource: ["./resources/app-update.yml"], - + protocols: [ + { + name: "Follow", + schemes: ["follow"], + }, + ], afterCopy: [cleanSources], asar: true, ignore: [/^\/node_modules\/(?!font-list)/], @@ -117,6 +122,7 @@ const config: ForgeConfig = { new MakerAppImage({ options: { icon: "resources/icon.png", + mimeType: ["x-scheme-handler/follow"], }, }), ], diff --git a/package.json b/package.json index a783e1a3e..b458295bf 100644 --- a/package.json +++ b/package.json @@ -141,7 +141,7 @@ "@vercel/ncc": "0.38.1", "@vitejs/plugin-react": "^4.3.1", "drizzle-orm": "0.32.0", - "electron": "^30.1.2", + "electron": "^31.0.2", "electron-devtools-installer": "3.2.0", "electron-vite": "^2.3.0", "eslint": "^9.7.0", @@ -171,5 +171,6 @@ }, "lint-staged": { "*": "eslint --fix" - } + }, + "productName": "Follow" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 12dda5a80..6e2722021 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -21,13 +21,13 @@ importers: dependencies: '@egoist/tipc': specifier: 0.3.1 - version: 0.3.1(patch_hash=xlivt3m5hothgltzlhgcjx3uca)(electron@30.1.2)(react@18.3.1) + version: 0.3.1(patch_hash=xlivt3m5hothgltzlhgcjx3uca)(electron@31.2.1)(react@18.3.1) '@electron-toolkit/preload': specifier: ^3.0.1 - version: 3.0.1(electron@30.1.2) + version: 3.0.1(electron@31.2.1) '@electron-toolkit/utils': specifier: ^3.0.0 - version: 3.0.0(electron@30.1.2) + version: 3.0.0(electron@31.2.1) '@fontsource/sn-pro': specifier: 5.0.1 version: 5.0.1 @@ -348,8 +348,8 @@ importers: specifier: 0.32.0 version: 0.32.0(@opentelemetry/api@1.9.0)(@types/pg@8.6.1)(@types/react@18.3.3)(react@18.3.1) electron: - specifier: ^30.1.2 - version: 30.1.2 + specifier: ^31.0.2 + version: 31.2.1 electron-devtools-installer: specifier: 3.2.0 version: 3.2.0 @@ -3664,8 +3664,8 @@ packages: resolution: {integrity: sha512-oM8BW3a8NEqG0XW+Vx3xywhk0DyDV4T0jT0zZfWt0IczNT3jHAAvQWBorF8osQDplSsCyXXyxrsrQ8cY0Slb/A==} engines: {node: '>=8.0.0'} - electron@30.1.2: - resolution: {integrity: sha512-A5CFGwbA+HSXnzwjc8fP2GIezBcAb0uN/VbNGLOW8DHOYn07rvJ/1bAJECHUUzt5zbfohveG3hpMQiYpbktuDw==} + electron@31.2.1: + resolution: {integrity: sha512-g3CLKjl4yuXt6VWm/KpgEjYYhFiCl19RgUn8lOC8zV/56ZXAS3+mqV4wWzicE/7vSYXs6GRO7vkYRwrwhX3Gaw==} engines: {node: '>= 12.20.55'} hasBin: true @@ -7212,9 +7212,9 @@ snapshots: transitivePeerDependencies: - supports-color - '@egoist/tipc@0.3.1(patch_hash=xlivt3m5hothgltzlhgcjx3uca)(electron@30.1.2)(react@18.3.1)': + '@egoist/tipc@0.3.1(patch_hash=xlivt3m5hothgltzlhgcjx3uca)(electron@31.2.1)(react@18.3.1)': dependencies: - electron: 30.1.2 + electron: 31.2.1 optionalDependencies: '@tanstack/react-query': 5.51.4(react@18.3.1) transitivePeerDependencies: @@ -7439,17 +7439,17 @@ snapshots: dependencies: chrome-trace-event: 1.0.4 - '@electron-toolkit/preload@3.0.1(electron@30.1.2)': + '@electron-toolkit/preload@3.0.1(electron@31.2.1)': dependencies: - electron: 30.1.2 + electron: 31.2.1 '@electron-toolkit/tsconfig@1.0.1(@types/node@20.14.11)': dependencies: '@types/node': 20.14.11 - '@electron-toolkit/utils@3.0.0(electron@30.1.2)': + '@electron-toolkit/utils@3.0.0(electron@31.2.1)': dependencies: - electron: 30.1.2 + electron: 31.2.1 '@electron/asar@3.2.10': dependencies: @@ -10703,7 +10703,7 @@ snapshots: - supports-color optional: true - electron@30.1.2: + electron@31.2.1: dependencies: '@electron/get': 2.0.3 '@types/node': 20.14.11 diff --git a/resources/icon.ico b/resources/icon.ico new file mode 100644 index 000000000..4d1ecb48b Binary files /dev/null and b/resources/icon.ico differ diff --git a/src/main/index.ts b/src/main/index.ts index e7054616a..db46281e0 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,7 +1,5 @@ import "dotenv/config" -import path from "node:path" - import { electronApp, optimizer } from "@electron-toolkit/utils" import { APP_PROTOCOL, DEEPLINK_SCHEME } from "@shared/constants" import { extractElectronWindowOptions } from "@shared/electron" @@ -14,47 +12,99 @@ import { registerUpdater } from "./updater" import { createMainWindow, createWindow } from "./window" if (isDev) console.info("[main] env loaded:", env) -initializationApp() -let mainWindow: BrowserWindow -if (process.defaultApp) { - if (process.argv.length >= 2) { - app.setAsDefaultProtocolClient(APP_PROTOCOL, process.execPath, [ - path.resolve(process.argv[1]), - ]) +function bootsharp() { + const gotTheLock = app.requestSingleInstanceLock() + + if (!gotTheLock) { + app.quit() + + return } -} else { - app.setAsDefaultProtocolClient(APP_PROTOCOL) -} -// This method will be called when Electron has finished -// initialization and is ready to create browser windows. -// Some APIs can only be used after this event occurs. -app.whenReady().then(() => { - // Set app user model id for windows - electronApp.setAppUserModelId(`re.${APP_PROTOCOL}`) + let mainWindow: BrowserWindow - // Default open or close DevTools by F12 in development - // and ignore CommandOrControl + R in production. - // see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils - app.on("browser-window-created", (_, window) => { - optimizer.watchWindowShortcuts(window) + initializationApp() + + app.on("second-instance", (_, commandLine) => { + if (mainWindow) { + if (mainWindow.isMinimized()) mainWindow.restore() + mainWindow.focus() + } + + const url = commandLine.pop() + if (url) { + handleOpen(url) + } }) - mainWindow = createMainWindow() + // This method will be called when Electron has finished + // initialization and is ready to create browser windows. + // Some APIs can only be used after this event occurs. + app.whenReady().then(() => { + // Set app user model id for windows + electronApp.setAppUserModelId(`re.${APP_PROTOCOL}`) - app.on("activate", () => { - // On macOS it's common to re-create a window in the app when the - // dock icon is clicked and there are no other windows open. - if (BrowserWindow.getAllWindows().length === 0) { - mainWindow = createMainWindow() + mainWindow = createMainWindow() + + registerUpdater() + + app.on("activate", () => { + // On macOS it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + if (BrowserWindow.getAllWindows().length === 0) { + mainWindow = createMainWindow() + } + }) + + app.on("open-url", (_, url) => { + if (mainWindow && !mainWindow.isDestroyed()) { + if (mainWindow.isMinimized()) mainWindow.restore() + mainWindow.focus() + } else { + mainWindow = createMainWindow() + } + handleOpen(url) + }) + + // Default open or close DevTools by F12 in development + // and ignore CommandOrControl + R in production. + // see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils + app.on("browser-window-created", (_, window) => { + optimizer.watchWindowShortcuts(window) + }) + + // for dev debug + + if (process.env.NODE_ENV === "development") { + import("electron-devtools-installer").then( + ({ + default: installExtension, + REDUX_DEVTOOLS, + REACT_DEVELOPER_TOOLS, + }) => { + [REDUX_DEVTOOLS, REACT_DEVELOPER_TOOLS].forEach((extension) => { + installExtension(extension, { + loadExtensionOptions: { allowFileAccess: true }, + }) + .then((name) => console.info(`Added Extension: ${name}`)) + .catch((err) => console.info("An error occurred:", err)) + }) + + session.defaultSession.getAllExtensions().forEach((e) => { + session.defaultSession.loadExtension(e.path) + }) + }, + ) } }) const handleOpen = (url: string) => { const urlObj = new URL(url) - if (urlObj.hostname === "auth") { + + if (urlObj.hostname === "auth" || urlObj.pathname === "//auth") { const token = urlObj.searchParams.get("token") + const apiURL = process.env["VITE_API_URL"] || import.meta.env.VITE_API_URL if (token && apiURL) { @@ -80,58 +130,16 @@ app.whenReady().then(() => { resizable, }) } + + // Quit when all windows are closed, except on macOS. There, it's common + // for applications and their menu bar to stay active until the user quits + // explicitly with Cmd + Q. + app.on("window-all-closed", () => { + if (process.platform !== "darwin") { + app.quit() + } + }) } +} - app.on("second-instance", (_, commandLine) => { - if (mainWindow) { - if (mainWindow.isMinimized()) mainWindow.restore() - mainWindow.focus() - } - const url = commandLine.pop() - if (url) { - handleOpen(url) - } - }) - app.on("open-url", (_, url) => { - if (mainWindow) { - if (mainWindow.isMinimized()) mainWindow.restore() - mainWindow.focus() - } - handleOpen(url) - }) - - registerUpdater() - - // for dev debug - - if (process.env.NODE_ENV === "development") { - import("electron-devtools-installer").then( - ({ - default: installExtension, - REDUX_DEVTOOLS, - REACT_DEVELOPER_TOOLS, - }) => { - [REDUX_DEVTOOLS, REACT_DEVELOPER_TOOLS].forEach((extension) => { - installExtension(extension, { - loadExtensionOptions: { allowFileAccess: true }, - }) - .then((name) => console.info(`Added Extension: ${name}`)) - .catch((err) => console.info("An error occurred:", err)) - }) - - session.defaultSession.getAllExtensions().forEach((e) => { - session.defaultSession.loadExtension(e.path) - }) - }, - ) - } -}) - -// Quit when all windows are closed, except on macOS. There, it's common -// for applications and their menu bar to stay active until the user quits -// explicitly with Cmd + Q. -app.on("window-all-closed", () => { - if (process.platform !== "darwin") { - app.quit() - } -}) +bootsharp() diff --git a/src/main/init.ts b/src/main/init.ts index 866c865aa..ffd20b962 100644 --- a/src/main/init.ts +++ b/src/main/init.ts @@ -2,6 +2,7 @@ import path from "node:path" import { registerIpcMain } from "@egoist/tipc/main" import * as Sentry from "@sentry/electron/main" +import { APP_PROTOCOL } from "@shared/constants" import { app } from "electron" import { getIconPath } from "./helper" @@ -15,6 +16,15 @@ const appFolder = { const isDev = process.env.NODE_ENV === "development" export const initializationApp = () => { + if (process.defaultApp) { + if (process.argv.length >= 2) { + app.setAsDefaultProtocolClient(APP_PROTOCOL, process.execPath, [ + path.resolve(process.argv[1]), + ]) + } + } else { + app.setAsDefaultProtocolClient(APP_PROTOCOL) + } Sentry.init({ dsn: process.env.VITE_SENTRY_DSN, }) diff --git a/src/main/window.ts b/src/main/window.ts index 8fec85ef9..2f98e3ae7 100644 --- a/src/main/window.ts +++ b/src/main/window.ts @@ -31,7 +31,7 @@ export function createWindow( show: false, resizable: configs?.resizable ?? true, autoHideMenuBar: true, - ...(platform === "linux" ? { icon: getIconPath() } : {}), + ...(platform !== "darwin" ? { icon: getIconPath() } : {}), webPreferences: { preload: path.join(__dirname, "../preload/index.mjs"), sandbox: false, @@ -66,7 +66,7 @@ export function createWindow( process.env["ELECTRON_RENDERER_URL"] + (options?.extraPath || ""), ) } else { - window.loadFile(path.join(__dirname, "../renderer/index.html")) + window.loadFile(path.resolve(__dirname, "../renderer/index.html")) } const refererMatchs = [ diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index dd4d77a09..2b3810efb 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -5,10 +5,9 @@ import { Outlet } from "react-router-dom" import { env } from "../../env.js" import { useAppIsReady } from "./atoms/app" import { useUISettingKey } from "./atoms/settings/ui" -import { Logo } from "./components/icons/logo" -import { tipcClient } from "./lib/client" import { appLog } from "./lib/log" import { getOS } from "./lib/utils" +import { Titlebar } from "./modules/app/Titlebar.js" import { RootProviders } from "./providers/root-providers" import { handlers } from "./tipc" @@ -51,33 +50,7 @@ function App() { aria-hidden /> )} - {windowsElectron && ( -