zcw-shared 1.42.0 → 1.43.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/functions/android/configureAppIcon.d.ts +17 -0
- package/dist/functions/android/configureAppIcon.js +106 -0
- package/dist/functions/android/configureAppIcon.js.map +1 -0
- package/dist/functions/android/configureLaunchScreen.d.ts +5 -1
- package/dist/functions/android/configureLaunchScreen.js +115 -20
- package/dist/functions/android/configureLaunchScreen.js.map +1 -1
- package/dist/functions/android/modifyGradle.d.ts +1 -0
- package/dist/functions/android/modifyGradle.js +5 -0
- package/dist/functions/android/modifyGradle.js.map +1 -1
- package/dist/functions/android/permission.d.ts +17 -3
- package/dist/functions/android/permission.js +26 -6
- package/dist/functions/android/permission.js.map +1 -1
- package/dist/functions/ios/configureAppIcon.d.ts +17 -0
- package/dist/functions/ios/configureAppIcon.js +149 -0
- package/dist/functions/ios/configureAppIcon.js.map +1 -0
- package/dist/functions/ios/configureLaunchScreen.js +70 -57
- package/dist/functions/ios/configureLaunchScreen.js.map +1 -1
- package/dist/functions/ios/configurePermissions.d.ts +19 -0
- package/dist/functions/ios/configurePermissions.js +120 -0
- package/dist/functions/ios/configurePermissions.js.map +1 -0
- package/dist/functions/uniapp/app-plus/buildAndroidApp.d.ts +2 -1
- package/dist/functions/uniapp/app-plus/buildAndroidApp.js +100 -34
- package/dist/functions/uniapp/app-plus/buildAndroidApp.js.map +1 -1
- package/dist/functions/uniapp/app-plus/buildAndroidPlugin.js +42 -34
- package/dist/functions/uniapp/app-plus/buildAndroidPlugin.js.map +1 -1
- package/dist/functions/uniapp/app-plus/buildIOSApp.js +92 -28
- package/dist/functions/uniapp/app-plus/buildIOSApp.js.map +1 -1
- package/dist/functions/uniapp/app-plus/buildIOSPlugin.js +50 -27
- package/dist/functions/uniapp/app-plus/buildIOSPlugin.js.map +1 -1
- package/package.json +4 -1
- package/types/uniapp-android-build.d.ts +18 -0
- package/types/uniapp-ios-build.d.ts +18 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
const IOS_ICON_SIZES = [
|
|
2
|
+
{ idiom: 'iphone', scale: '2x', size: '20x20', pixels: 40 },
|
|
3
|
+
{ idiom: 'iphone', scale: '3x', size: '20x20', pixels: 60 },
|
|
4
|
+
{ idiom: 'iphone', scale: '2x', size: '29x29', pixels: 58 },
|
|
5
|
+
{ idiom: 'iphone', scale: '3x', size: '29x29', pixels: 87 },
|
|
6
|
+
{ idiom: 'iphone', scale: '2x', size: '40x40', pixels: 80 },
|
|
7
|
+
{ idiom: 'iphone', scale: '3x', size: '40x40', pixels: 120 },
|
|
8
|
+
{ idiom: 'iphone', scale: '2x', size: '60x60', pixels: 120 },
|
|
9
|
+
{ idiom: 'iphone', scale: '3x', size: '60x60', pixels: 180 },
|
|
10
|
+
{ idiom: 'ipad', scale: '1x', size: '20x20', pixels: 20 },
|
|
11
|
+
{ idiom: 'ipad', scale: '2x', size: '20x20', pixels: 40 },
|
|
12
|
+
{ idiom: 'ipad', scale: '1x', size: '29x29', pixels: 29 },
|
|
13
|
+
{ idiom: 'ipad', scale: '2x', size: '29x29', pixels: 58 },
|
|
14
|
+
{ idiom: 'ipad', scale: '1x', size: '40x40', pixels: 40 },
|
|
15
|
+
{ idiom: 'ipad', scale: '2x', size: '40x40', pixels: 80 },
|
|
16
|
+
{ idiom: 'ipad', scale: '1x', size: '76x76', pixels: 76 },
|
|
17
|
+
{ idiom: 'ipad', scale: '2x', size: '76x76', pixels: 152 },
|
|
18
|
+
{ idiom: 'ipad', scale: '2x', size: '83.5x83.5', pixels: 167 },
|
|
19
|
+
{ idiom: 'ios-marketing', scale: '1x', size: '1024x1024', pixels: 1024 }
|
|
20
|
+
];
|
|
21
|
+
const DCLOUD_ICON_SIZES = [
|
|
22
|
+
{ filename: 'icon29.png', size: 29 },
|
|
23
|
+
{ filename: 'icon40.png', size: 40 },
|
|
24
|
+
{ filename: 'icon50.png', size: 50 },
|
|
25
|
+
{ filename: 'icon57.png', size: 57 },
|
|
26
|
+
{ filename: 'icon58.png', size: 58 },
|
|
27
|
+
{ filename: 'icon60.png', size: 60 },
|
|
28
|
+
{ filename: 'icon72.png', size: 72 },
|
|
29
|
+
{ filename: 'icon76.png', size: 76 },
|
|
30
|
+
{ filename: 'icon80.png', size: 80 },
|
|
31
|
+
{ filename: 'icon87.png', size: 87 },
|
|
32
|
+
{ filename: 'icon100.png', size: 100 },
|
|
33
|
+
{ filename: 'icon114.png', size: 114 },
|
|
34
|
+
{ filename: 'icon120.png', size: 120 },
|
|
35
|
+
{ filename: 'icon144.png', size: 144 },
|
|
36
|
+
{ filename: 'icon152.png', size: 152 },
|
|
37
|
+
{ filename: 'icon180.png', size: 180 },
|
|
38
|
+
{ filename: 'icon1024.png', size: 1024 }
|
|
39
|
+
];
|
|
40
|
+
export async function configureAppIconIOS(imagePath, projectPath, projectName, deps) {
|
|
41
|
+
const logs = [];
|
|
42
|
+
try {
|
|
43
|
+
if (!deps.existsSync(imagePath)) {
|
|
44
|
+
return {
|
|
45
|
+
success: false,
|
|
46
|
+
error: `原始图片不存在: ${imagePath}`,
|
|
47
|
+
logs
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
logs.push(`找到原始图标图片: ${imagePath}`);
|
|
51
|
+
const imageBuffer = deps.readFileSync(imagePath);
|
|
52
|
+
logs.push('成功读取原始图片');
|
|
53
|
+
const sharpInstance = deps.sharp(imageBuffer);
|
|
54
|
+
const metadata = await sharpInstance.metadata();
|
|
55
|
+
const originalWidth = metadata.width || 1024;
|
|
56
|
+
const originalHeight = metadata.height || 1024;
|
|
57
|
+
logs.push(`原图尺寸: ${originalWidth}x${originalHeight}`);
|
|
58
|
+
if (originalWidth !== originalHeight) {
|
|
59
|
+
logs.push(`警告: 图标图片不是正方形 (${originalWidth}x${originalHeight}),将进行裁剪处理`);
|
|
60
|
+
}
|
|
61
|
+
const possibleAssetsPaths = [
|
|
62
|
+
deps.join(projectPath, projectName, 'Assets.xcassets'),
|
|
63
|
+
deps.join(projectPath, projectName, 'Images.xcassets'),
|
|
64
|
+
deps.join(projectPath, 'HBuilder', 'Images.xcassets'),
|
|
65
|
+
deps.join(projectPath, 'HBuilder', 'Assets.xcassets')
|
|
66
|
+
];
|
|
67
|
+
let assetsPath = null;
|
|
68
|
+
for (const p of possibleAssetsPaths) {
|
|
69
|
+
if (deps.existsSync(p)) {
|
|
70
|
+
assetsPath = p;
|
|
71
|
+
logs.push(`找到资源目录: ${p}`);
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (assetsPath) {
|
|
76
|
+
const appIconSetPath = deps.join(assetsPath, 'AppIcon.appiconset');
|
|
77
|
+
if (!deps.existsSync(appIconSetPath)) {
|
|
78
|
+
deps.mkdirSync(appIconSetPath, { recursive: true });
|
|
79
|
+
logs.push(`创建 AppIcon.appiconset 目录`);
|
|
80
|
+
}
|
|
81
|
+
logs.push('开始生成 AppIcon.appiconset 图标...');
|
|
82
|
+
const contentsImages = [];
|
|
83
|
+
for (const sizeConfig of IOS_ICON_SIZES) {
|
|
84
|
+
const filename = `AppIcon-${sizeConfig.pixels}.png`;
|
|
85
|
+
const outputPath = deps.join(appIconSetPath, filename);
|
|
86
|
+
const resizedIcon = await deps.sharp(imageBuffer)
|
|
87
|
+
.resize(sizeConfig.pixels, sizeConfig.pixels, {
|
|
88
|
+
fit: 'cover',
|
|
89
|
+
position: 'center'
|
|
90
|
+
})
|
|
91
|
+
.png()
|
|
92
|
+
.toBuffer();
|
|
93
|
+
deps.writeFileSync(outputPath, resizedIcon);
|
|
94
|
+
logs.push(`已生成 ${filename} (${sizeConfig.pixels}x${sizeConfig.pixels})`);
|
|
95
|
+
contentsImages.push({
|
|
96
|
+
filename,
|
|
97
|
+
idiom: sizeConfig.idiom,
|
|
98
|
+
scale: sizeConfig.scale,
|
|
99
|
+
size: sizeConfig.size
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
const contentsJson = {
|
|
103
|
+
images: contentsImages,
|
|
104
|
+
info: {
|
|
105
|
+
author: 'xcode',
|
|
106
|
+
version: 1
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const contentsJsonPath = deps.join(appIconSetPath, 'Contents.json');
|
|
110
|
+
deps.writeFileSync(contentsJsonPath, JSON.stringify(contentsJson, null, 2), 'utf8');
|
|
111
|
+
logs.push('已生成 Contents.json');
|
|
112
|
+
logs.push(`AppIcon.appiconset 配置完成,共生成 ${IOS_ICON_SIZES.length} 个图标文件`);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
logs.push('未找到 Assets.xcassets 或 Images.xcassets 目录,跳过 appiconset 生成');
|
|
116
|
+
}
|
|
117
|
+
const iconDir = deps.join(projectPath, projectName, 'icon');
|
|
118
|
+
if (deps.existsSync(iconDir)) {
|
|
119
|
+
logs.push('开始生成 DCloud 传统格式图标 (icon/ 目录)...');
|
|
120
|
+
for (const iconConfig of DCLOUD_ICON_SIZES) {
|
|
121
|
+
const outputPath = deps.join(iconDir, iconConfig.filename);
|
|
122
|
+
const resizedIcon = await deps.sharp(imageBuffer)
|
|
123
|
+
.resize(iconConfig.size, iconConfig.size, {
|
|
124
|
+
fit: 'cover',
|
|
125
|
+
position: 'center'
|
|
126
|
+
})
|
|
127
|
+
.png()
|
|
128
|
+
.toBuffer();
|
|
129
|
+
deps.writeFileSync(outputPath, resizedIcon);
|
|
130
|
+
logs.push(`已生成 ${iconConfig.filename} (${iconConfig.size}x${iconConfig.size})`);
|
|
131
|
+
}
|
|
132
|
+
logs.push(`DCloud 传统图标配置完成,共生成 ${DCLOUD_ICON_SIZES.length} 个图标文件`);
|
|
133
|
+
}
|
|
134
|
+
logs.push('iOS App Icon 配置完成');
|
|
135
|
+
return {
|
|
136
|
+
success: true,
|
|
137
|
+
logs
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
142
|
+
return {
|
|
143
|
+
success: false,
|
|
144
|
+
error: `配置 iOS App Icon 时出错: ${errorMessage}`,
|
|
145
|
+
logs
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=configureAppIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configureAppIcon.js","sourceRoot":"","sources":["../../../src/functions/ios/configureAppIcon.ts"],"names":[],"mappings":"AAsCA,MAAM,cAAc,GAAG;IAErB,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE;IAC3D,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE;IAE3D,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE;IAC3D,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE;IAE3D,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE;IAC3D,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE;IAE5D,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE;IAC5D,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE;IAE5D,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI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AK,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,IAAI,GAAG,CAAC,CAAA;YACjF,CAAC;YAED,IAAI,CAAC,IAAI,CAAC,uBAAuB,iBAAiB,CAAC,MAAM,QAAQ,CAAC,CAAA;QACpE,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA;QAE9B,OAAO;YACL,OAAO,EAAE,IAAI;YACb,IAAI;SACL,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAC3E,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,wBAAwB,YAAY,EAAE;YAC7C,IAAI;SACL,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -11,67 +11,80 @@ export async function configureLaunchScreen(imagePath, projectPath, projectName,
|
|
|
11
11
|
logs.push(`找到原始图片: ${imagePath}`);
|
|
12
12
|
const imageBuffer = deps.readFileSync(imagePath);
|
|
13
13
|
logs.push('成功读取原始图片');
|
|
14
|
-
const assetsPath = deps.join(projectPath, projectName, 'Assets.xcassets');
|
|
15
|
-
const imageSetPath = deps.join(assetsPath, 'LaunchImage.imageset');
|
|
16
|
-
if (!deps.existsSync(assetsPath)) {
|
|
17
|
-
return {
|
|
18
|
-
success: false,
|
|
19
|
-
error: `Assets.xcassets 目录不存在: ${assetsPath}`,
|
|
20
|
-
logs
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
if (!deps.existsSync(imageSetPath)) {
|
|
24
|
-
deps.mkdirSync(imageSetPath, { recursive: true });
|
|
25
|
-
logs.push(`创建 LaunchImage.imageset 目录: ${imageSetPath}`);
|
|
26
|
-
}
|
|
27
|
-
logs.push('开始生成不同分辨率的图片...');
|
|
28
14
|
const sharpInstance = deps.sharp(imageBuffer);
|
|
29
15
|
const metadata = await sharpInstance.metadata();
|
|
30
16
|
const originalWidth = metadata.width || 1000;
|
|
31
17
|
const originalHeight = metadata.height || 1000;
|
|
32
18
|
logs.push(`原图尺寸: ${originalWidth}x${originalHeight}`);
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
.resize(1500, 1500, {
|
|
46
|
-
fit: 'cover',
|
|
47
|
-
position: 'center'
|
|
48
|
-
})
|
|
49
|
-
.png()
|
|
50
|
-
.toBuffer();
|
|
51
|
-
const image3xPath = deps.join(imageSetPath, 'LaunchImage@3x.png');
|
|
52
|
-
deps.writeFileSync(image3xPath, image3x);
|
|
53
|
-
logs.push('已生成 @3x 版本 (1500x1500)');
|
|
54
|
-
const contentsJson = {
|
|
55
|
-
images: [
|
|
56
|
-
{
|
|
57
|
-
idiom: 'universal',
|
|
58
|
-
filename: 'LaunchImage@2x.png',
|
|
59
|
-
scale: '2x'
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
idiom: 'universal',
|
|
63
|
-
filename: 'LaunchImage@3x.png',
|
|
64
|
-
scale: '3x'
|
|
65
|
-
}
|
|
66
|
-
],
|
|
67
|
-
info: {
|
|
68
|
-
version: 1,
|
|
69
|
-
author: 'xcode'
|
|
19
|
+
const possibleAssetsPaths = [
|
|
20
|
+
deps.join(projectPath, projectName, 'Assets.xcassets'),
|
|
21
|
+
deps.join(projectPath, projectName, 'Images.xcassets'),
|
|
22
|
+
deps.join(projectPath, 'HBuilder', 'Images.xcassets'),
|
|
23
|
+
deps.join(projectPath, 'HBuilder', 'Assets.xcassets')
|
|
24
|
+
];
|
|
25
|
+
let assetsPath = null;
|
|
26
|
+
for (const p of possibleAssetsPaths) {
|
|
27
|
+
if (deps.existsSync(p)) {
|
|
28
|
+
assetsPath = p;
|
|
29
|
+
logs.push(`找到资源目录: ${p}`);
|
|
30
|
+
break;
|
|
70
31
|
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
32
|
+
}
|
|
33
|
+
if (assetsPath) {
|
|
34
|
+
const imageSetPath = deps.join(assetsPath, 'LaunchImage.imageset');
|
|
35
|
+
if (!deps.existsSync(imageSetPath)) {
|
|
36
|
+
deps.mkdirSync(imageSetPath, { recursive: true });
|
|
37
|
+
logs.push(`创建 LaunchImage.imageset 目录`);
|
|
38
|
+
}
|
|
39
|
+
logs.push('开始生成不同分辨率的图片...');
|
|
40
|
+
const aspectRatio = originalWidth / originalHeight;
|
|
41
|
+
const height2x = 2000;
|
|
42
|
+
const width2x = Math.round(height2x * aspectRatio);
|
|
43
|
+
const image2x = await deps.sharp(imageBuffer)
|
|
44
|
+
.resize(width2x, height2x, {
|
|
45
|
+
fit: 'inside'
|
|
46
|
+
})
|
|
47
|
+
.png()
|
|
48
|
+
.toBuffer();
|
|
49
|
+
const image2xPath = deps.join(imageSetPath, 'LaunchImage@2x.png');
|
|
50
|
+
deps.writeFileSync(image2xPath, image2x);
|
|
51
|
+
logs.push(`已生成 @2x 版本 (${width2x}x${height2x})`);
|
|
52
|
+
const height3x = 3000;
|
|
53
|
+
const width3x = Math.round(height3x * aspectRatio);
|
|
54
|
+
const image3x = await deps.sharp(imageBuffer)
|
|
55
|
+
.resize(width3x, height3x, {
|
|
56
|
+
fit: 'inside'
|
|
57
|
+
})
|
|
58
|
+
.png()
|
|
59
|
+
.toBuffer();
|
|
60
|
+
const image3xPath = deps.join(imageSetPath, 'LaunchImage@3x.png');
|
|
61
|
+
deps.writeFileSync(image3xPath, image3x);
|
|
62
|
+
logs.push(`已生成 @3x 版本 (${width3x}x${height3x})`);
|
|
63
|
+
const contentsJson = {
|
|
64
|
+
images: [
|
|
65
|
+
{
|
|
66
|
+
idiom: 'universal',
|
|
67
|
+
filename: 'LaunchImage@2x.png',
|
|
68
|
+
scale: '2x'
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
idiom: 'universal',
|
|
72
|
+
filename: 'LaunchImage@3x.png',
|
|
73
|
+
scale: '3x'
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
info: {
|
|
77
|
+
version: 1,
|
|
78
|
+
author: 'xcode'
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const contentsJsonPath = deps.join(imageSetPath, 'Contents.json');
|
|
82
|
+
deps.writeFileSync(contentsJsonPath, JSON.stringify(contentsJson, null, 2), 'utf8');
|
|
83
|
+
logs.push('已创建 Contents.json');
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
logs.push('未找到 Assets.xcassets 或 Images.xcassets 目录,跳过 imageset 生成');
|
|
87
|
+
}
|
|
75
88
|
const storyboardPath = deps.join(projectPath, projectName, 'LaunchScreen.storyboard');
|
|
76
89
|
const storyboardXml = generateLaunchScreenStoryboard();
|
|
77
90
|
deps.writeFileSync(storyboardPath, storyboardXml, 'utf8');
|
|
@@ -109,7 +122,7 @@ function generateLaunchScreenStoryboard() {
|
|
|
109
122
|
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
|
|
110
123
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
|
111
124
|
<subviews>
|
|
112
|
-
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="
|
|
125
|
+
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="LaunchImage" translatesAutoresizingMaskIntoConstraints="NO" id="launch-image-view">
|
|
113
126
|
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
|
|
114
127
|
</imageView>
|
|
115
128
|
</subviews>
|
|
@@ -129,7 +142,7 @@ function generateLaunchScreenStoryboard() {
|
|
|
129
142
|
</scene>
|
|
130
143
|
</scenes>
|
|
131
144
|
<resources>
|
|
132
|
-
<image name="LaunchImage" width="
|
|
145
|
+
<image name="LaunchImage" width="924" height="2000"/>
|
|
133
146
|
</resources>
|
|
134
147
|
</document>
|
|
135
148
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureLaunchScreen.js","sourceRoot":"","sources":["../../../src/functions/ios/configureLaunchScreen.ts"],"names":[],"mappings":"AA+DA,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,SAAiB,EACjB,WAAmB,EACnB,WAAmB,EACnB,IAA+B;IAE/B,MAAM,IAAI,GAAa,EAAE,CAAA;IAEzB,IAAI,CAAC;QAEH,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAChC,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,YAAY,SAAS,EAAE;gBAC9B,IAAI;aACL,CAAA;QACH,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,WAAW,SAAS,EAAE,CAAC,CAAA;QAGjC,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAA;QAChD,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QAGrB,MAAM,
|
|
1
|
+
{"version":3,"file":"configureLaunchScreen.js","sourceRoot":"","sources":["../../../src/functions/ios/configureLaunchScreen.ts"],"names":[],"mappings":"AA+DA,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,SAAiB,EACjB,WAAmB,EACnB,WAAmB,EACnB,IAA+B;IAE/B,MAAM,IAAI,GAAa,EAAE,CAAA;IAEzB,IAAI,CAAC;QAEH,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAChC,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,YAAY,SAAS,EAAE;gBAC9B,IAAI;aACL,CAAA;QACH,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,WAAW,SAAS,EAAE,CAAC,CAAA;QAGjC,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,S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AK,EAAE,aAAa,YAAY,EAAE;YAClC,IAAI;SACL,CAAA;IACH,CAAC;AACH,CAAC;AASD,SAAS,8BAA8B;IACrC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCR,CAAA;AACD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FileSystem } from '../../../references/node.d';
|
|
2
|
+
import type { XMLParserConstructor, XMLSerializerConstructor } from '../../../references/xml.d';
|
|
3
|
+
export interface ConfigureIOSPermissionsDeps {
|
|
4
|
+
existsSync: FileSystem['existsSync'];
|
|
5
|
+
readFileSync: FileSystem['readFileSync'];
|
|
6
|
+
writeFileSync: FileSystem['writeFileSync'];
|
|
7
|
+
xmlParser: XMLParserConstructor;
|
|
8
|
+
xmlSerializer: XMLSerializerConstructor;
|
|
9
|
+
}
|
|
10
|
+
export interface ConfigureIOSPermissionsResult {
|
|
11
|
+
success: boolean;
|
|
12
|
+
error?: string;
|
|
13
|
+
logs: string[];
|
|
14
|
+
data?: {
|
|
15
|
+
added: number;
|
|
16
|
+
skipped: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export declare function configureIOSPermissions(infoPlistPath: string, permissions: string[], customDescriptions?: Record<string, string>, deps?: ConfigureIOSPermissionsDeps): Promise<ConfigureIOSPermissionsResult>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { modifyInfoPlistKeyValue } from './modifyInfoPlistKeyValue';
|
|
2
|
+
const PERMISSION_MAPPING = {
|
|
3
|
+
'CAMERA': 'NSCameraUsageDescription',
|
|
4
|
+
'READ_EXTERNAL_STORAGE': 'NSPhotoLibraryUsageDescription',
|
|
5
|
+
'WRITE_EXTERNAL_STORAGE': 'NSPhotoLibraryAddUsageDescription',
|
|
6
|
+
'ACCESS_FINE_LOCATION': 'NSLocationWhenInUseUsageDescription',
|
|
7
|
+
'ACCESS_COARSE_LOCATION': 'NSLocationWhenInUseUsageDescription',
|
|
8
|
+
'RECORD_AUDIO': 'NSMicrophoneUsageDescription',
|
|
9
|
+
'READ_CONTACTS': 'NSContactsUsageDescription',
|
|
10
|
+
'WRITE_CONTACTS': 'NSContactsUsageDescription',
|
|
11
|
+
'READ_CALENDAR': 'NSCalendarsUsageDescription',
|
|
12
|
+
'WRITE_CALENDAR': 'NSCalendarsUsageDescription',
|
|
13
|
+
'READ_PHONE_STATE': 'NSUserTrackingUsageDescription',
|
|
14
|
+
'BLUETOOTH': 'NSBluetoothAlwaysUsageDescription',
|
|
15
|
+
'BLUETOOTH_ADMIN': 'NSBluetoothAlwaysUsageDescription',
|
|
16
|
+
'ACTIVITY_RECOGNITION': 'NSMotionUsageDescription',
|
|
17
|
+
'BODY_SENSORS': 'NSMotionUsageDescription',
|
|
18
|
+
'FACE_ID': 'NSFaceIDUsageDescription',
|
|
19
|
+
};
|
|
20
|
+
const DEFAULT_DESCRIPTIONS = {
|
|
21
|
+
'NSCameraUsageDescription': '应用需要使用相机来拍摄照片和视频',
|
|
22
|
+
'NSPhotoLibraryUsageDescription': '应用需要访问您的相册以选择图片',
|
|
23
|
+
'NSPhotoLibraryAddUsageDescription': '应用需要保存图片到您的相册',
|
|
24
|
+
'NSLocationWhenInUseUsageDescription': '应用需要获取您的位置信息以提供更好的服务',
|
|
25
|
+
'NSLocationAlwaysAndWhenInUseUsageDescription': '应用需要获取您的位置信息以提供更好的服务',
|
|
26
|
+
'NSMicrophoneUsageDescription': '应用需要使用麦克风来录制音频',
|
|
27
|
+
'NSContactsUsageDescription': '应用需要访问您的通讯录',
|
|
28
|
+
'NSCalendarsUsageDescription': '应用需要访问您的日历',
|
|
29
|
+
'NSRemindersUsageDescription': '应用需要访问您的提醒事项',
|
|
30
|
+
'NSMotionUsageDescription': '应用需要访问您的运动与健身数据',
|
|
31
|
+
'NSHealthShareUsageDescription': '应用需要读取您的健康数据',
|
|
32
|
+
'NSHealthUpdateUsageDescription': '应用需要更新您的健康数据',
|
|
33
|
+
'NSBluetoothPeripheralUsageDescription': '应用需要使用蓝牙',
|
|
34
|
+
'NSBluetoothAlwaysUsageDescription': '应用需要使用蓝牙',
|
|
35
|
+
'NSSpeechRecognitionUsageDescription': '应用需要使用语音识别功能',
|
|
36
|
+
'NSFaceIDUsageDescription': '应用需要使用 Face ID 进行身份验证',
|
|
37
|
+
'NSAppleMusicUsageDescription': '应用需要访问您的 Apple Music',
|
|
38
|
+
'NSLocalNetworkUsageDescription': '应用需要访问本地网络',
|
|
39
|
+
'NSUserTrackingUsageDescription': '应用需要追踪您的活动以提供个性化广告',
|
|
40
|
+
};
|
|
41
|
+
export async function configureIOSPermissions(infoPlistPath, permissions, customDescriptions, deps) {
|
|
42
|
+
const logs = [];
|
|
43
|
+
if (!deps) {
|
|
44
|
+
return {
|
|
45
|
+
success: false,
|
|
46
|
+
error: 'deps 参数是必需的',
|
|
47
|
+
logs
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
if (!deps.existsSync(infoPlistPath)) {
|
|
52
|
+
return {
|
|
53
|
+
success: false,
|
|
54
|
+
error: `Info.plist 文件不存在: ${infoPlistPath}`,
|
|
55
|
+
logs
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const xmlContent = deps.readFileSync(infoPlistPath, 'utf8');
|
|
59
|
+
const parser = new deps.xmlParser();
|
|
60
|
+
const xmlDoc = parser.parseFromString(xmlContent, 'text/xml');
|
|
61
|
+
const existingKeys = new Set();
|
|
62
|
+
const keyElements = xmlDoc.getElementsByTagName('key');
|
|
63
|
+
for (let i = 0; i < keyElements.length; i++) {
|
|
64
|
+
const keyElement = keyElements[i];
|
|
65
|
+
const keyName = keyElement.textContent;
|
|
66
|
+
if (keyName && keyName.startsWith('NS') && keyName.includes('UsageDescription')) {
|
|
67
|
+
existingKeys.add(keyName);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const iosPermissionKeys = new Set();
|
|
71
|
+
for (const permission of permissions) {
|
|
72
|
+
const cleanPermission = permission.replace(/^android\.permission\./i, '').toUpperCase();
|
|
73
|
+
const iosKey = PERMISSION_MAPPING[cleanPermission];
|
|
74
|
+
if (iosKey) {
|
|
75
|
+
iosPermissionKeys.add(iosKey);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
logs.push(`警告: 未找到权限 ${permission} 对应的 iOS 权限 key,已跳过`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const permissionsToAdd = Array.from(iosPermissionKeys).filter(key => !existingKeys.has(key));
|
|
82
|
+
if (permissionsToAdd.length === 0) {
|
|
83
|
+
logs.push('所有权限已存在,无需添加');
|
|
84
|
+
return {
|
|
85
|
+
success: true,
|
|
86
|
+
logs,
|
|
87
|
+
data: {
|
|
88
|
+
added: 0,
|
|
89
|
+
skipped: iosPermissionKeys.size
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
for (const iosKey of permissionsToAdd) {
|
|
94
|
+
const description = customDescriptions?.[iosKey] || DEFAULT_DESCRIPTIONS[iosKey] || '应用需要使用此功能';
|
|
95
|
+
modifyInfoPlistKeyValue(xmlDoc, iosKey, description, 'string');
|
|
96
|
+
logs.push(`已添加权限: ${iosKey}`);
|
|
97
|
+
}
|
|
98
|
+
const serializer = new deps.xmlSerializer();
|
|
99
|
+
const newXmlContent = serializer.serializeToString(xmlDoc);
|
|
100
|
+
deps.writeFileSync(infoPlistPath, newXmlContent, 'utf8');
|
|
101
|
+
logs.push(`权限配置完成,共添加 ${permissionsToAdd.length} 个权限`);
|
|
102
|
+
return {
|
|
103
|
+
success: true,
|
|
104
|
+
logs,
|
|
105
|
+
data: {
|
|
106
|
+
added: permissionsToAdd.length,
|
|
107
|
+
skipped: iosPermissionKeys.size - permissionsToAdd.length
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
113
|
+
return {
|
|
114
|
+
success: false,
|
|
115
|
+
error: `配置 iOS 权限时出错: ${errorMessage}`,
|
|
116
|
+
logs
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=configurePermissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configurePermissions.js","sourceRoot":"","sources":["../../../src/functions/ios/configurePermissions.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AA4BnE,MAAM,kBAAkB,GAA2B;IACjD,QAAQ,EAAE,0BAA0B;IACpC,uBAAuB,EAAE,gCAAgC;IACzD,wBAAwB,EAAE,mCAAmC;IAC7D,sBAAsB,EAAE,qCAAqC;IAC7D,wBAAwB,EAAE,qCAAqC;IAC/D,cAAc,EAAE,8BAA8B;IAC9C,eAAe,EAAE,4BAA4B;IAC7C,gBAAgB,EAAE,4BAA4B;IAC9C,eAAe,EAAE,6BAA6B;IAC9C,gBAAgB,EAAE,6BAA6B;IAC/C,kBAAkB,EAAE,gCAAgC;IACpD,WAAW,EAAE,mCAAmC;IAChD,iBAAiB,EAAE,mCAAmC;IACtD,sBAAsB,EAAE,0BAA0B;IAClD,cAAc,EAAE,0BAA0B;IAC1C,SAAS,EAAE,0BAA0B;CACtC,CAAA;AAKD,MAAM,oBAAoB,GAA2B;IACnD,0BAA0B,EAAE,kBAAkB;IAC9C,gCAAgC,EAAE,iBAAiB;IACnD,mCAAmC,EAAE,eAAe;IACpD,qCAAqC,EAAE,sBAAsB;IAC7D,8CAA8C,EAAE,sBAAsB;IACtE,8BAA8B,EAAE,gBAAgB;IAChD,4BAA4B,EAAE,aAAa;IAC3C,6BAA6B,EAAE,YAAY;IAC3C,6BAA6B,EAAE,cAAc;IAC7C,0BAA0B,EAAE,iBAAiB;IAC7C,+BAA+B,EAAE,cAAc;IAC/C,gCAAgC,EAAE,cAAc;IAChD,uCAAuC,EAAE,UAAU;IACnD,mCAAmC,EAAE,UAAU;IAC/C,qCAAq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C,UAAU,MAAM,EAAE,CAAC,CAAA;QAC/B,CAAC;QAGD,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,aAAa,EAAE,CAAA;QAC3C,MAAM,aAAa,GAAG,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAA;QAC1D,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,aAAa,EAAE,MAAM,CAAC,CAAA;QAExD,IAAI,CAAC,IAAI,CAAC,cAAc,gBAAgB,CAAC,MAAM,MAAM,CAAC,CAAA;QAEtD,OAAO;YACL,OAAO,EAAE,IAAI;YACb,IAAI;YACJ,IAAI,EAAE;gBACJ,KAAK,EAAE,gBAAgB,CAAC,MAAM;gBAC9B,OAAO,EAAE,iBAAiB,CAAC,IAAI,GAAG,gBAAgB,CAAC,MAAM;aAC1D;SACF,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAC3E,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,iBAAiB,YAAY,EAAE;YACtC,IAAI;SACL,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UniAppAndroidBuildOptions, UniAppAndroidBuildResult } from '../../../../types/uniapp-android-build.d';
|
|
2
|
-
import type { FileSystem, Path, ChildProcess } from '../../../../references/node.d';
|
|
2
|
+
import type { FileSystem, Path, ChildProcess, BufferConstructor } from '../../../../references/node.d';
|
|
3
3
|
import type { XMLParserConstructor, XMLSerializerConstructor } from '../../../../references/xml.d';
|
|
4
4
|
import type { JSON5Parser } from '../../../../references/json5.d';
|
|
5
5
|
import type { XPath } from '../../../../references/xpath.d';
|
|
@@ -25,6 +25,7 @@ export interface BuildAndroidAppDeps {
|
|
|
25
25
|
xpath: XPath;
|
|
26
26
|
setTimeout: typeof setTimeout;
|
|
27
27
|
sharp?: Sharp;
|
|
28
|
+
Buffer?: BufferConstructor;
|
|
28
29
|
}
|
|
29
30
|
export declare function buildAndroidApp(options: UniAppAndroidBuildOptions, deps: BuildAndroidAppDeps): Promise<UniAppAndroidBuildResult>;
|
|
30
31
|
export { buildAndroidPlugin } from './buildAndroidPlugin';
|