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) {

29
dist/cli.js vendored
View File

@@ -1678,6 +1678,10 @@ const logger = {
}
};
const IS_MAC = process.platform === 'darwin';
const IS_WIN = process.platform === 'win32';
const IS_LINUX = process.platform === 'linux';
function handleIcon(options, url) {
return __awaiter(this, void 0, void 0, function* () {
if (options.icon) {
@@ -1689,15 +1693,21 @@ function handleIcon(options, url) {
}
}
if (!options.icon) {
return inferIcon(options.name);
return getDefaultIcon();
}
});
}
function inferIcon(name, url) {
function getDefaultIcon() {
return __awaiter(this, void 0, void 0, function* () {
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) {
@@ -1773,10 +1783,6 @@ function handleOptions(options, url) {
});
}
const IS_MAC = process.platform === 'darwin';
const IS_WIN = process.platform === 'win32';
const IS_LINUX = process.platform === 'linux';
function shellExec(command) {
return new Promise((resolve, reject) => {
shelljs.exec(command, { async: true, silent: false }, (code) => {
@@ -1943,7 +1949,8 @@ var tauri = {
],
shortDescription: "",
targets: [
"deb"
"deb",
"appimage"
]
}
};
@@ -2130,7 +2137,6 @@ Type=Application
class BuilderFactory {
static create() {
console.log("now platform is ", process.platform);
if (IS_MAC) {
return new MacBuilder();
}
@@ -2161,8 +2167,7 @@ var author = {
var files = [
"dist",
"src-tauri",
"cli.js",
"pake-default.icns"
"cli.js"
];
var scripts = {
start: "npm run dev",

View File

@@ -16,8 +16,7 @@
"files": [
"dist",
"src-tauri",
"cli.js",
"pake-default.icns"
"cli.js"
],
"scripts": {
"start": "npm run dev",