feat(cli): 不同平台默认icon处理

This commit is contained in:
volare
2022-12-10 23:36:23 +08:00
parent 6dfa8e7a2f
commit a43b01d67a
5 changed files with 31 additions and 21 deletions

2
bin/README_EN.md vendored
View File

@@ -34,7 +34,7 @@ The application name, if not specified when entering, will prompt you to enter,
#### [icon]
应用 icon支持本地/远程文件,默认为 Pake 自带图标。
The application icon, support local and remote files. The default is brand icon of Pake.
- MacOS must be `.icns`
- Windows must be `.ico`

View File

@@ -6,7 +6,6 @@ import LinuxBuilder from './LinuxBuilder.js';
export default class BuilderFactory {
static create(): IBuilder {
console.log("now platform is ", process.platform);
if (IS_MAC) {
return new MacBuilder();
}

17
bin/options/icon.ts vendored
View File

@@ -4,8 +4,9 @@ import { PakeAppOptions } from '../types.js';
import { dir } from 'tmp-promise';
import path from 'path';
import fs from 'fs/promises';
import { fileURLToPath } from 'url';
import logger from './logger.js';
import { npmDirectory } from '@/utils/dir.js';
import { IS_LINUX, IS_WIN } from '@/utils/platform.js';
export async function handleIcon(options: PakeAppOptions, url: string) {
if (options.icon) {
@@ -16,14 +17,20 @@ export async function handleIcon(options: PakeAppOptions, url: string) {
}
}
if (!options.icon) {
return inferIcon(options.name, url);
return getDefaultIcon();
}
}
export async function inferIcon(name: string, url: string) {
export async function getDefaultIcon() {
logger.info('You have not provided an app icon, use the default icon.(use --icon option to assign an icon)')
const npmDirectory = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
return path.join(npmDirectory, 'pake-default.icns');
let iconPath = 'src-tauri/icons/icon.icns';
if (IS_WIN) {
iconPath = 'src-tauri/png/icon_256.ico';
} else if (IS_LINUX) {
iconPath = 'src-tauri/png/icon_512.png';
}
return path.join(npmDirectory, iconPath);
}
// export async function getIconFromPageUrl(url: string) {