Skip to content

Commit

Permalink
🎨 Format Optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
tw93 committed May 10, 2024
1 parent eabdfc2 commit 0e1e57d
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 78 deletions.
11 changes: 5 additions & 6 deletions bin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Ensure that your Node.js version is 18.0 or higher (e.g., 18.20.2). Avoid using `sudo` for the installation. If you encounter permission issues with npm, refer to [How to fix npm throwing error without sudo](https://stackoverflow.com/questions/16151018/how-to-fix-npm-throwing-error-without-sudo).

```bash
npm install pake-cli -g
npm install pake-cli -g
```

## Considerations for Windows & Linux Users
Expand Down Expand Up @@ -40,14 +40,15 @@ npm install pake-cli -g
## Usage

### Development

The `DEFAULT_DEV_PAKE_OPTIONS` configuration in `bin/defaults.ts` can be modified at development time to match the `pake-cli` configuration description.

```typescript
export const DEFAULT_DEV_PAKE_OPTIONS: PakeCliOptions & {url: string} = {
export const DEFAULT_DEV_PAKE_OPTIONS: PakeCliOptions & { url: string } = {
...DEFAULT_PAKE_OPTIONS,
url: 'https://weread.qq.com',
name: 'Weread',
}
};
```
then
Expand Down Expand Up @@ -129,7 +130,6 @@ screen.
--fullscreen
```

#### [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).
Expand Down Expand Up @@ -221,7 +221,7 @@ Enable recursive copying. When the URL is a local file path, enabling this optio
#### [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
--inject ./tools/style.css,./tools/hotkey.js
Expand All @@ -248,4 +248,3 @@ The typed package has dev-tools for debugging, in addition to outputting more lo
## 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.
6 changes: 3 additions & 3 deletions bin/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
请确保您的 Node.js 版本为 18 或更高版本(例如 18.7)。请避免使用 `sudo` 进行安装。如果 npm 报告权限问题,请参考 [如何在不使用 sudo 的情况下修复 npm 报错](https://stackoverflow.com/questions/16151018/how-to-fix-npm-throwing-error-without-sudo)

```bash
npm install pake-cli -g
npm install pake-cli -g
```

## Windows/Linux 注意事项
Expand Down Expand Up @@ -44,11 +44,11 @@ npm install pake-cli -g
开发时可以修改 `bin/defaults.ts``DEFAULT_DEV_PAKE_OPTIONS` 配置,配置项和 `pake-cli` 配置说明保持一致

```typescript
export const DEFAULT_DEV_PAKE_OPTIONS: PakeCliOptions & {url: string} = {
export const DEFAULT_DEV_PAKE_OPTIONS: PakeCliOptions & { url: string } = {
...DEFAULT_PAKE_OPTIONS,
url: 'https://weread.qq.com',
name: 'Weread',
}
};
```
之后运行
Expand Down
25 changes: 17 additions & 8 deletions bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ ${green('| __/ (_| | < __/')} ${yellow('https://github.com/tw93/pake')}
${green('|_| \\__,_|_|\\_\\___| can turn any webpage into a desktop app with Rust.')}
`;

program
.addHelpText('beforeAll', logo)
.usage(`[url] [options]`)
.showHelpAfterError();
program.addHelpText('beforeAll', logo).usage(`[url] [options]`).showHelpAfterError();

program
.argument('[url]', 'The web URL you want to package', validateUrlInput)
Expand All @@ -37,12 +34,24 @@ program
.option('--inject [injects...]', 'Injection of .js or .css Files', DEFAULT.inject)
.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('--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('--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('--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('--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')
.action(async (url: string, options: PakeCliOptions) => {
await checkUpdateTips();
Expand Down
4 changes: 2 additions & 2 deletions bin/dev.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import log from 'loglevel';
import {DEFAULT_DEV_PAKE_OPTIONS} from './defaults';
import { DEFAULT_DEV_PAKE_OPTIONS } from './defaults';
import handleInputOptions from './options/index';
import BuilderProvider from './builders/BuilderProvider';

Expand All @@ -14,4 +14,4 @@ async function startBuild() {
await builder.start(DEFAULT_DEV_PAKE_OPTIONS.url);
}

startBuild();
startBuild();
2 changes: 1 addition & 1 deletion bin/helpers/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
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;
await combineFiles(files, injectFilePath);
} else {
Expand Down
7 changes: 4 additions & 3 deletions bin/helpers/rust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { isChinaDomain } from '@/utils/ip';
export async function installRust() {
const isActions = process.env.GITHUB_ACTIONS;
const isInChina = await isChinaDomain('sh.rustup.rs');
const rustInstallScriptForMac = isInChina && !isActions
? '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 rustInstallScriptForMac =
isInChina && !isActions
? '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 spinner = getSpinner('Downloading Rust...');
Expand Down
5 changes: 1 addition & 4 deletions bin/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ function isValidName(name: string, platform: NodeJS.Platform): boolean {
return !!name && reg.test(name);
}

export default async function handleOptions(
options: PakeCliOptions,
url: string,
): Promise<PakeAppOptions> {
export default async function handleOptions(options: PakeCliOptions, url: string): Promise<PakeAppOptions> {
const { platform } = process;
const isActions = process.env.GITHUB_ACTIONS;
let name = options.name;
Expand Down
2 changes: 1 addition & 1 deletion bin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface PakeCliOptions {
// Tray icon, default same as app icon for Windows and Linux, macOS requires separate png or ico
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;

// Multi arch, supports both Intel and M1 chips, only for Mac
Expand Down
12 changes: 8 additions & 4 deletions bin/utils/combine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ export default async function combineFiles(files: string[], output: string) {
const contents = files.map(file => {
const fileContent = fs.readFileSync(file);
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'));
return files;
}
}
5 changes: 4 additions & 1 deletion bin/utils/dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ const currentModulePath = fileURLToPath(import.meta.url);
// Resolve the parent directory of the current module
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 changes: 1 addition & 5 deletions script/app_config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ switch (os.platform()) {
break;
}


updateIconFile(platformVariables.iconPath, platformVariables.defaultIconPath);

updatePlatformConfig(platformConfig, platformVariables);
Expand Down Expand Up @@ -148,7 +147,6 @@ function updatePlatformConfig(platformConfig, platformVariables) {
}

function save() {

writeFileSync(variables.pakeConfigPath, JSON.stringify(pakeJson, null, 2));
writeFileSync(variables.tauriConfigPath, JSON.stringify(tauriJson, null, 2));

Expand All @@ -158,13 +156,11 @@ function save() {
writeFileSync(variables.macos.configFilePath, JSON.stringify(macosJson, null, 2));

writeFileSync(variables.windows.configFilePath, JSON.stringify(windowsJson, null, 2));

}

function updateDesktopEntry() {
linuxJson.tauri.bundle.deb.files = {};
linuxJson.tauri.bundle.deb.files[variables.linux.desktopEntryConfig.configKey] =
variables.linux.desktopEntryConfig.configValue;
linuxJson.tauri.bundle.deb.files[variables.linux.desktopEntryConfig.configKey] = variables.linux.desktopEntryConfig.configValue;
writeFileSync(variables.linux.desktopEntryPath, variables.linux.desktopEntry);
}

Expand Down
5 changes: 2 additions & 3 deletions src-tauri/src/inject/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ document.addEventListener('DOMContentLoaded', () => {
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;';
document.body.appendChild(m);
setTimeout(function() {
setTimeout(function () {
const d = 0.5;
m.style.transition = 'transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
m.style.opacity = '0';
setTimeout(function() {
setTimeout(function () {
document.body.removeChild(m);
}, d * 1000);
}, 3000);
}

window.pakeToast = pakeToast;

});
Loading

0 comments on commit 0e1e57d

Please sign in to comment.