Skip to content

Commit ed84cff

Browse files
committed
Add lyswhut.AnyListen
1 parent 1458a8d commit ed84cff

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Type: PackageTask
2+
WinGetIdentifier: lyswhut.AnyListen
3+
Skip: false

Tasks/lyswhut.AnyListen/Script.ps1

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
$Object1 = Invoke-GitHubApi -Uri 'https://api.github.com/repos/any-listen/any-listen-desktop/releases/latest'
2+
3+
# Version
4+
$this.CurrentState.Version = $Object1.tag_name -replace '^v'
5+
6+
# Installer
7+
$this.CurrentState.Installer += [ordered]@{
8+
Architecture = 'x64'
9+
InstallerUrl = $Object1.assets.Where({ $_.name.EndsWith('.exe') -and $_.name.Contains('x64') -and $_.name -match 'Setup' }, 'First')[0].browser_download_url | ConvertTo-UnescapedUri
10+
}
11+
$this.CurrentState.Installer += [ordered]@{
12+
Architecture = 'arm64'
13+
InstallerUrl = $Object1.assets.Where({ $_.name.EndsWith('.exe') -and $_.name.Contains('arm64') -and $_.name -match 'Setup' }, 'First')[0].browser_download_url | ConvertTo-UnescapedUri
14+
}
15+
16+
switch -Regex ($this.Check()) {
17+
'New|Changed|Updated' {
18+
try {
19+
# ReleaseTime
20+
$this.CurrentState.ReleaseTime = $Object1.published_at.ToUniversalTime()
21+
22+
if (-not [string]::IsNullOrWhiteSpace($Object1.body)) {
23+
$ReleaseNotesObject = $Object1.body | Convert-MarkdownToHtml -Extensions 'advanced', 'emojis', 'hardlinebreak'
24+
$ReleaseNotesCNTitleNode = $ReleaseNotesObject.SelectSingleNode('./hr')
25+
if ($ReleaseNotesCNTitleNode) {
26+
$ReleaseNotesNodes = for ($Node = $ReleaseNotesObject.ChildNodes[0]; $Node -and $Node.Name -ne 'hr' -and -not ($Node.Name -match 'h\d' -and $Node.InnerText -match 'SHA256'); $Node = $Node.NextSibling) { $Node }
27+
# ReleaseNotes (en-US)
28+
$this.CurrentState.Locale += [ordered]@{
29+
Locale = 'en-US'
30+
Key = 'ReleaseNotes'
31+
Value = $ReleaseNotesNodes | Get-TextContent | Format-Text
32+
}
33+
$ReleaseNotesCNNodes = for ($Node = $ReleaseNotesCNTitleNode.NextSibling; $Node -and -not ($Node.Name -match 'h\d' -and $Node.InnerText -match 'SHA256'); $Node = $Node.NextSibling) { $Node }
34+
# ReleaseNotes (zh-CN)
35+
$this.CurrentState.Locale += [ordered]@{
36+
Locale = 'zh-CN'
37+
Key = 'ReleaseNotes'
38+
Value = $ReleaseNotesCNNodes | Get-TextContent | Format-Text
39+
}
40+
} else {
41+
$this.Log("No ReleaseNotes (zh-CN) for version $($this.CurrentState.Version)", 'Warning')
42+
$ReleaseNotesNodes = for ($Node = $ReleaseNotesObject.ChildNodes[0]; $Node -and -not ($Node.Name -match 'h\d' -and $Node.InnerText -match 'SHA256'); $Node = $Node.NextSibling) { $Node }
43+
# ReleaseNotes (en-US)
44+
$this.CurrentState.Locale += [ordered]@{
45+
Locale = 'en-US'
46+
Key = 'ReleaseNotes'
47+
Value = $ReleaseNotesNodes | Get-TextContent | Format-Text
48+
}
49+
}
50+
} else {
51+
$this.Log("No ReleaseNotes (en-US) and ReleaseNotes (zh-CN) for version $($this.CurrentState.Version)", 'Warning')
52+
}
53+
54+
# ReleaseNotesUrl (en-US)
55+
$this.CurrentState.Locale += [ordered]@{
56+
Locale = 'en-US'
57+
Key = 'ReleaseNotesUrl'
58+
Value = $Object1.html_url
59+
}
60+
} catch {
61+
$_ | Out-Host
62+
$this.Log($_, 'Warning')
63+
}
64+
65+
$this.Print()
66+
$this.Write()
67+
}
68+
'Changed|Updated' {
69+
$this.Message()
70+
}
71+
'Updated' {
72+
$this.Submit()
73+
}
74+
}

0 commit comments

Comments
 (0)