🎨 Format Optimization
This commit is contained in:
9
bin/README.md
vendored
9
bin/README.md
vendored
@@ -40,14 +40,15 @@ npm install pake-cli -g
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Development
|
### Development
|
||||||
|
|
||||||
The `DEFAULT_DEV_PAKE_OPTIONS` configuration in `bin/defaults.ts` can be modified at development time to match the `pake-cli` configuration description.
|
The `DEFAULT_DEV_PAKE_OPTIONS` configuration in `bin/defaults.ts` can be modified at development time to match the `pake-cli` configuration description.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
export const DEFAULT_DEV_PAKE_OPTIONS: PakeCliOptions & {url: string} = {
|
export const DEFAULT_DEV_PAKE_OPTIONS: PakeCliOptions & { url: string } = {
|
||||||
...DEFAULT_PAKE_OPTIONS,
|
...DEFAULT_PAKE_OPTIONS,
|
||||||
url: 'https://weread.qq.com',
|
url: 'https://weread.qq.com',
|
||||||
name: 'Weread',
|
name: 'Weread',
|
||||||
}
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
then
|
then
|
||||||
@@ -129,7 +130,6 @@ screen.
|
|||||||
--fullscreen
|
--fullscreen
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
#### [activation-shortcut]
|
#### [activation-shortcut]
|
||||||
|
|
||||||
Set the activation shortcut for the application. Default is ` `, it does not take effect, you can customize the activation shortcut with the following commands, e.g. `CmdOrControl+Shift+P`, use can refer to [available-modifiers](https://www.electronjs.org/docs/latest/api/accelerator#available-modifiers).
|
Set the activation shortcut for the application. Default is ` `, it does not take effect, you can customize the activation shortcut with the following commands, e.g. `CmdOrControl+Shift+P`, use can refer to [available-modifiers](https://www.electronjs.org/docs/latest/api/accelerator#available-modifiers).
|
||||||
@@ -221,7 +221,7 @@ Enable recursive copying. When the URL is a local file path, enabling this optio
|
|||||||
|
|
||||||
#### [inject]
|
#### [inject]
|
||||||
|
|
||||||
Using `inject`, you can inject local absolute and relative path `css` and `js` files into the page you specify the `url` to customize it. For example, an adblock script that can be applied to any web page, or a `css` that optimizes the `UI` of a page, you can write it once to customize it. would only need to write the `app` once to generalize it to any other page.
|
Using `inject`, you can inject local absolute and relative path `css` and `js` files into the page you specify the `url` to customize it. For example, an adblock script that can be applied to any web page, or a `css` that optimizes the `UI` of a page, you can write it once to customize it. would only need to write the `app` once to generalize it to any other page.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
--inject ./tools/style.css,./tools/hotkey.js
|
--inject ./tools/style.css,./tools/hotkey.js
|
||||||
@@ -248,4 +248,3 @@ The typed package has dev-tools for debugging, in addition to outputting more lo
|
|||||||
## Conclusion
|
## Conclusion
|
||||||
|
|
||||||
After completing the above steps, your application should be successfully packaged. Please note that the packaging process may take some time depending on your system configuration and network conditions. Be patient, and once the packaging is complete, you can find the application installer in the specified directory.
|
After completing the above steps, your application should be successfully packaged. Please note that the packaging process may take some time depending on your system configuration and network conditions. Be patient, and once the packaging is complete, you can find the application installer in the specified directory.
|
||||||
|
|
||||||
|
|||||||
4
bin/README_CN.md
vendored
4
bin/README_CN.md
vendored
@@ -44,11 +44,11 @@ npm install pake-cli -g
|
|||||||
开发时可以修改 `bin/defaults.ts` 中 `DEFAULT_DEV_PAKE_OPTIONS` 配置,配置项和 `pake-cli` 配置说明保持一致
|
开发时可以修改 `bin/defaults.ts` 中 `DEFAULT_DEV_PAKE_OPTIONS` 配置,配置项和 `pake-cli` 配置说明保持一致
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
export const DEFAULT_DEV_PAKE_OPTIONS: PakeCliOptions & {url: string} = {
|
export const DEFAULT_DEV_PAKE_OPTIONS: PakeCliOptions & { url: string } = {
|
||||||
...DEFAULT_PAKE_OPTIONS,
|
...DEFAULT_PAKE_OPTIONS,
|
||||||
url: 'https://weread.qq.com',
|
url: 'https://weread.qq.com',
|
||||||
name: 'Weread',
|
name: 'Weread',
|
||||||
}
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
之后运行
|
之后运行
|
||||||
|
|||||||
25
bin/cli.ts
vendored
25
bin/cli.ts
vendored
@@ -18,10 +18,7 @@ ${green('| __/ (_| | < __/')} ${yellow('https://github.com/tw93/pake')}
|
|||||||
${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with Rust.')}
|
${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with Rust.')}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
program
|
program.addHelpText('beforeAll', logo).usage(`[url] [options]`).showHelpAfterError();
|
||||||
.addHelpText('beforeAll', logo)
|
|
||||||
.usage(`[url] [options]`)
|
|
||||||
.showHelpAfterError();
|
|
||||||
|
|
||||||
program
|
program
|
||||||
.argument('[url]', 'The web URL you want to package', validateUrlInput)
|
.argument('[url]', 'The web URL you want to package', validateUrlInput)
|
||||||
@@ -37,12 +34,24 @@ program
|
|||||||
.option('--inject [injects...]', 'Injection of .js or .css Files', DEFAULT.inject)
|
.option('--inject [injects...]', 'Injection of .js or .css Files', DEFAULT.inject)
|
||||||
.option('--debug', 'Debug build and more output', DEFAULT.debug)
|
.option('--debug', 'Debug build and more output', DEFAULT.debug)
|
||||||
.addOption(new Option('--user-agent <string>', 'Custom user agent').default(DEFAULT.userAgent).hideHelp())
|
.addOption(new Option('--user-agent <string>', 'Custom user agent').default(DEFAULT.userAgent).hideHelp())
|
||||||
.addOption(new Option('--targets <string>', 'Only for Linux, option "deb" or "appimage"').default(DEFAULT.targets).hideHelp())
|
.addOption(
|
||||||
|
new Option('--targets <string>', 'Only for Linux, option "deb" or "appimage"').default(DEFAULT.targets).hideHelp(),
|
||||||
|
)
|
||||||
.addOption(new Option('--always-on-top', 'Always on the top level').default(DEFAULT.alwaysOnTop).hideHelp())
|
.addOption(new Option('--always-on-top', 'Always on the top level').default(DEFAULT.alwaysOnTop).hideHelp())
|
||||||
.addOption(new Option('--disabled-web-shortcuts', 'Disabled webPage shortcuts').default(DEFAULT.disabledWebShortcuts).hideHelp())
|
.addOption(
|
||||||
.addOption(new Option('--safe-domain [domains...]', 'Domains that Require Security Configuration').default(DEFAULT.safeDomain).hideHelp())
|
new Option('--disabled-web-shortcuts', 'Disabled webPage shortcuts')
|
||||||
|
.default(DEFAULT.disabledWebShortcuts)
|
||||||
|
.hideHelp(),
|
||||||
|
)
|
||||||
|
.addOption(
|
||||||
|
new Option('--safe-domain [domains...]', 'Domains that Require Security Configuration')
|
||||||
|
.default(DEFAULT.safeDomain)
|
||||||
|
.hideHelp(),
|
||||||
|
)
|
||||||
.addOption(new Option('--show-system-tray', 'Show system tray in app').default(DEFAULT.showSystemTray).hideHelp())
|
.addOption(new Option('--show-system-tray', 'Show system tray in app').default(DEFAULT.showSystemTray).hideHelp())
|
||||||
.addOption(new Option('--system-tray-icon <string>', 'Custom system tray icon').default(DEFAULT.systemTrayIcon).hideHelp())
|
.addOption(
|
||||||
|
new Option('--system-tray-icon <string>', 'Custom system tray icon').default(DEFAULT.systemTrayIcon).hideHelp(),
|
||||||
|
)
|
||||||
.version(packageJson.version, '-v, --version', 'Output the current version')
|
.version(packageJson.version, '-v, --version', 'Output the current version')
|
||||||
.action(async (url: string, options: PakeCliOptions) => {
|
.action(async (url: string, options: PakeCliOptions) => {
|
||||||
await checkUpdateTips();
|
await checkUpdateTips();
|
||||||
|
|||||||
2
bin/dev.ts
vendored
2
bin/dev.ts
vendored
@@ -1,5 +1,5 @@
|
|||||||
import log from 'loglevel';
|
import log from 'loglevel';
|
||||||
import {DEFAULT_DEV_PAKE_OPTIONS} from './defaults';
|
import { DEFAULT_DEV_PAKE_OPTIONS } from './defaults';
|
||||||
import handleInputOptions from './options/index';
|
import handleInputOptions from './options/index';
|
||||||
import BuilderProvider from './builders/BuilderProvider';
|
import BuilderProvider from './builders/BuilderProvider';
|
||||||
|
|
||||||
|
|||||||
2
bin/helpers/merge.ts
vendored
2
bin/helpers/merge.ts
vendored
@@ -197,7 +197,7 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
|
|||||||
logger.error('The injected file must be in either CSS or JS format.');
|
logger.error('The injected file must be in either CSS or JS format.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const files = inject.map(filepath => path.isAbsolute(filepath) ? filepath : path.join(process.cwd(), filepath));
|
const files = inject.map(filepath => (path.isAbsolute(filepath) ? filepath : path.join(process.cwd(), filepath)));
|
||||||
tauriConf.pake.inject = files;
|
tauriConf.pake.inject = files;
|
||||||
await combineFiles(files, injectFilePath);
|
await combineFiles(files, injectFilePath);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
7
bin/helpers/rust.ts
vendored
7
bin/helpers/rust.ts
vendored
@@ -9,9 +9,10 @@ import { isChinaDomain } from '@/utils/ip';
|
|||||||
export async function installRust() {
|
export async function installRust() {
|
||||||
const isActions = process.env.GITHUB_ACTIONS;
|
const isActions = process.env.GITHUB_ACTIONS;
|
||||||
const isInChina = await isChinaDomain('sh.rustup.rs');
|
const isInChina = await isChinaDomain('sh.rustup.rs');
|
||||||
const rustInstallScriptForMac = isInChina && !isActions
|
const rustInstallScriptForMac =
|
||||||
? 'export RUSTUP_DIST_SERVER="https://rsproxy.cn" && export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup" && curl --proto "=https" --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh | sh'
|
isInChina && !isActions
|
||||||
: "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y";
|
? 'export RUSTUP_DIST_SERVER="https://rsproxy.cn" && export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup" && curl --proto "=https" --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh | sh'
|
||||||
|
: "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y";
|
||||||
const rustInstallScriptForWindows = 'winget install --id Rustlang.Rustup';
|
const rustInstallScriptForWindows = 'winget install --id Rustlang.Rustup';
|
||||||
|
|
||||||
const spinner = getSpinner('Downloading Rust...');
|
const spinner = getSpinner('Downloading Rust...');
|
||||||
|
|||||||
5
bin/options/index.ts
vendored
5
bin/options/index.ts
vendored
@@ -20,10 +20,7 @@ function isValidName(name: string, platform: NodeJS.Platform): boolean {
|
|||||||
return !!name && reg.test(name);
|
return !!name && reg.test(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function handleOptions(
|
export default async function handleOptions(options: PakeCliOptions, url: string): Promise<PakeAppOptions> {
|
||||||
options: PakeCliOptions,
|
|
||||||
url: string,
|
|
||||||
): Promise<PakeAppOptions> {
|
|
||||||
const { platform } = process;
|
const { platform } = process;
|
||||||
const isActions = process.env.GITHUB_ACTIONS;
|
const isActions = process.env.GITHUB_ACTIONS;
|
||||||
let name = options.name;
|
let name = options.name;
|
||||||
|
|||||||
2
bin/types.ts
vendored
2
bin/types.ts
vendored
@@ -42,7 +42,7 @@ export interface PakeCliOptions {
|
|||||||
// Tray icon, default same as app icon for Windows and Linux, macOS requires separate png or ico
|
// Tray icon, default same as app icon for Windows and Linux, macOS requires separate png or ico
|
||||||
systemTrayIcon: string;
|
systemTrayIcon: string;
|
||||||
|
|
||||||
// Recursive copy, when url is a local file path, if this option is enabled, the url path file and all its subfiles will be copied to the pake static file folder, default off
|
// Recursive copy, when url is a local file path, if this option is enabled, the url path file and all its subFiles will be copied to the pake static file folder, default off
|
||||||
useLocalFile: false;
|
useLocalFile: false;
|
||||||
|
|
||||||
// Multi arch, supports both Intel and M1 chips, only for Mac
|
// Multi arch, supports both Intel and M1 chips, only for Mac
|
||||||
|
|||||||
8
bin/utils/combine.ts
vendored
8
bin/utils/combine.ts
vendored
@@ -4,10 +4,14 @@ export default async function combineFiles(files: string[], output: string) {
|
|||||||
const contents = files.map(file => {
|
const contents = files.map(file => {
|
||||||
const fileContent = fs.readFileSync(file);
|
const fileContent = fs.readFileSync(file);
|
||||||
if (file.endsWith('.css')) {
|
if (file.endsWith('.css')) {
|
||||||
return "window.addEventListener('DOMContentLoaded', (_event) => { const css = `" + fileContent + "`; const style = document.createElement('style'); style.innerHTML = css; document.head.appendChild(style); });";
|
return (
|
||||||
|
"window.addEventListener('DOMContentLoaded', (_event) => { const css = `" +
|
||||||
|
fileContent +
|
||||||
|
"`; const style = document.createElement('style'); style.innerHTML = css; document.head.appendChild(style); });"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "window.addEventListener('DOMContentLoaded', (_event) => { " + fileContent + " });";
|
return "window.addEventListener('DOMContentLoaded', (_event) => { " + fileContent + ' });';
|
||||||
});
|
});
|
||||||
fs.writeFileSync(output, contents.join('\n'));
|
fs.writeFileSync(output, contents.join('\n'));
|
||||||
return files;
|
return files;
|
||||||
|
|||||||
5
bin/utils/dir.ts
vendored
5
bin/utils/dir.ts
vendored
@@ -7,4 +7,7 @@ const currentModulePath = fileURLToPath(import.meta.url);
|
|||||||
// Resolve the parent directory of the current module
|
// Resolve the parent directory of the current module
|
||||||
export const npmDirectory = path.join(path.dirname(currentModulePath), '..');
|
export const npmDirectory = path.join(path.dirname(currentModulePath), '..');
|
||||||
|
|
||||||
export const tauriConfigDirectory = process.env.NODE_ENV === 'development' ? path.join(npmDirectory, 'src-tauri', '.pake') : path.join(npmDirectory, 'src-tauri');
|
export const tauriConfigDirectory =
|
||||||
|
process.env.NODE_ENV === 'development'
|
||||||
|
? path.join(npmDirectory, 'src-tauri', '.pake')
|
||||||
|
: path.join(npmDirectory, 'src-tauri');
|
||||||
|
|||||||
6
script/app_config.mjs
vendored
6
script/app_config.mjs
vendored
@@ -86,7 +86,6 @@ switch (os.platform()) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
updateIconFile(platformVariables.iconPath, platformVariables.defaultIconPath);
|
updateIconFile(platformVariables.iconPath, platformVariables.defaultIconPath);
|
||||||
|
|
||||||
updatePlatformConfig(platformConfig, platformVariables);
|
updatePlatformConfig(platformConfig, platformVariables);
|
||||||
@@ -148,7 +147,6 @@ function updatePlatformConfig(platformConfig, platformVariables) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
|
|
||||||
writeFileSync(variables.pakeConfigPath, JSON.stringify(pakeJson, null, 2));
|
writeFileSync(variables.pakeConfigPath, JSON.stringify(pakeJson, null, 2));
|
||||||
writeFileSync(variables.tauriConfigPath, JSON.stringify(tauriJson, null, 2));
|
writeFileSync(variables.tauriConfigPath, JSON.stringify(tauriJson, null, 2));
|
||||||
|
|
||||||
@@ -158,13 +156,11 @@ function save() {
|
|||||||
writeFileSync(variables.macos.configFilePath, JSON.stringify(macosJson, null, 2));
|
writeFileSync(variables.macos.configFilePath, JSON.stringify(macosJson, null, 2));
|
||||||
|
|
||||||
writeFileSync(variables.windows.configFilePath, JSON.stringify(windowsJson, null, 2));
|
writeFileSync(variables.windows.configFilePath, JSON.stringify(windowsJson, null, 2));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateDesktopEntry() {
|
function updateDesktopEntry() {
|
||||||
linuxJson.tauri.bundle.deb.files = {};
|
linuxJson.tauri.bundle.deb.files = {};
|
||||||
linuxJson.tauri.bundle.deb.files[variables.linux.desktopEntryConfig.configKey] =
|
linuxJson.tauri.bundle.deb.files[variables.linux.desktopEntryConfig.configKey] = variables.linux.desktopEntryConfig.configValue;
|
||||||
variables.linux.desktopEntryConfig.configValue;
|
|
||||||
writeFileSync(variables.linux.desktopEntryPath, variables.linux.desktopEntry);
|
writeFileSync(variables.linux.desktopEntryPath, variables.linux.desktopEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
5
src-tauri/src/inject/component.js
vendored
5
src-tauri/src/inject/component.js
vendored
@@ -6,16 +6,15 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
m.style.cssText =
|
m.style.cssText =
|
||||||
'max-width:60%;min-width: 80px;padding:0 12px;height: 32px;color: rgb(255, 255, 255);line-height: 32px;text-align: center;border-radius: 8px;position: fixed; bottom:24px;right: 28px;z-index: 999999;background: rgba(0, 0, 0,.8);font-size: 13px;';
|
'max-width:60%;min-width: 80px;padding:0 12px;height: 32px;color: rgb(255, 255, 255);line-height: 32px;text-align: center;border-radius: 8px;position: fixed; bottom:24px;right: 28px;z-index: 999999;background: rgba(0, 0, 0,.8);font-size: 13px;';
|
||||||
document.body.appendChild(m);
|
document.body.appendChild(m);
|
||||||
setTimeout(function() {
|
setTimeout(function () {
|
||||||
const d = 0.5;
|
const d = 0.5;
|
||||||
m.style.transition = 'transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
|
m.style.transition = 'transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
|
||||||
m.style.opacity = '0';
|
m.style.opacity = '0';
|
||||||
setTimeout(function() {
|
setTimeout(function () {
|
||||||
document.body.removeChild(m);
|
document.body.removeChild(m);
|
||||||
}, d * 1000);
|
}, d * 1000);
|
||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.pakeToast = pakeToast;
|
window.pakeToast = pakeToast;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
78
src-tauri/src/inject/event.js
vendored
78
src-tauri/src/inject/event.js
vendored
@@ -1,13 +1,13 @@
|
|||||||
const shortcuts = {
|
const shortcuts = {
|
||||||
'ArrowUp': () => scrollTo(0, 0),
|
|
||||||
'ArrowDown': () => scrollTo(0, document.body.scrollHeight),
|
|
||||||
'[': () => window.history.back(),
|
'[': () => window.history.back(),
|
||||||
']': () => window.history.forward(),
|
']': () => window.history.forward(),
|
||||||
'r': () => window.location.reload(),
|
|
||||||
'-': () => zoomOut(),
|
'-': () => zoomOut(),
|
||||||
'=': () => zoomIn(),
|
'=': () => zoomIn(),
|
||||||
'+': () => zoomIn(),
|
'+': () => zoomIn(),
|
||||||
'0': () => setZoom('100%'),
|
0: () => setZoom('100%'),
|
||||||
|
r: () => window.location.reload(),
|
||||||
|
ArrowUp: () => scrollTo(0, 0),
|
||||||
|
ArrowDown: () => scrollTo(0, document.body.scrollHeight),
|
||||||
};
|
};
|
||||||
|
|
||||||
function setZoom(zoom) {
|
function setZoom(zoom) {
|
||||||
@@ -22,11 +22,11 @@ function zoomCommon(zoomChange) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function zoomIn() {
|
function zoomIn() {
|
||||||
zoomCommon((currentZoom) => `${Math.min(parseInt(currentZoom) + 10, 200)}%`);
|
zoomCommon(currentZoom => `${Math.min(parseInt(currentZoom) + 10, 200)}%`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function zoomOut() {
|
function zoomOut() {
|
||||||
zoomCommon((currentZoom) => `${Math.max(parseInt(currentZoom) - 10, 30)}%`);
|
zoomCommon(currentZoom => `${Math.max(parseInt(currentZoom) - 10, 30)}%`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleShortcut(event) {
|
function handleShortcut(event) {
|
||||||
@@ -75,7 +75,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
appWindow.startDragging().then();
|
appWindow.startDragging().then();
|
||||||
});
|
});
|
||||||
|
|
||||||
domEl.addEventListener('mousedown', (e) => {
|
domEl.addEventListener('mousedown', e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (e.buttons === 1 && e.detail !== 2) {
|
if (e.buttons === 1 && e.detail !== 2) {
|
||||||
appWindow.startDragging().then();
|
appWindow.startDragging().then();
|
||||||
@@ -83,13 +83,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
domEl.addEventListener('dblclick', () => {
|
domEl.addEventListener('dblclick', () => {
|
||||||
appWindow.isFullscreen().then((fullscreen) => {
|
appWindow.isFullscreen().then(fullscreen => {
|
||||||
appWindow.setFullscreen(!fullscreen).then();
|
appWindow.setFullscreen(!fullscreen).then();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (window['pakeConfig']?.disabled_web_shortcuts !== true) {
|
if (window['pakeConfig']?.disabled_web_shortcuts !== true) {
|
||||||
document.addEventListener('keyup', (event) => {
|
document.addEventListener('keyup', event => {
|
||||||
if (/windows|linux/i.test(navigator.userAgent) && event.ctrlKey) {
|
if (/windows|linux/i.test(navigator.userAgent) && event.ctrlKey) {
|
||||||
handleShortcut(event);
|
handleShortcut(event);
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
function collectUrlToBlobs() {
|
function collectUrlToBlobs() {
|
||||||
const backupCreateObjectURL = window.URL.createObjectURL;
|
const backupCreateObjectURL = window.URL.createObjectURL;
|
||||||
window.blobToUrlCaches = new Map();
|
window.blobToUrlCaches = new Map();
|
||||||
window.URL.createObjectURL = (blob) => {
|
window.URL.createObjectURL = blob => {
|
||||||
const url = backupCreateObjectURL.call(window.URL, blob);
|
const url = backupCreateObjectURL.call(window.URL, blob);
|
||||||
window.blobToUrlCaches.set(url, blob);
|
window.blobToUrlCaches.set(url, blob);
|
||||||
return url;
|
return url;
|
||||||
@@ -111,7 +111,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function convertBlobUrlToBinary(blobUrl) {
|
function convertBlobUrlToBinary(blobUrl) {
|
||||||
return new Promise((resolve) => {
|
return new Promise(resolve => {
|
||||||
const blob = window.blobToUrlCaches.get(blobUrl);
|
const blob = window.blobToUrlCaches.get(blobUrl);
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
|
|
||||||
@@ -145,7 +145,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function downloadFromBlobUrl(blobUrl, filename) {
|
function downloadFromBlobUrl(blobUrl, filename) {
|
||||||
convertBlobUrlToBinary(blobUrl).then((binary) => {
|
convertBlobUrlToBinary(blobUrl).then(binary => {
|
||||||
invoke('download_file_by_binary', {
|
invoke('download_file_by_binary', {
|
||||||
params: {
|
params: {
|
||||||
filename,
|
filename,
|
||||||
@@ -155,37 +155,40 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// detect blob download by createElement("a")
|
// detect blob download by createElement("a")
|
||||||
function detectDownloadByCreateAnchor() {
|
function detectDownloadByCreateAnchor() {
|
||||||
const createEle = document.createElement;
|
const createEle = document.createElement;
|
||||||
document.createElement = (el) => {
|
document.createElement = el => {
|
||||||
if (el !== 'a') return createEle.call(document, el);
|
if (el !== 'a') return createEle.call(document, el);
|
||||||
const anchorEle = createEle.call(document, el);
|
const anchorEle = createEle.call(document, el);
|
||||||
|
|
||||||
// use addEventListener to avoid overriding the original click event.
|
// use addEventListener to avoid overriding the original click event.
|
||||||
anchorEle.addEventListener('click', (e) => {
|
anchorEle.addEventListener(
|
||||||
const url = anchorEle.href;
|
'click',
|
||||||
const filename = anchorEle.download || getFilenameFromUrl(url);
|
e => {
|
||||||
if (window.blobToUrlCaches.has(url)) {
|
const url = anchorEle.href;
|
||||||
downloadFromBlobUrl(url, filename);
|
const filename = anchorEle.download || getFilenameFromUrl(url);
|
||||||
// case: download from dataURL -> convert dataURL ->
|
if (window.blobToUrlCaches.has(url)) {
|
||||||
} else if (url.startsWith('data:')) {
|
downloadFromBlobUrl(url, filename);
|
||||||
downloadFromDataUri(url, filename);
|
// case: download from dataURL -> convert dataURL ->
|
||||||
} else if (isDownloadLink(url) || anchorEle.hostname !== window.location.host) {
|
} else if (url.startsWith('data:')) {
|
||||||
handleExternalLink(e, url);
|
downloadFromDataUri(url, filename);
|
||||||
}
|
} else if (isDownloadLink(url) || anchorEle.hostname !== window.location.host) {
|
||||||
}, true);
|
handleExternalLink(e, url);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
return anchorEle;
|
return anchorEle;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const isExternalLink = (link) => window.location.host !== link.host;
|
const isExternalLink = link => window.location.host !== link.host;
|
||||||
// process special download protocol['data:','blob:']
|
// process special download protocol['data:','blob:']
|
||||||
const isSpecialDownload = (url) => ['blob', 'data'].some(protocol => url.startsWith(protocol));
|
const isSpecialDownload = url => ['blob', 'data'].some(protocol => url.startsWith(protocol));
|
||||||
|
|
||||||
const isDownloadRequired = (url, anchorElement, e) =>
|
const isDownloadRequired = (url, anchorElement, e) => anchorElement.download || e.metaKey || e.ctrlKey || isDownloadLink(url);
|
||||||
anchorElement.download || e.metaKey || e.ctrlKey || isDownloadLink(url);
|
|
||||||
|
|
||||||
const handleExternalLink = (e, url) => {
|
const handleExternalLink = (e, url) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -197,7 +200,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
invoke('download_file', { params: { url, filename } });
|
invoke('download_file', { params: { url, filename } });
|
||||||
};
|
};
|
||||||
|
|
||||||
const detectAnchorElementClick = (e) => {
|
const detectAnchorElementClick = e => {
|
||||||
const anchorElement = e.target.closest('a');
|
const anchorElement = e.target.closest('a');
|
||||||
if (anchorElement && anchorElement.href) {
|
if (anchorElement && anchorElement.href) {
|
||||||
anchorElement.target = '_self';
|
anchorElement.target = '_self';
|
||||||
@@ -226,7 +229,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
// Rewrite the window.open function.
|
// Rewrite the window.open function.
|
||||||
const originalWindowOpen = window.open;
|
const originalWindowOpen = window.open;
|
||||||
window.open = function(url, name, specs) {
|
window.open = function (url, name, specs) {
|
||||||
// Apple login and google login
|
// Apple login and google login
|
||||||
if (name === 'AppleAuthentication') {
|
if (name === 'AppleAuthentication') {
|
||||||
//do nothing
|
//do nothing
|
||||||
@@ -249,10 +252,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fix Chinese input method "Enter" on Safari
|
// Fix Chinese input method "Enter" on Safari
|
||||||
document.addEventListener('keydown', (e) => {
|
document.addEventListener(
|
||||||
if (e.keyCode === 229) e.stopPropagation();
|
'keydown',
|
||||||
}, true);
|
e => {
|
||||||
|
if (e.keyCode === 229) e.stopPropagation();
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
function setDefaultZoom() {
|
function setDefaultZoom() {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"copyright": "",
|
"copyright": "",
|
||||||
"deb": {
|
"deb": {
|
||||||
"depends": ["curl", "wget"],
|
"depends": ["curl", "wget"],
|
||||||
"files": {"/usr/share/applications/com-pake-weread.desktop": "assets/com-pake-weread.desktop"}
|
"files": { "/usr/share/applications/com-pake-weread.desktop": "assets/com-pake-weread.desktop" }
|
||||||
},
|
},
|
||||||
"externalBin": [],
|
"externalBin": [],
|
||||||
"longDescription": "",
|
"longDescription": "",
|
||||||
|
|||||||
Reference in New Issue
Block a user