diff --git a/README_CN.md b/README_CN.md index 43ecd2ff6..92175d8f3 100644 --- a/README_CN.md +++ b/README_CN.md @@ -228,6 +228,13 @@ Pake 的发展离不开这些 Hacker 们,一起贡献了大量能力,也欢 Pan93412 + + + jeasonnow +
+ Santree +
+ wanghanzhen @@ -248,15 +255,15 @@ Pake 的发展离不开这些 Hacker 们,一起贡献了大量能力,也欢
Essesoul
- + + AielloChan
Aiello
- - + m1911star @@ -271,13 +278,6 @@ Pake 的发展离不开这些 Hacker 们,一起贡献了大量能力,也欢 Pake Actions - - - jeasonnow -
- Santree -
- QingZ11 @@ -328,6 +328,13 @@ Pake 的发展离不开这些 Hacker 们,一起贡献了大量能力,也欢 Fechin + + + Milo123459 +
+ Milo +
+ princemaple @@ -348,15 +355,15 @@ Pake 的发展离不开这些 Hacker 们,一起贡献了大量能力,也欢
Null
- + + liusishan
Liusishan
- - + piaoyidage diff --git a/bin/cli.ts b/bin/cli.ts index 5e4e856fe..37f04a7a6 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -38,8 +38,8 @@ program .option('--iter-copy-file', 'Copy files when URL is a local file', DEFAULT.iterCopyFile) .option('--multi-arch', 'Only for Mac, supports both Intel and M1', DEFAULT.multiArch) .option('--targets ', 'Only for Linux, option "deb" or "appimage"', DEFAULT.targets) - .option('--inject [injects...]', 'Inject .js or .css for this app', DEFAULT.inject) - .option('--safe-domain [domains...]', 'Please enter the security domains that need to be configured', DEFAULT.safeDomain) + .option('--inject [injects...]', 'Injection of .js or .css Files', DEFAULT.inject) + .option('--safe-domain [domains...]', 'Domains that Require Security Configuration"', DEFAULT.safeDomain) .option('--debug', 'Debug mode', DEFAULT.debug) .version(packageJson.version, '-v, --version', 'Output the current version') .action(async (url: string, options: PakeCliOptions) => { diff --git a/bin/defaults.ts b/bin/defaults.ts index 23464d979..9fa26fde0 100644 --- a/bin/defaults.ts +++ b/bin/defaults.ts @@ -19,9 +19,11 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = { safeDomain: [], }; -// just for cli development +// Just for cli development export const DEFAULT_DEV_PAKE_OPTIONS: PakeCliOptions & {url: string} = { ...DEFAULT_PAKE_OPTIONS, url: 'https://weread.qq.com', - name: 'Weread', -} \ No newline at end of file + name: 'WeRead', + safeDomain:['weread.qq.com'], + transparent: true, +} diff --git a/dist/cli.js b/dist/cli.js index db315f4a4..87c1e30e3 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -1,307 +1,313 @@ -import chalk from 'chalk'; -import { InvalidArgumentError, program } from 'commander'; -import log from 'loglevel'; -import path from 'path'; -import fsExtra from 'fs-extra'; -import prompts from 'prompts'; -import shelljs from 'shelljs'; -import crypto from 'crypto'; -import ora from 'ora'; -import { fileURLToPath } from 'url'; -import dns from 'dns'; -import http from 'http'; -import { promisify } from 'util'; -import updateNotifier from 'update-notifier'; -import axios from 'axios'; -import { dir } from 'tmp-promise'; -import { fileTypeFromBuffer } from 'file-type'; -import psl from 'psl'; -import isUrl from 'is-url'; -import fs from 'fs'; - -var name = "pake-cli"; -var version = "2.2.5"; -var description = "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 很简单的用 Rust 打包网页生成很小的桌面 App。"; -var engines = { - node: ">=16.0.0" -}; -var bin = { - pake: "./cli.js" -}; -var repository = { - type: "git", - url: "https://github.com/tw93/pake.git" -}; -var author = { - name: "Tw93", - email: "tw93@qq.com" -}; -var keywords = [ - "pake", - "pake-cli", - "rust", - "tauri", - "no-electron", - "productivity" -]; -var files = [ - "dist", - "src-tauri", - "cli.js" -]; -var scripts = { - start: "npm run dev", - dev: "npm run tauri dev", - build: "npm run tauri build --release", - "build:mac": "npm run tauri build -- --target universal-apple-darwin", - "build:all-unix": "chmod +x ./script/build.sh && ./script/build.sh", - "build:all-windows": "pwsh ./script/build.ps1", - analyze: "cd src-tauri && cargo bloat --release --crates", - tauri: "tauri", - cli: "rollup -c rollup.config.js --watch", - "cli:build": "cross-env NODE_ENV=production rollup -c rollup.config.js", - prepublishOnly: "npm run cli:build" -}; -var type = "module"; -var exports = "./dist/pake.js"; -var license = "MIT"; -var dependencies = { - "@tauri-apps/api": "^1.4.0", - "@tauri-apps/cli": "^1.4.0", - axios: "^1.1.3", - chalk: "^5.1.2", - commander: "^11.0.0", - "file-type": "^18.0.0", - "fs-extra": "^11.1.0", - "is-url": "^1.2.4", - loglevel: "^1.8.1", - ora: "^6.1.2", - prompts: "^2.4.2", - psl: "^1.9.0", - shelljs: "^0.8.5", - "tmp-promise": "^3.0.3", - "update-notifier": "^6.0.2" -}; -var devDependencies = { - "@rollup/plugin-alias": "^4.0.2", - "@rollup/plugin-commonjs": "^23.0.2", - "@rollup/plugin-json": "^5.0.2", - "@rollup/plugin-terser": "^0.1.0", - "@types/fs-extra": "^9.0.13", - "@types/is-url": "^1.2.30", - "@types/page-icon": "^0.3.4", - "@types/prompts": "^2.4.1", - "@types/psl": "^1.1.0", - "@types/shelljs": "^0.8.11", - "@types/tmp": "^0.2.3", - "@types/update-notifier": "^6.0.1", - "app-root-path": "^3.1.0", - "cross-env": "^7.0.3", - rollup: "^3.3.0", - "rollup-plugin-typescript2": "^0.34.1", - tslib: "^2.4.1", - typescript: "^4.9.3" -}; -var packageJson = { - name: name, - version: version, - description: description, - engines: engines, - bin: bin, - repository: repository, - author: author, - keywords: keywords, - files: files, - scripts: scripts, - type: type, - exports: exports, - license: license, - dependencies: dependencies, - devDependencies: devDependencies -}; - -var windows = [ - { - url: "https://weread.qq.com/", - transparent: true, - fullscreen: false, - width: 1200, - height: 780, - resizable: true, - url_type: "web" - } -]; -var user_agent = { - macos: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15", - linux: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36", - windows: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" -}; -var menu = { - macos: true, - linux: false, - windows: false -}; -var system_tray = { - macos: false, - linux: true, - windows: true -}; -var pakeConf = { - windows: windows, - user_agent: user_agent, - menu: menu, - system_tray: system_tray -}; - -var tauri$3 = { - security: { - csp: null, - dangerousRemoteDomainIpcAccess: [ - { - domain: "weread.qq.com", - windows: [ - "pake" - ], - enableTauriAPI: true - } - ] - }, - updater: { - active: false - }, - systemTray: { - iconPath: "png/weread_512.png", - iconAsTemplate: true - }, - allowlist: { - all: true, - fs: { - all: true, - scope: [ - "$DOWNLOAD/*" - ] - } - } -}; -var build = { - withGlobalTauri: true, - devPath: "../dist", - distDir: "../dist", - beforeBuildCommand: "", - beforeDevCommand: "" -}; -var CommonConf = { - "package": { - productName: "WeRead", - version: "1.0.0" -}, - tauri: tauri$3, - build: build -}; - -var tauri$2 = { - bundle: { - icon: [ - "png/weread_256.ico", - "png/weread_32.ico" - ], - identifier: "com.pake.weread", - active: true, - category: "DeveloperTool", - copyright: "", - externalBin: [ - ], - longDescription: "", - resources: [ - "png/weread_32.ico" - ], - shortDescription: "", - targets: [ - "msi" - ], - windows: { - certificateThumbprint: null, - digestAlgorithm: "sha256", - timestampUrl: "", - wix: { - language: [ - "en-US" - ], - template: "assets/main.wxs" - } - } - } -}; -var WinConf = { - tauri: tauri$2 -}; - -var tauri$1 = { - bundle: { - icon: [ - "icons/weread.icns" - ], - identifier: "com.pake.weread", - active: true, - category: "DeveloperTool", - copyright: "", - externalBin: [ - ], - longDescription: "", - macOS: { - entitlements: null, - exceptionDomain: "", - frameworks: [ - ], - providerShortName: null, - signingIdentity: null - }, - resources: [ - ], - shortDescription: "", - targets: [ - "dmg" - ] - } -}; -var MacConf = { - tauri: tauri$1 -}; - -var tauri = { - bundle: { - icon: [ - "png/weread_512.png" - ], - identifier: "com.pake.weread", - active: true, - category: "DeveloperTool", - copyright: "", - deb: { - depends: [ - "curl", - "wget" - ], - files: { - "/usr/share/applications/com-pake-weread.desktop": "assets/com-pake-weread.desktop" - } - }, - externalBin: [ - ], - longDescription: "", - resources: [ - ], - shortDescription: "", - targets: [ - "deb", - "appimage" - ] - } -}; -var LinuxConf = { - tauri: tauri -}; - +import chalk from 'chalk'; +import { InvalidArgumentError, program } from 'commander'; +import log from 'loglevel'; +import path from 'path'; +import fsExtra from 'fs-extra'; +import prompts from 'prompts'; +import shelljs from 'shelljs'; +import crypto from 'crypto'; +import ora from 'ora'; +import { fileURLToPath } from 'url'; +import dns from 'dns'; +import http from 'http'; +import { promisify } from 'util'; +import fs from 'fs'; +import updateNotifier from 'update-notifier'; +import axios from 'axios'; +import { dir } from 'tmp-promise'; +import { fileTypeFromBuffer } from 'file-type'; +import psl from 'psl'; +import isUrl from 'is-url'; + +var name = "pake-cli"; +var version = "2.2.5"; +var description = "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 利用 Rust 轻松构建轻量级多端桌面应用。"; +var engines = { + node: ">=16.0.0" +}; +var bin = { + pake: "./cli.js" +}; +var repository = { + type: "git", + url: "https://github.com/tw93/pake.git" +}; +var author = { + name: "Tw93", + email: "tw93@qq.com" +}; +var keywords = [ + "pake", + "pake-cli", + "rust", + "tauri", + "no-electron", + "productivity" +]; +var files = [ + "dist", + "src-tauri", + "cli.js" +]; +var scripts = { + start: "npm run dev", + dev: "npm run tauri dev", + build: "npm run tauri build --release", + "build:debug": "npm run tauri build -- --debug", + "build:mac": "npm run tauri build -- --target universal-apple-darwin", + "build:all-unix": "chmod +x ./script/build.sh && ./script/build.sh", + "build:all-windows": "pwsh ./script/build.ps1", + analyze: "cd src-tauri && cargo bloat --release --crates", + tauri: "tauri", + cli: "rollup -c rollup.config.js --watch", + "cli:dev": "cross-env NODE_ENV=development rollup -c rollup.config.js -w", + "cli:build": "cross-env NODE_ENV=production rollup -c rollup.config.js", + prepublishOnly: "npm run cli:build" +}; +var type = "module"; +var exports = "./dist/pake.js"; +var license = "MIT"; +var dependencies = { + "@tauri-apps/api": "^1.4.0", + "@tauri-apps/cli": "^1.4.0", + axios: "^1.1.3", + chalk: "^5.1.2", + commander: "^11.0.0", + "file-type": "^18.0.0", + "fs-extra": "^11.1.0", + "is-url": "^1.2.4", + loglevel: "^1.8.1", + ora: "^6.1.2", + prompts: "^2.4.2", + psl: "^1.9.0", + shelljs: "^0.8.5", + "tmp-promise": "^3.0.3", + "update-notifier": "^6.0.2" +}; +var devDependencies = { + "@rollup/plugin-alias": "^4.0.2", + "@rollup/plugin-commonjs": "^23.0.2", + "@rollup/plugin-json": "^5.0.2", + "@rollup/plugin-replace": "^5.0.2", + "@rollup/plugin-terser": "^0.1.0", + "@types/fs-extra": "^9.0.13", + "@types/is-url": "^1.2.30", + "@types/page-icon": "^0.3.4", + "@types/prompts": "^2.4.1", + "@types/psl": "^1.1.0", + "@types/shelljs": "^0.8.11", + "@types/tmp": "^0.2.3", + "@types/update-notifier": "^6.0.1", + "app-root-path": "^3.1.0", + "cross-env": "^7.0.3", + rollup: "^3.3.0", + "rollup-plugin-typescript2": "^0.34.1", + tslib: "^2.4.1", + typescript: "^4.9.3" +}; +var packageJson = { + name: name, + version: version, + description: description, + engines: engines, + bin: bin, + repository: repository, + author: author, + keywords: keywords, + files: files, + scripts: scripts, + type: type, + exports: exports, + license: license, + dependencies: dependencies, + devDependencies: devDependencies +}; + +var windows = [ + { + url: "https://weread.qq.com/", + transparent: true, + fullscreen: false, + width: 1200, + height: 780, + resizable: true, + url_type: "web" + } +]; +var user_agent = { + macos: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15", + linux: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36", + windows: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" +}; +var menu = { + macos: false, + linux: false, + windows: false +}; +var system_tray = { + macos: false, + linux: true, + windows: true +}; +var inject = [ +]; +var pakeConf = { + windows: windows, + user_agent: user_agent, + menu: menu, + system_tray: system_tray, + inject: inject +}; + +var tauri$3 = { + security: { + csp: null, + dangerousRemoteDomainIpcAccess: [ + { + domain: "weread.qq.com", + windows: [ + "pake" + ], + enableTauriAPI: true + } + ] + }, + updater: { + active: false + }, + systemTray: { + iconPath: "png/icon_512.png", + iconAsTemplate: true + }, + allowlist: { + all: true, + fs: { + all: true, + scope: [ + "$DOWNLOAD/*" + ] + } + } +}; +var build = { + withGlobalTauri: true, + devPath: "../dist", + distDir: "../dist", + beforeBuildCommand: "", + beforeDevCommand: "" +}; +var CommonConf = { + "package": { + productName: "WeRead", + version: "1.0.0" +}, + tauri: tauri$3, + build: build +}; + +var tauri$2 = { + bundle: { + icon: [ + "png/weread_256.ico", + "png/weread_32.ico" + ], + identifier: "com.pake.weread", + active: true, + category: "DeveloperTool", + copyright: "", + externalBin: [ + ], + longDescription: "", + resources: [ + "png/weread_32.ico" + ], + shortDescription: "", + targets: [ + "msi" + ], + windows: { + certificateThumbprint: null, + digestAlgorithm: "sha256", + timestampUrl: "", + wix: { + language: [ + "en-US" + ], + template: "assets/main.wxs" + } + } + } +}; +var WinConf = { + tauri: tauri$2 +}; + +var tauri$1 = { + bundle: { + icon: [ + "icons/weread.icns" + ], + identifier: "com.pake.weread", + active: true, + category: "DeveloperTool", + copyright: "", + externalBin: [ + ], + longDescription: "", + macOS: { + entitlements: null, + exceptionDomain: "", + frameworks: [ + ], + providerShortName: null, + signingIdentity: null + }, + resources: [ + ], + shortDescription: "", + targets: [ + "dmg" + ] + } +}; +var MacConf = { + tauri: tauri$1 +}; + +var tauri = { + bundle: { + icon: [ + "png/weread_512.png" + ], + identifier: "com.pake.weread", + active: true, + category: "DeveloperTool", + copyright: "", + deb: { + depends: [ + "curl", + "wget" + ], + files: { + "/usr/share/applications/com-pake-weread.desktop": "assets/com-pake-weread.desktop" + } + }, + externalBin: [ + ], + longDescription: "", + resources: [ + ], + shortDescription: "", + targets: [ + "deb", + "appimage" + ] + } +}; +var LinuxConf = { + tauri: tauri +}; + const platformConfigs = { win32: WinConf, darwin: MacConf, @@ -318,8 +324,8 @@ let tauriConfig = { package: CommonConf.package, build: CommonConf.build, pake: pakeConf, -}; - +}; + // Generates an identifier based on the given URL. function getIdentifier(url) { const postFixHash = crypto.createHash('md5').update(url).digest('hex').substring(0, 6); @@ -347,19 +353,19 @@ function getSpinner(text) { spinner: loadingType, color: 'cyan', }).start(); -} - +} + const { platform: platform$1 } = process; const IS_MAC = platform$1 === 'darwin'; const IS_WIN = platform$1 === 'win32'; -const IS_LINUX = platform$1 === 'linux'; - +const IS_LINUX = platform$1 === 'linux'; + // Convert the current module URL to a file path const currentModulePath = fileURLToPath(import.meta.url); // Resolve the parent directory of the current module const npmDirectory = path.join(path.dirname(currentModulePath), '..'); -const tauriConfigDirectory = path.join(npmDirectory, 'src-tauri'); - +const tauriConfigDirectory = path.join(npmDirectory, 'src-tauri'); + function shellExec(command) { return new Promise((resolve, reject) => { shelljs.exec(command, { async: true, silent: false, cwd: npmDirectory }, code => { @@ -371,8 +377,8 @@ function shellExec(command) { } }); }); -} - +} + const logger = { info(...msg) { log.info(...msg.map(m => chalk.white(m))); @@ -389,8 +395,8 @@ const logger = { success(...msg) { log.info(...msg.map(m => chalk.green(m))); }, -}; - +}; + const resolve = promisify(dns.resolve); const ping = async (host) => { const lookup = promisify(dns.lookup); @@ -434,8 +440,8 @@ async function isChinaIP(ip, domain) { logger.debug(`ping ${domain} failed!`); return true; } -} - +} + async function installRust() { const isActions = process.env.GITHUB_ACTIONS; const isInChina = await isChinaDomain('sh.rustup.rs'); @@ -456,8 +462,8 @@ async function installRust() { } function checkRustInstalled() { return shelljs.exec('rustc --version', { silent: true }).code === 0; -} - +} + async function combineFiles(files, output) { const contents = files.map(file => { const fileContent = fs.readFileSync(file); @@ -468,8 +474,8 @@ async function combineFiles(files, output) { }); fs.writeFileSync(output, contents.join('\n')); return files; -} - +} + async function mergeConfig(url, options, tauriConf) { const { width, height, fullscreen, transparent, userAgent, showMenu, showSystemTray, systemTrayIcon, iterCopyFile, identifier, name, resizable = true, inject, safeDomain, } = options; const { platform } = process; @@ -619,7 +625,7 @@ async function mergeConfig(url, options, tauriConf) { } } tauriConf.tauri.systemTray.iconPath = trayIconPath; - const injectFilePath = path.join(npmDirectory, `src-tauri/src/inject/_INJECT_.js`); + const injectFilePath = path.join(npmDirectory, `src-tauri/src/inject/custom.js`); // inject js or css files if (inject?.length > 0) { if (!inject.every(item => item.endsWith('.css') || item.endsWith('.js'))) { @@ -650,8 +656,8 @@ async function mergeConfig(url, options, tauriConf) { delete tauriConf2.tauri.bundle; const configJsonPath = path.join(tauriConfigDirectory, 'tauri.conf.json'); await fsExtra.outputJSON(configJsonPath, tauriConf2, { spaces: 4 }); -} - +} + class BaseBuilder { constructor(options) { this.options = options; @@ -733,8 +739,8 @@ class BaseBuilder { getBuildAppPath(npmDirectory, fileName, fileType) { return path.join(npmDirectory, this.getBasePath(), fileType.toLowerCase(), `${fileName}.${fileType}`); } -} - +} + class MacBuilder extends BaseBuilder { constructor(options) { super(options); @@ -759,8 +765,8 @@ class MacBuilder extends BaseBuilder { ? 'src-tauri/target/universal-apple-darwin/release/bundle' : super.getBasePath(); } -} - +} + class WinBuilder extends BaseBuilder { constructor(options) { super(options); @@ -772,8 +778,8 @@ class WinBuilder extends BaseBuilder { const language = tauriConfig.tauri.bundle.windows.wix.language[0]; return `${name}_${tauriConfig.package.version}_${arch}_${language}`; } -} - +} + class LinuxBuilder extends BaseBuilder { constructor(options) { super(options); @@ -798,8 +804,8 @@ class LinuxBuilder extends BaseBuilder { } return super.getFileType(target); } -} - +} + const { platform } = process; const buildersMap = { darwin: MacBuilder, @@ -814,8 +820,8 @@ class BuilderProvider { } return new Builder(options); } -} - +} + const DEFAULT_PAKE_OPTIONS = { icon: '', height: 780, @@ -833,12 +839,12 @@ const DEFAULT_PAKE_OPTIONS = { debug: false, inject: [], safeDomain: [], -}; - +}; + async function checkUpdateTips() { updateNotifier({ pkg: packageJson, updateCheckInterval: 1000 * 60 }).notify({ isGlobal: true }); -} - +} + async function handleIcon(options) { if (options.icon) { if (options.icon.startsWith('http')) { @@ -891,8 +897,8 @@ async function downloadIcon(iconUrl) { } throw error; } -} - +} + // Extracts the domain from a given URL. function getDomain(inputUrl) { try { @@ -930,8 +936,8 @@ function normalizeUrl(urlToNormalize) { else { throw new Error(`Your url "${urlWithProtocol}" is invalid`); } -} - +} + function resolveAppName(name, platform) { const domain = getDomain(name) || 'pake'; return platform !== 'linux' ? capitalizeFirstLetter(domain) : domain; @@ -975,8 +981,8 @@ async function handleOptions(options, url) { }; appOptions.icon = await handleIcon(appOptions); return appOptions; -} - +} + function validateNumberInput(value) { const parsedValue = Number(value); if (isNaN(parsedValue)) { @@ -995,14 +1001,14 @@ function validateUrlInput(url) { } } return url; -} - +} + const { green, yellow } = chalk; -const logo = `${chalk.green(' ____ _')} -${green('| _ \\ __ _| | _____')} -${green('| |_) / _` | |/ / _ \\')} -${green('| __/ (_| | < __/')} ${yellow('https://github.com/tw93/pake')} -${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with Rust.')} +const logo = `${chalk.green(' ____ _')} +${green('| _ \\ __ _| | _____')} +${green('| |_) / _` | |/ / _ \\')} +${green('| __/ (_| | < __/')} ${yellow('https://github.com/tw93/pake')} +${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with Rust.')} `; program .addHelpText('beforeAll', logo) @@ -1023,8 +1029,8 @@ program .option('--iter-copy-file', 'Copy files when URL is a local file', DEFAULT_PAKE_OPTIONS.iterCopyFile) .option('--multi-arch', 'Only for Mac, supports both Intel and M1', DEFAULT_PAKE_OPTIONS.multiArch) .option('--targets ', 'Only for Linux, option "deb" or "appimage"', DEFAULT_PAKE_OPTIONS.targets) - .option('--inject [injects...]', 'inject .js or .css for this app', DEFAULT_PAKE_OPTIONS.inject) - .option('--safe-domain [domains...]', 'domains that can call window.__TAURI__ and use ipc', DEFAULT_PAKE_OPTIONS.safeDomain) + .option('--inject [injects...]', 'Injection of .js or .css Files', DEFAULT_PAKE_OPTIONS.inject) + .option('--safe-domain [domains...]', 'Domains that Require Security Configuration"', DEFAULT_PAKE_OPTIONS.safeDomain) .option('--debug', 'Debug mode', DEFAULT_PAKE_OPTIONS.debug) .version(packageJson.version, '-v, --version', 'Output the current version') .action(async (url, options) => { @@ -1048,4 +1054,4 @@ program await builder.prepare(); await builder.build(url); }); -program.parse(); +program.parse(); diff --git a/plugins/pakeCliDevPlugin.js b/plugins/pakeCliDevPlugin.js index 33f8f161e..62def614b 100644 --- a/plugins/pakeCliDevPlugin.js +++ b/plugins/pakeCliDevPlugin.js @@ -1,6 +1,5 @@ import chalk from 'chalk'; -import {spawn, exec} from 'child_process'; - +import { spawn, exec } from 'child_process'; // just run in development mode export default function pakeCliDevPlugin() { @@ -15,8 +14,8 @@ export default function pakeCliDevPlugin() { const command = 'node'; const cliCmdArgs = ['./dist/dev.js']; - - cliChildProcess = spawn(command, cliCmdArgs, {detached: true}); + + cliChildProcess = spawn(command, cliCmdArgs, { detached: true }); cliChildProcess.stdout.on('data', (data) => { console.log(chalk.green(data.toString())); @@ -35,7 +34,7 @@ export default function pakeCliDevPlugin() { devChildProcess.stdout.on('data', (data) => { console.log(chalk.green(data.toString())); }); - + devChildProcess.stderr.on('data', (data) => { console.error(chalk.yellow(data.toString())); }); @@ -45,6 +44,6 @@ export default function pakeCliDevPlugin() { process.exit(code); }); }); - } - } -} \ No newline at end of file + }, + }; +} diff --git a/rollup.config.js b/rollup.config.js index 1aaf44b29..2289976ef 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -25,12 +25,13 @@ export default { plugins: [ json(), typescript({ - tsconfig: "tsconfig.json", - clean: true, // 清理缓存 + tsconfig: 'tsconfig.json', + clean: true, // Clear cache }), commonjs(), replace({ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV), + preventAssignment: true, }), alias({ entries: [{ find: '@', replacement: path.join(appRootPath.path, 'bin') }], diff --git a/src-tauri/icons/weread.icns b/src-tauri/icons/weread.icns index 08e095b02..16a492099 100644 Binary files a/src-tauri/icons/weread.icns and b/src-tauri/icons/weread.icns differ diff --git a/src-tauri/pake.json b/src-tauri/pake.json index 96dd6fbe1..31f5d5666 100644 --- a/src-tauri/pake.json +++ b/src-tauri/pake.json @@ -1,29 +1,29 @@ { - "windows": [ - { - "url": "https://weread.qq.com/", - "transparent": false, - "fullscreen": false, - "width": 1200, - "height": 780, - "resizable": true, - "url_type": "web" - } - ], - "user_agent": { - "macos": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15", - "linux": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36", - "windows": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" - }, - "menu": { - "macos": false, - "linux": false, - "windows": false - }, - "system_tray": { - "macos": false, - "linux": true, - "windows": true - }, - "inject": [] + "windows": [ + { + "url": "https://weread.qq.com/", + "transparent": true, + "fullscreen": false, + "width": 1200, + "height": 780, + "resizable": true, + "url_type": "web" + } + ], + "user_agent": { + "macos": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15", + "linux": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36", + "windows": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36" + }, + "menu": { + "macos": false, + "linux": false, + "windows": false + }, + "system_tray": { + "macos": false, + "linux": true, + "windows": true + }, + "inject": [] } diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs index c8485db25..24aed37b1 100644 --- a/src-tauri/src/app/window.rs +++ b/src-tauri/src/app/window.rs @@ -30,7 +30,8 @@ pub fn get_window(app: &mut App, config: PakeConfig, _data_dir: PathBuf) -> Wind .initialization_script(include_str!("../inject/component.js")) .initialization_script(include_str!("../inject/event.js")) .initialization_script(include_str!("../inject/style.js")) - .initialization_script(include_str!("../inject/custom.js")); //Very annoying, otherwise dragging files to the window will not work. + //This is necessary to allow for file injection by external developers for customization purposes. + .initialization_script(include_str!("../inject/custom.js")); #[cfg(target_os = "macos")] { diff --git a/src-tauri/src/inject/custom.js b/src-tauri/src/inject/custom.js index 9c013037d..6b9ed4626 100644 --- a/src-tauri/src/inject/custom.js +++ b/src-tauri/src/inject/custom.js @@ -1,2 +1,6 @@ -// This file is used to merge the injected external js and css files -// and you can also directly add script files that you want to attach to the application in this fil \ No newline at end of file +/* + * This file serves as a collection point for external JS and CSS dependencies. + * It amalgamates these external resources for easier injection into the application. + * Additionally, you can directly include any script files in this file + * that you wish to attach to the application. + */ diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.js index 71ecc1334..6056616db 100644 --- a/src-tauri/src/inject/event.js +++ b/src-tauri/src/inject/event.js @@ -68,95 +68,17 @@ document.addEventListener('DOMContentLoaded', () => { document.body.appendChild(topDom); const domEl = document.getElementById('pack-top-dom'); - -// Collect blob urls to blob by overriding window.URL.createObjectURL -function collectUrlToBlobs() { - const backupCreateObjectURL = window.URL.createObjectURL; - window.blobToUrlCaches = new Map(); - window.URL.createObjectURL = (blob) => { - const url = backupCreateObjectURL.call(window.URL, blob); - window.blobToUrlCaches.set(url, blob); - return url; - }; -} - -function convertBlobUrlToBinary(blobUrl) { - return new Promise((resolve) => { - const blob = window.blobToUrlCaches.get(blobUrl); - const reader = new FileReader(); - - reader.readAsArrayBuffer(blob); - reader.onload = () => { - resolve(Array.from(new Uint8Array(reader.result))); - }; - }); -} - -function downladFromDataUri(dataURI, filename) { - const byteString = atob(dataURI.split(',')[1]); - // write the bytes of the string to an ArrayBuffer - const bufferArray = new ArrayBuffer(byteString.length); - - // create a view into the buffer - const binary = new Uint8Array(bufferArray); - - // set the bytes of the buffer to the correct values - for (var i = 0; i < byteString.length; i++) { - binary[i] = byteString.charCodeAt(i); - } - - // write the ArrayBuffer to a binary, and you're done - invoke('download_file_by_binary', { - params: { - filename, - binary: Array.from(binary) - }, - }); -} - -function downloadFromBlobUrl(blobUrl, filename) { - convertBlobUrlToBinary(blobUrl).then((binary) => { - invoke('download_file_by_binary', { - params: { - filename, - binary - }, - }); - }); -} - - -// detect blob download by createElement("a") -function detectDownloadByCreateAnchor() { - const createEle = document.createElement; - document.createElement = (el) => { - if (el !== 'a') return createEle.call(document, el); - const anchorEle = createEle.call(document, el); - - // use addEventListener to avoid overriding the original click event. - anchorEle.addEventListener('click', (e) => { - const url = anchorEle.href; - const filename = anchorEle.download || getFilenameFromUrl(url); - if (window.blobToUrlCaches.has(url)) { - downloadFromBlobUrl(url, filename); - // case: downoload from dataURL -> convert dataURL -> - } else if (url.startsWith('data:')) { - downladFromDataUri(url, filename); - } else { - handleExternalLink(e, url); - } - }, true); - - return anchorEle; - }; -} - - - domEl.addEventListener('touchstart', () => { appWindow.startDragging().then(); }); + domEl.addEventListener('mousedown', (e) => { + e.preventDefault(); + if (e.buttons === 1 && e.detail !== 2) { + appWindow.startDragging().then(); + } + }); + domEl.addEventListener('dblclick', () => { appWindow.isFullscreen().then((fullscreen) => { appWindow.setFullscreen(!fullscreen).then(); @@ -172,8 +94,90 @@ function detectDownloadByCreateAnchor() { } }); + // Collect blob urls to blob by overriding window.URL.createObjectURL + function collectUrlToBlobs() { + const backupCreateObjectURL = window.URL.createObjectURL; + window.blobToUrlCaches = new Map(); + window.URL.createObjectURL = (blob) => { + const url = backupCreateObjectURL.call(window.URL, blob); + window.blobToUrlCaches.set(url, blob); + return url; + }; + } + + function convertBlobUrlToBinary(blobUrl) { + return new Promise((resolve) => { + const blob = window.blobToUrlCaches.get(blobUrl); + const reader = new FileReader(); + + reader.readAsArrayBuffer(blob); + reader.onload = () => { + resolve(Array.from(new Uint8Array(reader.result))); + }; + }); + } + + function downloadFromDataUri(dataURI, filename) { + const byteString = atob(dataURI.split(',')[1]); + // write the bytes of the string to an ArrayBuffer + const bufferArray = new ArrayBuffer(byteString.length); + + // create a view into the buffer + const binary = new Uint8Array(bufferArray); + + // set the bytes of the buffer to the correct values + for (let i = 0; i < byteString.length; i++) { + binary[i] = byteString.charCodeAt(i); + } + + // write the ArrayBuffer to a binary, and you're done + invoke('download_file_by_binary', { + params: { + filename, + binary: Array.from(binary) + }, + }); + } + + function downloadFromBlobUrl(blobUrl, filename) { + convertBlobUrlToBinary(blobUrl).then((binary) => { + invoke('download_file_by_binary', { + params: { + filename, + binary + }, + }); + }); + } + + +// detect blob download by createElement("a") + function detectDownloadByCreateAnchor() { + const createEle = document.createElement; + document.createElement = (el) => { + if (el !== 'a') return createEle.call(document, el); + const anchorEle = createEle.call(document, el); + + // use addEventListener to avoid overriding the original click event. + anchorEle.addEventListener('click', (e) => { + const url = anchorEle.href; + const filename = anchorEle.download || getFilenameFromUrl(url); + if (window.blobToUrlCaches.has(url)) { + downloadFromBlobUrl(url, filename); + // case: download from dataURL -> convert dataURL -> + } else if (url.startsWith('data:')) { + downloadFromDataUri(url, filename); + } else { + handleExternalLink(e, url); + } + }, true); + + return anchorEle; + }; + } + const isExternalLink = (url, host) => window.location.host !== host; - // process special download protocal['data:','blob:'] + // process special download protocol['data:','blob:'] const isSpecialDownload = (url) => ['blob', 'data'].some(protocal => url.startsWith(protocal)); const isDownloadRequired = (url, anchorElement, e) => @@ -186,7 +190,7 @@ function detectDownloadByCreateAnchor() { const handleDownloadLink = (e, url, filename) => { e.preventDefault(); - invoke('download_file', { params: { url, filename } }); + invoke('download_file', {params: {url, filename}}); }; const detectAnchorElementClick = (e) => { @@ -217,7 +221,7 @@ function detectDownloadByCreateAnchor() { // Rewrite the window.open function. const originalWindowOpen = window.open; - window.open = function(url, name, specs) { + window.open = function (url, name, specs) { // Apple login and google login if (name === 'AppleAuthentication') { //do nothing @@ -257,10 +261,3 @@ function getFilenameFromUrl(url) { const urlPath = new URL(url).pathname; return urlPath.substring(urlPath.lastIndexOf('/') + 1); } - - -// Determine the language of the current system. -function getSystemLanguage() { - const lang = navigator.language.substr(0, 2); - return lang === 'ch' ? 'ch' : 'en'; -} diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 306cb1f42..09501a28c 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,43 +1,39 @@ { - "package": { - "productName": "WeRead", - "version": "1.0.0" - }, - "tauri": { - "security": { - "csp": null, - "dangerousRemoteDomainIpcAccess": [ - { - "domain": "weread.qq.com", - "windows": [ - "pake" - ], - "enableTauriAPI": true - } - ] - }, - "updater": { - "active": false - }, - "systemTray": { - "iconPath": "png/icon_512.png", - "iconAsTemplate": true - }, - "allowlist": { - "all": true, - "fs": { - "all": true, - "scope": [ - "$DOWNLOAD/*" - ] - } + "package": { + "productName": "WeRead", + "version": "1.0.0" + }, + "tauri": { + "security": { + "csp": null, + "dangerousRemoteDomainIpcAccess": [ + { + "domain": "weread.qq.com", + "windows": ["pake"], + "enableTauriAPI": true } + ] + }, + "updater": { + "active": false + }, + "systemTray": { + "iconPath": "png/icon_512.png", + "iconAsTemplate": true }, - "build": { - "withGlobalTauri": true, - "devPath": "../dist", - "distDir": "../dist", - "beforeBuildCommand": "", - "beforeDevCommand": "" + "allowlist": { + "all": true, + "fs": { + "all": true, + "scope": ["$DOWNLOAD/*"] + } } + }, + "build": { + "withGlobalTauri": true, + "devPath": "../dist", + "distDir": "../dist", + "beforeBuildCommand": "", + "beforeDevCommand": "" + } } diff --git a/src-tauri/tauri.macos.conf.json b/src-tauri/tauri.macos.conf.json index e1d0328e1..cdfbfa188 100644 --- a/src-tauri/tauri.macos.conf.json +++ b/src-tauri/tauri.macos.conf.json @@ -1,25 +1,23 @@ { - "tauri": { - "bundle": { - "icon": ["icons/weread.icns"], - "identifier": "com.pake.weread", - "active": true, - "category": "DeveloperTool", - "copyright": "", - "externalBin": [], - "longDescription": "", - "macOS": { - "entitlements": null, - "exceptionDomain": "", - "frameworks": [], - "providerShortName": null, - "signingIdentity": null - }, - "resources": [], - "shortDescription": "", - "targets": [ - "dmg" - ] - } + "tauri": { + "bundle": { + "icon": ["icons/weread.icns"], + "identifier": "com.pake.weread", + "active": true, + "category": "DeveloperTool", + "copyright": "", + "externalBin": [], + "longDescription": "", + "macOS": { + "entitlements": null, + "exceptionDomain": "", + "frameworks": [], + "providerShortName": null, + "signingIdentity": null + }, + "resources": [], + "shortDescription": "", + "targets": ["dmg"] } + } }