Skip to content

Commit

Permalink
chore:封面异常时也支持创建壁纸
Browse files Browse the repository at this point in the history
  • Loading branch information
GiantappMan committed Feb 6, 2024
1 parent 7b3771c commit ad214ac
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 33 deletions.
6 changes: 3 additions & 3 deletions src/giantapp-wallpaper-client/Client.Test/Client.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.0" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
4 changes: 2 additions & 2 deletions src/giantapp-wallpaper-client/Client/Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="HandyControl" Version="3.4.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2210.55" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2277.86" />
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.22621.2428" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
<PackageReference Include="MultiLanguageForXAML" Version="2.3.0.2" />
<PackageReference Include="NLog" Version="5.2.7" />
<PackageReference Include="NLog" Version="5.2.8" />
<PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.1" />
</ItemGroup>
<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions src/giantapp-wallpaper-client/Client/UI/ShellWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using Windows.UI.Xaml.Controls;

namespace GiantappWallpaper;

Expand Down Expand Up @@ -238,7 +237,7 @@ static bool CheckWebView2()
{
try
{
var version = CoreWebView2Environment.GetAvailableBrowserVersionString();
string version = CoreWebView2Environment.GetAvailableBrowserVersionString(null, new CoreWebView2EnvironmentOptions());
return true;
}
catch (WebView2RuntimeNotFoundException e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.0" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
14 changes: 9 additions & 5 deletions src/giantapp-wallpaper-client/WallpaperCore/WallpaperApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,18 @@ public static bool CreateWallpaper(Wallpaper wallpaper, string saveFolder)
//保存到目录
File.Copy(path, savePath);
}
//移动cover位置
string coverExtension = Path.GetExtension(cover);
string coverSavePath = Path.Combine(saveFolder, $"{saveFileName}.cover{coverExtension}");
File.Copy(cover, coverSavePath);

if (!string.IsNullOrEmpty(cover))
{
//移动cover位置
string coverExtension = Path.GetExtension(cover);
string coverSavePath = Path.Combine(saveFolder, $"{saveFileName}.cover{coverExtension}");
File.Copy(cover, coverSavePath);
wallpaper.Meta.Cover = $"{saveFileName}.cover{coverExtension}";
}

//保存meta
wallpaper.Meta.CreateTime = DateTime.Now;
wallpaper.Meta.Cover = $"{saveFileName}.cover{coverExtension}";
string metaJsonFile = Path.Combine(saveFolder, $"{saveFileName}.meta.json");
File.WriteAllText(metaJsonFile, JsonConvert.SerializeObject(wallpaper.Meta, JsonSettings));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<!--<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>-->
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NLog" Version="5.2.7" />
<PackageReference Include="NLog" Version="5.2.8" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/giantapp-wallpaper-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"next-themes": "^0.2.1",
"react": "^18",
"react-dom": "^18",
"react-hook-form": "^7.50.0",
"react-hook-form": "^7.50.1",
"sonner": "^1.4.0",
"tailwind-merge": "^2.2.1",
"tailwindcss-animate": "^1.0.7",
Expand Down
14 changes: 7 additions & 7 deletions src/giantapp-wallpaper-ui/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export function WallpaperDialog(props: WallpaperDialogProps) {
const [uploading, setUploading] = useState(false); //是否正在上传
const fileInputRef = useRef<HTMLInputElement>(null);
const inputRef = useRef<HTMLInputElement>(null);
const [loadVideoError, setLoadVideoError] = useState(false);
const previewVideoRef = useRef<HTMLVideoElement>(null);
const previewImgRef = useRef<HTMLImageElement>(null);
const [openSelectWallpaperDialog, setOpenSelectWallpaperDialog] = useState(false);
Expand Down Expand Up @@ -237,6 +238,7 @@ export function WallpaperDialog(props: WallpaperDialogProps) {
}, [form, props.open, props.wallpaper]);

const uploadFile = useCallback(async (file: File) => {
setLoadVideoError(false);
setProgress(0);
setImporting(true);
setImportedFile(undefined);
Expand Down Expand Up @@ -333,14 +335,22 @@ export function WallpaperDialog(props: WallpaperDialogProps) {
eHeight = previewElement?.videoHeight || 0;
}

const imgData = await generateCoverImage(previewElement, eWidth, eHeight);
//Blob转换成base64
const base64String = await getBase64FromBlob(imgData);
const fileName = importedFile.name.split(".")[0] + ".jpg";
var { data: coverUrl } = await api.uploadToTmp(fileName, base64String);
let coverUrl = null;
try {
const imgData = await generateCoverImage(previewElement, eWidth, eHeight);
//Blob转换成base64
const base64String = await getBase64FromBlob(imgData);
const fileName = importedFile.name.split(".")[0] + ".jpg";
var { data: tmpCoverUrl } = await api.uploadToTmp(fileName, base64String);
coverUrl = tmpCoverUrl;
} catch (e) {
console.error(e);
toast.error("生成封面失败");
}
var wallpaper = new Wallpaper({
...props.wallpaper,
});

wallpaper.meta.title = data.title;
wallpaper.meta.type = WallpaperType.Video;//todo 更细节的判断
wallpaper.coverUrl = coverUrl || "";
Expand Down Expand Up @@ -510,22 +520,38 @@ export function WallpaperDialog(props: WallpaperDialogProps) {
<div className="flex justify-between items-center text-[#9CA3AF]">
<div>
<div className="flex justify-between items-center">
<p>{importedFile.name}</p> <Button type="button" variant="ghost" onClick={() => {
<p>{importedFile.name}</p>
<Button type="button" variant="ghost" onClick={() => {
setImportedFile(undefined);
// if (fileInputRef.current)
// fileInputRef.current.value = '';
if (fileInputRef.current)
fileInputRef.current.value = '';
form.setValue("file", undefined);
}}>
<DeleteIcon className="h-6 w-6" />
</Button>
</div>
{
importedFile.fileType === "video" && <video
onError={(e) => console.error('Video loading error:', e)}
onError={(e) => {
console.error('Video loading error:', e);
setLoadVideoError(true);
}}
autoPlay={true} ref={previewVideoRef} className="object-contain">
<source src={importedFile.url} />
</video>
}
{
loadVideoError &&
<button onClick={() => {
// setLoadVideoError(false);
// setImportedFile({
// ...importedFile,
// url: importedFile.url + "?t=" + Date.now()
// })
}}>
加载视频失败,请重试
</button>
}
{
importedFile.fileType === "img" &&
<picture>
Expand Down

0 comments on commit ad214ac

Please sign in to comment.