Core Features
- Services @@ -21,8 +22,19 @@
Plugins
+Desktop
+ Download Link +Mobile
+ Download Link +Community Plugins
-
Bluetooth
@@ -37,14 +49,11 @@
Plugins
diff --git a/docs/getting-started.md b/docs/getting-started.md index 0b6e78b..088af95 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -13,7 +13,7 @@ Follow the prompts to select your favorite framework and features. After running `npm install`, add Commoners as a dependency: ```bash -npm install -D commoners@0.0.58 +npm install -D commoners@0.0.59 ``` ## Configuring the `package.json` File diff --git a/package.json b/package.json index 45aecf7..bb52236 100644 --- a/package.json +++ b/package.json @@ -20,13 +20,13 @@ "@commoners/bluetooth": "0.0.55", "@commoners/custom-protocol": "0.0.55", "@commoners/serial": "0.0.55", - "@commoners/solidarity": "0.0.58", + "@commoners/solidarity": "0.0.59", "@commoners/splash-screen": "0.0.55", - "@commoners/testing": "0.0.58", + "@commoners/testing": "0.0.59", "@commoners/windows": "0.0.58", "@vitest/coverage-v8": "^2.0.3", "search-insights": "^2.15.0", - "commoners": "0.0.58", + "commoners": "0.0.59", "vite": "^5.3.4", "vitepress": "^1.3.1", "vitest": "^2.0.3" diff --git a/packages/cli/package.json b/packages/cli/package.json index 7e73d7e..0459ef4 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,7 +1,7 @@ { "name": "commoners", "description": "Cross-Platform Development for the Rest of Us", - "version": "0.0.58", + "version": "0.0.59", "type": "module", "license": "MIT", "engines": { @@ -18,7 +18,7 @@ "watch": "vite build --watch" }, "dependencies": { - "@commoners/solidarity": "^0.0.58", + "@commoners/solidarity": "^0.0.59", "cac": "^6.7.14" }, "devDependencies": { diff --git a/packages/core/assets/electron/main.ts b/packages/core/assets/electron/main.ts index d1efc90..f0b493e 100644 --- a/packages/core/assets/electron/main.ts +++ b/packages/core/assets/electron/main.ts @@ -10,6 +10,16 @@ function normalizeAndCompare(path1, path2, comparison = (a,b) => a === b) { return comparison(decodePath(path1), decodePath(path2)) } +async function checkLinkType(url) { + try { + const response = await fetch(url, { method: 'HEAD' }); + const contentDisposition = response.headers.get('Content-Disposition'); + if (contentDisposition && contentDisposition.includes('attachment')) return 'download'; // Download if attachment + if (!response.headers.get('Content-Type').startsWith('text/html')) return 'download'; // Download if not an HTML file + return 'webpage'; + } catch (error) { return 'unknown' } +} + // Custom Window Flags // __main: Is Main Window // __show: Used to block show behavior @@ -297,13 +307,21 @@ const runWindowPlugins = async (win: BrowserWindow | null = null, type = 'load', }) - // CAtch all navigation events - win.webContents.on('will-navigate', (event, url) => { + // Catch all navigation events + win.webContents.on('will-navigate', async (event, url) => { event.preventDefault() + const urlObj = new URL(url) - const file = urlObj.pathname - loadPage(win, file) + const isValid = (devServerURL && devServerURL.startsWith(urlObj.origin)) || urlObj.protocol === 'file:' + + if (!isValid) { + const type = await checkLinkType(url) + if (type === 'download') return win.webContents.downloadURL(url) // Download + return shell.openExternal(url) // Opened externally + } + + loadPage(win, urlObj.pathname) // Required for successful navigation relative to the root (e.g. "../..") }) @@ -334,6 +352,7 @@ const runWindowPlugins = async (win: BrowserWindow | null = null, type = 'load', // ------------------------ Default Quit Behavior ------------------------ ipcMain.once('commoners:quit', () => app.quit()) + // ------------------------ Open Windows Externally ------------------------ win.webContents.setWindowOpenHandler(({ url }) => { shell.openExternal(url); return { action: 'deny' }; diff --git a/packages/core/package.json b/packages/core/package.json index 3c1ea73..d2a6c9b 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,7 +1,7 @@ { "name": "@commoners/solidarity", "description": "Build solidarity across platform", - "version": "0.0.58", + "version": "0.0.59", "type": "module", "license": "MIT", "exports": { diff --git a/packages/plugins/windows/package.json b/packages/plugins/windows/package.json index 5e27ffc..47130c9 100644 --- a/packages/plugins/windows/package.json +++ b/packages/plugins/windows/package.json @@ -12,6 +12,6 @@ "vite": "^5.3.4" }, "peerDependencies": { - "@commoners/solidarity": "^0.0.58" + "@commoners/solidarity": "^0.0.59" } } diff --git a/packages/testing/package.json b/packages/testing/package.json index 55373e6..b11dedb 100644 --- a/packages/testing/package.json +++ b/packages/testing/package.json @@ -1,6 +1,6 @@ { "name": "@commoners/testing", - "version": "0.0.58", + "version": "0.0.59", "license": "MIT", "type": "module", "main": "./dist/main.cjs", @@ -21,7 +21,7 @@ "postinstall": "pnpm exec playwright install chromium" }, "dependencies": { - "@commoners/solidarity": "^0.0.58", + "@commoners/solidarity": "^0.0.59", "playwright": "^1.48.0", "vite": "^5.4.2", "vitest": "^2.0.3" diff --git a/tests/demo/commoners.config.ts b/tests/demo/commoners.config.ts index a6100c6..310b1c6 100644 --- a/tests/demo/commoners.config.ts +++ b/tests/demo/commoners.config.ts @@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url"; // const root/ = resolve(dirname(fileURLToPath(import.meta.url))) const root = './' -import * as checksPlugin from './src/plugins/checks.ts' +import * as checksPlugin from './src/plugins/checks' import splashPagePlugin from '@commoners/splash-screen' import customProtocolPlugin from '@commoners/custom-protocol' @@ -75,7 +75,7 @@ const config = defineConfig({ plugins: { checks: checksPlugin, splash: splashPagePlugin(splashSrc), - protocol: customProtocolPlugin('app', { supportFetchAPI: true }), + protocol: customProtocolPlugin('commoners', { supportFetchAPI: true }), // NOTE: Test this in detail with a build windows: windowsPlugin({ popup: { src: join(root, "pages", "windows", 'popup.html'), diff --git a/tests/demo/index.html b/tests/demo/index.html index 40ba9c1..a01a779 100644 --- a/tests/demo/index.html +++ b/tests/demo/index.html @@ -14,6 +14,7 @@