refactor: pake-cli support tauri 2.x beta
This commit is contained in:
2
bin/builders/LinuxBuilder.ts
vendored
2
bin/builders/LinuxBuilder.ts
vendored
@@ -10,7 +10,7 @@ export default class LinuxBuilder extends BaseBuilder {
|
||||
getFileName(): string {
|
||||
const { name } = this.options;
|
||||
const arch = process.arch === 'x64' ? 'amd64' : process.arch;
|
||||
return `${name}_${tauriConfig.package.version}_${arch}`;
|
||||
return `${name}_${tauriConfig.version}_${arch}`;
|
||||
}
|
||||
|
||||
// Customize it, considering that there are all targets.
|
||||
|
||||
2
bin/builders/MacBuilder.ts
vendored
2
bin/builders/MacBuilder.ts
vendored
@@ -16,7 +16,7 @@ export default class MacBuilder extends BaseBuilder {
|
||||
} else {
|
||||
arch = process.arch === 'arm64' ? 'aarch64' : process.arch;
|
||||
}
|
||||
return `${name}_${tauriConfig.package.version}_${arch}`;
|
||||
return `${name}_${tauriConfig.version}_${arch}`;
|
||||
}
|
||||
|
||||
protected getBuildCommand(): string {
|
||||
|
||||
4
bin/builders/WinBuilder.ts
vendored
4
bin/builders/WinBuilder.ts
vendored
@@ -11,7 +11,7 @@ export default class WinBuilder extends BaseBuilder {
|
||||
getFileName(): string {
|
||||
const { name } = this.options;
|
||||
const { arch } = process;
|
||||
const language = tauriConfig.tauri.bundle.windows.wix.language[0];
|
||||
return `${name}_${tauriConfig.package.version}_${arch}_${language}`;
|
||||
const language = tauriConfig.bundle.windows.wix.language[0];
|
||||
return `${name}_${tauriConfig.version}_${arch}_${language}`;
|
||||
}
|
||||
}
|
||||
|
||||
7
bin/defaults.ts
vendored
7
bin/defaults.ts
vendored
@@ -11,7 +11,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
|
||||
disabledWebShortcuts: false,
|
||||
activationShortcut: '',
|
||||
userAgent: '',
|
||||
showSystemTray: false,
|
||||
showSystemTray: true,
|
||||
multiArch: false,
|
||||
targets: 'deb',
|
||||
useLocalFile: false,
|
||||
@@ -24,8 +24,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
|
||||
// Just for cli development
|
||||
export const DEFAULT_DEV_PAKE_OPTIONS: PakeCliOptions & { url: string } = {
|
||||
...DEFAULT_PAKE_OPTIONS,
|
||||
url: 'https://weread.qq.com',
|
||||
name: 'WeRead',
|
||||
safeDomain: ['weread.qq.com'],
|
||||
url: 'https://www.xiaoyuzhoufm.com/',
|
||||
name: 'XiaoYuZhou',
|
||||
hideTitleBar: true,
|
||||
};
|
||||
|
||||
52
bin/helpers/merge.ts
vendored
52
bin/helpers/merge.ts
vendored
@@ -24,7 +24,6 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
|
||||
name,
|
||||
resizable = true,
|
||||
inject,
|
||||
safeDomain,
|
||||
} = options;
|
||||
|
||||
const { platform } = process;
|
||||
@@ -42,8 +41,8 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
|
||||
};
|
||||
Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions });
|
||||
|
||||
tauriConf.package.productName = name;
|
||||
tauriConf.tauri.bundle.identifier = identifier;
|
||||
tauriConf.productName = name;
|
||||
tauriConf.identifier = identifier;
|
||||
|
||||
//Judge the type of URL, whether it is a file or a website.
|
||||
const pathExists = await fsExtra.pathExists(url);
|
||||
@@ -76,25 +75,6 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
|
||||
tauriConf.pake.windows[0].url_type = 'local';
|
||||
} else {
|
||||
tauriConf.pake.windows[0].url_type = 'web';
|
||||
// Set the secure domain for calling window.__TAURI__ to the application domain that has been set.
|
||||
tauriConf.tauri.security.dangerousRemoteDomainIpcAccess = [
|
||||
{
|
||||
domain: new URL(url).hostname,
|
||||
windows: ['pake'],
|
||||
enableTauriAPI: true,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (safeDomain.length > 0) {
|
||||
tauriConf.tauri.security.dangerousRemoteDomainIpcAccess = [
|
||||
...tauriConf.tauri.security.dangerousRemoteDomainIpcAccess,
|
||||
...safeDomain.map(domain => ({
|
||||
domain,
|
||||
windows: ['pake'],
|
||||
enableTauriAPI: true,
|
||||
})),
|
||||
];
|
||||
}
|
||||
|
||||
const platformMap: PlatformMap = {
|
||||
@@ -112,10 +92,10 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
|
||||
|
||||
// Processing targets are currently only open to Linux.
|
||||
if (platform === 'linux') {
|
||||
delete tauriConf.tauri.bundle.deb.files;
|
||||
delete tauriConf.bundle.linux.deb.files;
|
||||
const validTargets = ['all', 'deb', 'appimage'];
|
||||
if (validTargets.includes(options.targets)) {
|
||||
tauriConf.tauri.bundle.targets = options.targets === 'all' ? ['deb', 'appimage'] : [options.targets];
|
||||
tauriConf.bundle.targets = options.targets === 'all' ? ['deb', 'appimage'] : [options.targets];
|
||||
} else {
|
||||
logger.warn(`✼ The target must be one of ${validTargets.join(', ')}, the default 'deb' will be used.`);
|
||||
}
|
||||
@@ -151,25 +131,25 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
|
||||
if (customIconExt !== iconInfo.fileExt) {
|
||||
updateIconPath = false;
|
||||
logger.warn(`✼ ${iconInfo.message}, but you give ${customIconExt}`);
|
||||
tauriConf.tauri.bundle.icon = [iconInfo.defaultIcon];
|
||||
tauriConf.bundle.icon = [iconInfo.defaultIcon];
|
||||
} else {
|
||||
const iconPath = path.join(npmDirectory, 'src-tauri/', iconInfo.path);
|
||||
tauriConf.tauri.bundle.resources = [iconInfo.path];
|
||||
tauriConf.bundle.resources = [iconInfo.path];
|
||||
await fsExtra.copy(options.icon, iconPath);
|
||||
}
|
||||
|
||||
if (updateIconPath) {
|
||||
tauriConf.tauri.bundle.icon = [options.icon];
|
||||
tauriConf.bundle.icon = [options.icon];
|
||||
} else {
|
||||
logger.warn(`✼ Icon will remain as default.`);
|
||||
}
|
||||
} else {
|
||||
logger.warn('✼ Custom icon path may be invalid, default icon will be used instead.');
|
||||
tauriConf.tauri.bundle.icon = [iconInfo.defaultIcon];
|
||||
tauriConf.bundle.icon = [iconInfo.defaultIcon];
|
||||
}
|
||||
|
||||
// Set tray icon path.
|
||||
let trayIconPath = platform === 'darwin' ? 'png/icon_512.png' : tauriConf.tauri.bundle.icon[0];
|
||||
let trayIconPath = platform === 'darwin' ? 'png/icon_512.png' : tauriConf.bundle.icon[0];
|
||||
if (systemTrayIcon.length > 0) {
|
||||
try {
|
||||
await fsExtra.pathExists(systemTrayIcon);
|
||||
@@ -189,7 +169,11 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
|
||||
}
|
||||
}
|
||||
|
||||
tauriConf.tauri.systemTray.iconPath = trayIconPath;
|
||||
tauriConf.app.trayIcon.iconPath = trayIconPath;
|
||||
tauriConf.pake.system_tray_path = trayIconPath;
|
||||
|
||||
delete tauriConf.app.trayIcon;
|
||||
|
||||
const injectFilePath = path.join(npmDirectory, `src-tauri/src/inject/custom.js`);
|
||||
// inject js or css files
|
||||
if (inject?.length > 0) {
|
||||
@@ -213,17 +197,19 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon
|
||||
};
|
||||
const configPath = path.join(tauriConfigDirectory, platformConfigPaths[platform]);
|
||||
|
||||
const bundleConf = { tauri: { bundle: tauriConf.tauri.bundle } };
|
||||
const bundleConf = { bundle: tauriConf.bundle };
|
||||
console.log('pakeConfig', tauriConf.pake);
|
||||
await fsExtra.outputJSON(configPath, bundleConf, { spaces: 4 });
|
||||
const pakeConfigPath = path.join(tauriConfigDirectory, 'pake.json');
|
||||
await fsExtra.outputJSON(pakeConfigPath, tauriConf.pake, { spaces: 4 });
|
||||
|
||||
let tauriConf2 = JSON.parse(JSON.stringify(tauriConf));
|
||||
delete tauriConf2.pake;
|
||||
delete tauriConf2.tauri.bundle;
|
||||
// delete tauriConf2.bundle;
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
tauriConf2.tauri.bundle = bundleConf.tauri.bundle;
|
||||
tauriConf2.bundle = bundleConf.bundle;
|
||||
}
|
||||
console.log('tauriConf', tauriConf2)
|
||||
const configJsonPath = path.join(tauriConfigDirectory, 'tauri.conf.json');
|
||||
await fsExtra.outputJSON(configJsonPath, tauriConf2, { spaces: 4 });
|
||||
}
|
||||
|
||||
12
bin/helpers/tauriConfig.ts
vendored
12
bin/helpers/tauriConfig.ts
vendored
@@ -15,11 +15,15 @@ const { platform } = process;
|
||||
const platformConfig = platformConfigs[platform];
|
||||
|
||||
let tauriConfig = {
|
||||
tauri: {
|
||||
...CommonConf.tauri,
|
||||
bundle: platformConfig.tauri.bundle,
|
||||
...CommonConf,
|
||||
bundle: platformConfig.bundle,
|
||||
app: {
|
||||
...CommonConf.app,
|
||||
trayIcon: {
|
||||
...CommonConf.app.trayIcon,
|
||||
...(platformConfig?.app?.trayIcon ?? {}),
|
||||
},
|
||||
},
|
||||
package: CommonConf.package,
|
||||
build: CommonConf.build,
|
||||
pake: pakeConf,
|
||||
};
|
||||
|
||||
283
dist/cli.js
vendored
283
dist/cli.js
vendored
@@ -20,7 +20,7 @@ import psl from 'psl';
|
||||
import isUrl from 'is-url';
|
||||
|
||||
var name = "pake-cli";
|
||||
var version = "2.5.2";
|
||||
var version$1 = "2.5.2";
|
||||
var description = "🤱🏻 Turn any webpage into a desktop app with Rust. 🤱🏻 利用 Rust 轻松构建轻量级多端桌面应用。";
|
||||
var engines = {
|
||||
node: ">=16.0.0"
|
||||
@@ -68,7 +68,7 @@ var exports = "./dist/pake.js";
|
||||
var license = "MIT";
|
||||
var dependencies = {
|
||||
"@tauri-apps/api": "^1.5.4",
|
||||
"@tauri-apps/cli": "^1.5.13",
|
||||
"@tauri-apps/cli": "^2.0.0-beta.22",
|
||||
axios: "^1.6.8",
|
||||
chalk: "^5.3.0",
|
||||
commander: "^11.1.0",
|
||||
@@ -107,7 +107,7 @@ var devDependencies = {
|
||||
};
|
||||
var packageJson = {
|
||||
name: name,
|
||||
version: version,
|
||||
version: version$1,
|
||||
description: description,
|
||||
engines: engines,
|
||||
bin: bin,
|
||||
@@ -156,130 +156,109 @@ var pakeConf = {
|
||||
inject: inject
|
||||
};
|
||||
|
||||
var tauri$3 = {
|
||||
var build = {
|
||||
beforeBuildCommand: "",
|
||||
frontendDist: "../dist",
|
||||
beforeDevCommand: ""
|
||||
};
|
||||
var plugins = {
|
||||
};
|
||||
var productName = "WeRead";
|
||||
var version = "1.0.0";
|
||||
var app = {
|
||||
security: {
|
||||
csp: null,
|
||||
dangerousRemoteDomainIpcAccess: [
|
||||
{
|
||||
domain: "weread.qq.com",
|
||||
windows: [
|
||||
"pake"
|
||||
],
|
||||
enableTauriAPI: true
|
||||
}
|
||||
]
|
||||
csp: null
|
||||
},
|
||||
updater: {
|
||||
active: false
|
||||
},
|
||||
systemTray: {
|
||||
trayIcon: {
|
||||
iconPath: "png/icon_512.png",
|
||||
iconAsTemplate: false
|
||||
},
|
||||
allowlist: {
|
||||
all: true,
|
||||
fs: {
|
||||
all: true,
|
||||
scope: [
|
||||
"$DOWNLOAD/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
var build = {
|
||||
withGlobalTauri: true,
|
||||
devPath: "../dist",
|
||||
distDir: "../dist",
|
||||
beforeBuildCommand: "",
|
||||
beforeDevCommand: ""
|
||||
withGlobalTauri: true
|
||||
};
|
||||
var CommonConf = {
|
||||
"package": {
|
||||
productName: "WeRead",
|
||||
version: "1.0.0"
|
||||
},
|
||||
tauri: tauri$3,
|
||||
build: build
|
||||
build: build,
|
||||
plugins: plugins,
|
||||
productName: productName,
|
||||
version: version,
|
||||
app: app
|
||||
};
|
||||
|
||||
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 identifier$2 = "com.pake.weread";
|
||||
var bundle$2 = {
|
||||
icon: [
|
||||
"png/weread_256.ico",
|
||||
"png/weread_32.ico"
|
||||
],
|
||||
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
|
||||
identifier: identifier$2,
|
||||
bundle: bundle$2
|
||||
};
|
||||
|
||||
var tauri$1 = {
|
||||
bundle: {
|
||||
icon: [
|
||||
"icons/weread.icns"
|
||||
var identifier$1 = "com.pake.weread";
|
||||
var bundle$1 = {
|
||||
icon: [
|
||||
"icons/weread.icns"
|
||||
],
|
||||
active: true,
|
||||
category: "DeveloperTool",
|
||||
copyright: "",
|
||||
externalBin: [
|
||||
],
|
||||
longDescription: "",
|
||||
macOS: {
|
||||
entitlements: null,
|
||||
exceptionDomain: null,
|
||||
frameworks: [
|
||||
],
|
||||
identifier: "com.pake.weread",
|
||||
active: true,
|
||||
category: "DeveloperTool",
|
||||
copyright: "",
|
||||
externalBin: [
|
||||
],
|
||||
longDescription: "",
|
||||
macOS: {
|
||||
entitlements: null,
|
||||
exceptionDomain: "",
|
||||
frameworks: [
|
||||
],
|
||||
providerShortName: null,
|
||||
signingIdentity: null
|
||||
},
|
||||
resources: [
|
||||
],
|
||||
shortDescription: "",
|
||||
targets: [
|
||||
"dmg"
|
||||
]
|
||||
}
|
||||
providerShortName: null,
|
||||
signingIdentity: null
|
||||
},
|
||||
resources: [
|
||||
],
|
||||
shortDescription: "",
|
||||
targets: [
|
||||
"dmg"
|
||||
]
|
||||
};
|
||||
var MacConf = {
|
||||
tauri: tauri$1
|
||||
identifier: identifier$1,
|
||||
bundle: bundle$1
|
||||
};
|
||||
|
||||
var tauri = {
|
||||
bundle: {
|
||||
icon: [
|
||||
"png/weread_512.png"
|
||||
],
|
||||
identifier: "com.pake.weread",
|
||||
active: true,
|
||||
category: "DeveloperTool",
|
||||
copyright: "",
|
||||
var identifier = "com.pake.weread";
|
||||
var bundle = {
|
||||
icon: [
|
||||
"png/weread_512.png"
|
||||
],
|
||||
active: true,
|
||||
category: "DeveloperTool",
|
||||
copyright: "",
|
||||
linux: {
|
||||
deb: {
|
||||
depends: [
|
||||
"curl",
|
||||
@@ -288,21 +267,22 @@ var tauri = {
|
||||
files: {
|
||||
"/usr/share/applications/com-pake-weread.desktop": "assets/com-pake-weread.desktop"
|
||||
}
|
||||
},
|
||||
externalBin: [
|
||||
],
|
||||
longDescription: "",
|
||||
resources: [
|
||||
],
|
||||
shortDescription: "",
|
||||
targets: [
|
||||
"deb",
|
||||
"appimage"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
externalBin: [
|
||||
],
|
||||
longDescription: "",
|
||||
resources: [
|
||||
],
|
||||
shortDescription: "",
|
||||
targets: [
|
||||
"deb",
|
||||
"appimage"
|
||||
]
|
||||
};
|
||||
var LinuxConf = {
|
||||
tauri: tauri
|
||||
identifier: identifier,
|
||||
bundle: bundle
|
||||
};
|
||||
|
||||
const platformConfigs = {
|
||||
@@ -314,11 +294,15 @@ const { platform: platform$2 } = process;
|
||||
// @ts-ignore
|
||||
const platformConfig = platformConfigs[platform$2];
|
||||
let tauriConfig = {
|
||||
tauri: {
|
||||
...CommonConf.tauri,
|
||||
bundle: platformConfig.tauri.bundle,
|
||||
...CommonConf,
|
||||
bundle: platformConfig.bundle,
|
||||
app: {
|
||||
...CommonConf.app,
|
||||
trayIcon: {
|
||||
...CommonConf.app.trayIcon,
|
||||
...platformConfig.app.trayIcon,
|
||||
},
|
||||
},
|
||||
package: CommonConf.package,
|
||||
build: CommonConf.build,
|
||||
pake: pakeConf,
|
||||
};
|
||||
@@ -476,7 +460,7 @@ async function combineFiles(files, output) {
|
||||
}
|
||||
|
||||
async function mergeConfig(url, options, tauriConf) {
|
||||
const { width, height, fullscreen, hideTitleBar, alwaysOnTop, disabledWebShortcuts, activationShortcut, userAgent, showSystemTray, systemTrayIcon, useLocalFile, identifier, name, resizable = true, inject, safeDomain, } = options;
|
||||
const { width, height, fullscreen, hideTitleBar, alwaysOnTop, disabledWebShortcuts, activationShortcut, userAgent, showSystemTray, systemTrayIcon, useLocalFile, identifier, name, resizable = true, inject, } = options;
|
||||
const { platform } = process;
|
||||
// Set Windows parameters.
|
||||
const tauriConfWindowOptions = {
|
||||
@@ -490,8 +474,8 @@ async function mergeConfig(url, options, tauriConf) {
|
||||
disabled_web_shortcuts: disabledWebShortcuts,
|
||||
};
|
||||
Object.assign(tauriConf.pake.windows[0], { url, ...tauriConfWindowOptions });
|
||||
tauriConf.package.productName = name;
|
||||
tauriConf.tauri.bundle.identifier = identifier;
|
||||
tauriConf.productName = name;
|
||||
tauriConf.identifier = identifier;
|
||||
//Judge the type of URL, whether it is a file or a website.
|
||||
const pathExists = await fsExtra.pathExists(url);
|
||||
if (pathExists) {
|
||||
@@ -518,24 +502,6 @@ async function mergeConfig(url, options, tauriConf) {
|
||||
}
|
||||
else {
|
||||
tauriConf.pake.windows[0].url_type = 'web';
|
||||
// Set the secure domain for calling window.__TAURI__ to the application domain that has been set.
|
||||
tauriConf.tauri.security.dangerousRemoteDomainIpcAccess = [
|
||||
{
|
||||
domain: new URL(url).hostname,
|
||||
windows: ['pake'],
|
||||
enableTauriAPI: true,
|
||||
},
|
||||
];
|
||||
}
|
||||
if (safeDomain.length > 0) {
|
||||
tauriConf.tauri.security.dangerousRemoteDomainIpcAccess = [
|
||||
...tauriConf.tauri.security.dangerousRemoteDomainIpcAccess,
|
||||
...safeDomain.map(domain => ({
|
||||
domain,
|
||||
windows: ['pake'],
|
||||
enableTauriAPI: true,
|
||||
})),
|
||||
];
|
||||
}
|
||||
const platformMap = {
|
||||
win32: 'windows',
|
||||
@@ -549,10 +515,10 @@ async function mergeConfig(url, options, tauriConf) {
|
||||
tauriConf.pake.system_tray[currentPlatform] = showSystemTray;
|
||||
// Processing targets are currently only open to Linux.
|
||||
if (platform === 'linux') {
|
||||
delete tauriConf.tauri.bundle.deb.files;
|
||||
delete tauriConf.bundle.linux.deb.files;
|
||||
const validTargets = ['all', 'deb', 'appimage'];
|
||||
if (validTargets.includes(options.targets)) {
|
||||
tauriConf.tauri.bundle.targets = options.targets === 'all' ? ['deb', 'appimage'] : [options.targets];
|
||||
tauriConf.bundle.targets = options.targets === 'all' ? ['deb', 'appimage'] : [options.targets];
|
||||
}
|
||||
else {
|
||||
logger.warn(`✼ The target must be one of ${validTargets.join(', ')}, the default 'deb' will be used.`);
|
||||
@@ -587,15 +553,15 @@ async function mergeConfig(url, options, tauriConf) {
|
||||
if (customIconExt !== iconInfo.fileExt) {
|
||||
updateIconPath = false;
|
||||
logger.warn(`✼ ${iconInfo.message}, but you give ${customIconExt}`);
|
||||
tauriConf.tauri.bundle.icon = [iconInfo.defaultIcon];
|
||||
tauriConf.bundle.icon = [iconInfo.defaultIcon];
|
||||
}
|
||||
else {
|
||||
const iconPath = path.join(npmDirectory, 'src-tauri/', iconInfo.path);
|
||||
tauriConf.tauri.bundle.resources = [iconInfo.path];
|
||||
tauriConf.bundle.resources = [iconInfo.path];
|
||||
await fsExtra.copy(options.icon, iconPath);
|
||||
}
|
||||
if (updateIconPath) {
|
||||
tauriConf.tauri.bundle.icon = [options.icon];
|
||||
tauriConf.bundle.icon = [options.icon];
|
||||
}
|
||||
else {
|
||||
logger.warn(`✼ Icon will remain as default.`);
|
||||
@@ -603,10 +569,10 @@ async function mergeConfig(url, options, tauriConf) {
|
||||
}
|
||||
else {
|
||||
logger.warn('✼ Custom icon path may be invalid, default icon will be used instead.');
|
||||
tauriConf.tauri.bundle.icon = [iconInfo.defaultIcon];
|
||||
tauriConf.bundle.icon = [iconInfo.defaultIcon];
|
||||
}
|
||||
// Set tray icon path.
|
||||
let trayIconPath = platform === 'darwin' ? 'png/icon_512.png' : tauriConf.tauri.bundle.icon[0];
|
||||
let trayIconPath = platform === 'darwin' ? 'png/icon_512.png' : tauriConf.bundle.icon[0];
|
||||
if (systemTrayIcon.length > 0) {
|
||||
try {
|
||||
await fsExtra.pathExists(systemTrayIcon);
|
||||
@@ -627,7 +593,7 @@ async function mergeConfig(url, options, tauriConf) {
|
||||
logger.warn(`✼ Default system tray icon will remain unchanged.`);
|
||||
}
|
||||
}
|
||||
tauriConf.tauri.systemTray.iconPath = trayIconPath;
|
||||
tauriConf.app.trayIcon.iconPath = trayIconPath;
|
||||
const injectFilePath = path.join(npmDirectory, `src-tauri/src/inject/custom.js`);
|
||||
// inject js or css files
|
||||
if (inject?.length > 0) {
|
||||
@@ -650,13 +616,12 @@ async function mergeConfig(url, options, tauriConf) {
|
||||
linux: 'tauri.linux.conf.json',
|
||||
};
|
||||
const configPath = path.join(tauriConfigDirectory, platformConfigPaths[platform]);
|
||||
const bundleConf = { tauri: { bundle: tauriConf.tauri.bundle } };
|
||||
const bundleConf = { bundle: tauriConf.bundle };
|
||||
await fsExtra.outputJSON(configPath, bundleConf, { spaces: 4 });
|
||||
const pakeConfigPath = path.join(tauriConfigDirectory, 'pake.json');
|
||||
await fsExtra.outputJSON(pakeConfigPath, tauriConf.pake, { spaces: 4 });
|
||||
let tauriConf2 = JSON.parse(JSON.stringify(tauriConf));
|
||||
delete tauriConf2.pake;
|
||||
delete tauriConf2.tauri.bundle;
|
||||
const configJsonPath = path.join(tauriConfigDirectory, 'tauri.conf.json');
|
||||
await fsExtra.outputJSON(configJsonPath, tauriConf2, { spaces: 4 });
|
||||
}
|
||||
@@ -759,7 +724,7 @@ class MacBuilder extends BaseBuilder {
|
||||
else {
|
||||
arch = process.arch === 'arm64' ? 'aarch64' : process.arch;
|
||||
}
|
||||
return `${name}_${tauriConfig.package.version}_${arch}`;
|
||||
return `${name}_${tauriConfig.version}_${arch}`;
|
||||
}
|
||||
getBuildCommand() {
|
||||
return this.options.multiArch ? 'npm run build:mac' : super.getBuildCommand();
|
||||
@@ -779,8 +744,8 @@ class WinBuilder extends BaseBuilder {
|
||||
getFileName() {
|
||||
const { name } = this.options;
|
||||
const { arch } = process;
|
||||
const language = tauriConfig.tauri.bundle.windows.wix.language[0];
|
||||
return `${name}_${tauriConfig.package.version}_${arch}_${language}`;
|
||||
const language = tauriConfig.bundle.windows.wix.language[0];
|
||||
return `${name}_${tauriConfig.version}_${arch}_${language}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -791,7 +756,7 @@ class LinuxBuilder extends BaseBuilder {
|
||||
getFileName() {
|
||||
const { name } = this.options;
|
||||
const arch = process.arch === 'x64' ? 'amd64' : process.arch;
|
||||
return `${name}_${tauriConfig.package.version}_${arch}`;
|
||||
return `${name}_${tauriConfig.version}_${arch}`;
|
||||
}
|
||||
// Customize it, considering that there are all targets.
|
||||
async build(url) {
|
||||
|
||||
13
src-tauri/Cargo.lock
generated
13
src-tauri/Cargo.lock
generated
@@ -3552,9 +3552,9 @@ checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f"
|
||||
|
||||
[[package]]
|
||||
name = "tauri"
|
||||
version = "2.0.0-beta.24"
|
||||
version = "2.0.0-beta.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3eab508aad4ae86e23865e294b20a7bb89bd7afea523897b7478329b841d4295"
|
||||
checksum = "4339c67eb7700fe4a80ad6507e3b9af0b4159959f3d74aae48feed298baf4cbf"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
@@ -3568,6 +3568,7 @@ dependencies = [
|
||||
"gtk",
|
||||
"heck 0.5.0",
|
||||
"http",
|
||||
"image 0.24.9",
|
||||
"jni",
|
||||
"libc",
|
||||
"log",
|
||||
@@ -3781,9 +3782,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-runtime"
|
||||
version = "2.0.0-beta.20"
|
||||
version = "2.0.0-beta.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe978df03966febbebc608931dc2cf26ef94df70855a18b05f07134cf474de09"
|
||||
checksum = "189510033be50f6fde35cfa50b50c7ab4e0ced0c867ae0f643b4907b8385bbe5"
|
||||
dependencies = [
|
||||
"dpi",
|
||||
"gtk",
|
||||
@@ -3800,9 +3801,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tauri-runtime-wry"
|
||||
version = "2.0.0-beta.20"
|
||||
version = "2.0.0-beta.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "11e4d568f61095f507b3fc4254dfbfff3b20de2a1d66167ffca3f6d90b14db8f"
|
||||
checksum = "6938bd63b6658e7b08f0fe2151390148ee5a8ccdba100d4dff961d2c8734d9a9"
|
||||
dependencies = [
|
||||
"cocoa",
|
||||
"gtk",
|
||||
|
||||
@@ -21,7 +21,7 @@ tauri-build = { version = "2.0.0-beta", features = [] }
|
||||
[dependencies]
|
||||
serde_json = "1.0.116"
|
||||
serde = { version = "1.0.200", features = ["derive"] }
|
||||
tauri = { version = "2.0.0-beta", features = ["tray-icon"] }
|
||||
tauri = { version = "2.0.0-beta.25", features = ["tray-icon", "image-ico", "image-png"] }
|
||||
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
||||
tauri-plugin-oauth = { git = "https://github.com/FabianLars/tauri-plugin-oauth", branch = "v2" }
|
||||
tauri-plugin-clipboard-manager = "2.1.0-beta.6"
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1921,6 +1921,13 @@
|
||||
"window:allow-set-size"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "window:allow-set-size-constraints -> Enables the set_size_constraints command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"window:allow-set-size-constraints"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "window:allow-set-skip-taskbar -> Enables the set_skip_taskbar command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
@@ -2369,6 +2376,13 @@
|
||||
"window:deny-set-size"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "window:deny-set-size-constraints -> Denies the set_size_constraints command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"window:deny-set-size-constraints"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "window:deny-set-skip-taskbar -> Denies the set_skip_taskbar command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
|
||||
@@ -1921,6 +1921,13 @@
|
||||
"window:allow-set-size"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "window:allow-set-size-constraints -> Enables the set_size_constraints command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"window:allow-set-size-constraints"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "window:allow-set-skip-taskbar -> Enables the set_skip_taskbar command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
@@ -2369,6 +2376,13 @@
|
||||
"window:deny-set-size"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "window:deny-set-size-constraints -> Denies the set_size_constraints command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"window:deny-set-size-constraints"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "window:deny-set-skip-taskbar -> Denies the set_skip_taskbar command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
|
||||
Binary file not shown.
Binary file not shown.
BIN
src-tauri/icons/xiaoyuzhou.icns
Normal file
BIN
src-tauri/icons/xiaoyuzhou.icns
Normal file
Binary file not shown.
@@ -51,6 +51,7 @@ pub struct PakeConfig {
|
||||
pub windows: Vec<WindowConfig>,
|
||||
pub user_agent: UserAgent,
|
||||
pub system_tray: FunctionON,
|
||||
pub system_tray_path: String,
|
||||
}
|
||||
|
||||
impl PakeConfig {
|
||||
|
||||
@@ -1,16 +1,44 @@
|
||||
use tauri::{
|
||||
menu::{MenuBuilder, MenuItemBuilder}, tray::TrayIconBuilder, AppHandle, Manager
|
||||
image::Image, include_image, menu::{ContextMenu, MenuBuilder, MenuItemBuilder}, tray::{MouseButton, MouseButtonState, TrayIcon, TrayIconBuilder, TrayIconEvent}, AppHandle, Config, Manager
|
||||
};
|
||||
use tauri_plugin_window_state::{AppHandleExt, StateFlags};
|
||||
|
||||
pub fn set_system_tray(app: &AppHandle) -> tauri::Result<()> {
|
||||
use super::config::PakeConfig;
|
||||
|
||||
pub fn set_system_tray(app: &AppHandle, pake_config: &PakeConfig) -> tauri::Result<()> {
|
||||
let hide_app = MenuItemBuilder::with_id("hide_app", "Hide").build(app)?;
|
||||
let show_app = MenuItemBuilder::with_id("show_app", "Show").build(app)?;
|
||||
let quit = MenuItemBuilder::with_id("quit", "Quit").build(app)?;
|
||||
let menu = MenuBuilder::new(app).items(&[&hide_app, &show_app, &quit]).build()?;
|
||||
|
||||
TrayIconBuilder::new()
|
||||
app.app_handle().remove_tray_by_id("pake-tray");
|
||||
let tray = TrayIconBuilder::new()
|
||||
.icon(Image::from_path(pake_config.system_tray_path.as_str())?)
|
||||
.menu(&menu)
|
||||
.on_tray_icon_event(move |tray, event| {
|
||||
if let TrayIconEvent::Click {
|
||||
button: MouseButton::Left,
|
||||
button_state: MouseButtonState::Up,
|
||||
..
|
||||
} = event {
|
||||
println!("click");
|
||||
|
||||
let app = tray.app_handle();
|
||||
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
if let Some(webview_window) = app.get_webview_window("pake") {
|
||||
let _ = webview_window.show();
|
||||
let _ = webview_window.set_focus();
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
tauri::AppHandle::show(&app.app_handle()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
.on_menu_event(move |app, event| match event.id().as_ref() {
|
||||
"hide_app" => {
|
||||
app.get_webview_window("pake").unwrap().minimize().unwrap();
|
||||
@@ -26,5 +54,6 @@ pub fn set_system_tray(app: &AppHandle) -> tauri::Result<()> {
|
||||
})
|
||||
.build(app)?;
|
||||
|
||||
tray.set_icon_as_template(false)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use tauri::{App, WebviewUrl, WebviewWindow, WebviewWindowBuilder};
|
||||
#[cfg(target_os = "macos")]
|
||||
use tauri::TitleBarStyle;
|
||||
|
||||
pub fn get_window(app: &mut App, config: PakeConfig, _data_dir: PathBuf) -> WebviewWindow {
|
||||
pub fn get_window(app: &mut App, config: &PakeConfig, _data_dir: PathBuf) -> WebviewWindow {
|
||||
let window_config = config
|
||||
.windows
|
||||
.first()
|
||||
|
||||
6
src-tauri/src/inject/custom.js
vendored
6
src-tauri/src/inject/custom.js
vendored
@@ -1,6 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@@ -8,14 +8,14 @@ use app::{invoke, menu::set_system_tray, window};
|
||||
use invoke::{download_file, download_file_by_binary};
|
||||
use tauri::Manager;
|
||||
use tauri_plugin_window_state::Builder as windowStatePlugin;
|
||||
use tauri_plugin_global_shortcut::Shortcut;
|
||||
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut};
|
||||
use util::{get_data_dir, get_pake_config};
|
||||
use window::get_window;
|
||||
|
||||
pub fn run_app() {
|
||||
let (pake_config, tauri_config) = get_pake_config();
|
||||
|
||||
let mut tauri_app = tauri::Builder::default();
|
||||
let tauri_app = tauri::Builder::default();
|
||||
|
||||
let show_system_tray = pake_config.show_system_tray();
|
||||
|
||||
@@ -31,24 +31,26 @@ pub fn run_app() {
|
||||
download_file_by_binary
|
||||
])
|
||||
.setup(move |app| {
|
||||
let data_dir = get_data_dir(&app.app_handle(), tauri_config);
|
||||
let data_dir = get_data_dir(&app.app_handle(), tauri_config.clone());
|
||||
|
||||
let _window = get_window(app, pake_config, data_dir);
|
||||
let _window = get_window(app, &pake_config, data_dir);
|
||||
// Prevent initial shaking
|
||||
_window.show().unwrap();
|
||||
|
||||
if show_system_tray {
|
||||
let _ = set_system_tray(&app.app_handle());
|
||||
let _ = set_system_tray(&app.app_handle(), &pake_config);
|
||||
} else {
|
||||
app.app_handle().remove_tray_by_id("pake-tray");
|
||||
}
|
||||
|
||||
if !activation_shortcut.is_empty() {
|
||||
let app_handle = app.app_handle().clone();
|
||||
let shortcut_hotkey = Shortcut::from_str(&activation_shortcut.as_str()).unwrap();
|
||||
|
||||
app_handle
|
||||
.plugin(
|
||||
tauri_plugin_global_shortcut::Builder::new()
|
||||
.with_shortcut(activation_shortcut.as_str())
|
||||
?.with_handler(move |app, event, _shortcut| {
|
||||
let shortcut_hotkey = Shortcut::from_str(&activation_shortcut.as_str()).unwrap();
|
||||
.with_handler(move |app, event, _shortcut| {
|
||||
|
||||
if shortcut_hotkey.eq(event) {
|
||||
let window = app.get_webview_window("pake").unwrap();
|
||||
@@ -63,6 +65,8 @@ pub fn run_app() {
|
||||
}
|
||||
).build())
|
||||
.expect("Error registering global evoke shortcuts!");
|
||||
|
||||
app.global_shortcut().register(shortcut_hotkey)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
},
|
||||
"trayIcon": {
|
||||
"iconPath": "png/icon_512.png",
|
||||
"iconAsTemplate": false
|
||||
"iconAsTemplate": false,
|
||||
"id": "pake-tray"
|
||||
},
|
||||
"withGlobalTauri": true
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
{
|
||||
"tauri": {
|
||||
"identifier": "com.pake.weread",
|
||||
|
||||
"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" }
|
||||
"linux": {
|
||||
"deb": {
|
||||
"depends": ["curl", "wget"],
|
||||
"files": { "/usr/share/applications/com-pake-weread.desktop": "assets/com-pake-weread.desktop" }
|
||||
}
|
||||
},
|
||||
"externalBin": [],
|
||||
"longDescription": "",
|
||||
@@ -16,5 +18,4 @@
|
||||
"shortDescription": "",
|
||||
"targets": ["deb", "appimage"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,22 @@
|
||||
{
|
||||
"tauri": {
|
||||
"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"
|
||||
}
|
||||
"identifier": "com.pake.weread",
|
||||
"bundle": {
|
||||
"icon": ["png/weread_256.ico", "png/weread_32.ico"],
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user