Skip to content

Commit

Permalink
准备生成第一个安装包
Browse files Browse the repository at this point in the history
  • Loading branch information
zerofancy committed Aug 10, 2024
1 parent 430e63c commit 903077f
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 35 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# ZDesktopManager

> 通过 `pandoc .\README.md -o README.pdf --pdf-engine=xelatex -V CJKmainfont=KaiTi` 将文件转换为pdf,需要 `winget install MiKTex`
一个简单的桌面管理工具,目前功能比较简陋。

这是中文。
## 技术和依赖

虽然使用Compose Desktop开发,但因为功能特性不可避免用了一些Win32 API,因此只能在Windows下运行。目前仅测试过Windows 11。

## 目标和进度

- [x] 嵌入Windows11桌面
- [x] 图标显示和点击
- [x] 桌面文件监听
- [ ] 文件拖放支持
- [ ] 卡片大小、样式自定义
37 changes: 24 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,29 @@ version = "1.0-SNAPSHOT"
tasks.register("buildGuidePdf") {
val mdFile = project.file("docs/guide/Guide.md")
val generatedResources = project.file("build/generated/resources")
generatedResources.deleteRecursively()
generatedResources.mkdirs()
val outputFile = File(generatedResources, "Guide.pdf")
val guideDir = File(generatedResources, "guide")
val outputFile = File(guideDir, "Guide.pdf")

val command = arrayOf("pandoc", mdFile.absolutePath, "-o" , outputFile.absolutePath, "--pdf-engine=xelatex", "-V", "CJKmainfont=KaiTi")
println(command.joinToString(" "))
val process = ProcessBuilder(*command)
.start()
process.waitFor()
process.inputStream.readAllBytes().decodeToString().let(::println)
process.errorStream.readAllBytes().decodeToString().let(::println)
println("finish")
doLast {
if (mdFile.exists().not()) {
logger.log(LogLevel.WARN, "mdFile not exist, please create $mdFile.")
} else if (outputFile.exists() && outputFile.lastModified() > mdFile.lastModified()) {
logger.log(LogLevel.INFO, "Guide.pdf is UPDATE TO DATE.")
} else {
logger.log(LogLevel.INFO, "Guide.pdf not found, generating it.")
generatedResources.deleteRecursively()
generatedResources.mkdirs()
guideDir.mkdirs()
val command = arrayOf("pandoc", mdFile.absolutePath, "-o" , outputFile.absolutePath, "--pdf-engine=xelatex", "-V", "CJKmainfont=KaiTi")
println(command.joinToString(" "))
val process = ProcessBuilder(*command)
.directory(mdFile.parentFile)
.start()
process.waitFor()
process.inputStream.readAllBytes().decodeToString().let(::println)
process.errorStream.readAllBytes().decodeToString().let(::println)
}
}
}

tasks.withType<ProcessResources> {
Expand Down Expand Up @@ -66,14 +77,14 @@ compose.desktop {

nativeDistributions {
targetFormats(TargetFormat.Msi, TargetFormat.Exe)
packageVersion = "1.3.2"
packageVersion = "1.4.0"
description = "A simple Windows desktop workspace manager."

windows {
packageName = "top_ntutn_ZDesktopManager"
dirChooser = true
menuGroup = "ntutn"
upgradeUuid = "805a7041-2df5-40b5-96a4-2302b356ea45" // generate with https://www.guidgen.com
upgradeUuid = "a2fde22b-ec5f-49e4-b63f-a4235ef4848c" // generate with https://www.guidgen.com
// licenseFile.set(project.file("LICENSE.txt")) // 不能显示中文
}
}
Expand Down
25 changes: 23 additions & 2 deletions docs/guide/Guide.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# ZDesktopManager - 桌面管理工具
# ZDesktopManager - 桌面管理工具使用向导

这是一个桌面管理工具。
ZDesktopManager是一个试图模仿[Fences](https://www.stardock.com/products/fences/)[Portals](https://portals-app.com/) 的桌面管理工具,可以在你的桌面上添加数个窗格,展示你的桌面文件夹内容,便于随时访问和点击。

![ZDesktopManager桌面截图](screenshot1.png "桌面截图1")

与同类软件相比,ZDesktopManager有以下特点:

1. 更少的功能
2. Kotlin/JVM + Compose Desktop实现,占用更多内存
3. 维护者只有一个人,全凭兴趣,随时跑路
4. 开源

是的,现在各方面都比不上同类软件,因为这个工具的开发全凭个人兴趣,因为我买不起Fences。

## 简单使用

在桌面上创建数个文件夹并重命名为“娱乐”、“游戏”等,将你的桌面图标放到这些文件夹中,随后这些文件夹会以卡片的形式出现在桌面。你可以直接双击打开这些图标对应文件或应用。

## 支持和更新

所有代码开源在Github,有任何问题和建议可以提Issue讨论,欢迎Star和Pr。

[https://github.com/zerofancy/ZDesktopManager](https://github.com/zerofancy/ZDesktopManager)
Binary file added docs/guide/screenshot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
kotlin.code.style=official
kotlin.version=2.0.0
compose.version=1.6.10
compose.version=1.6.11
47 changes: 31 additions & 16 deletions src/main/kotlin/top/ntutn/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import java.awt.Dimension
import java.awt.Toolkit
import java.awt.Window
import java.io.File
import kotlin.system.exitProcess

object App

Expand All @@ -36,24 +37,29 @@ fun main() {
val desktopDir = Shell32Util.getSpecialFolderPath(ShlObj.CSIDL_DESKTOP, false).let(::File)
val subDirs = desktopDir.listFiles { file -> file.isDirectory }?.toMutableList() ?: mutableListOf()

// todo 移动到合适位置
val outputFile = File(desktopDir, "Guide.pdf")
if (!outputFile.exists()) {
val classLoader = App::class.java.classLoader
classLoader.getResourceAsStream("Guide.pdf")?.use { ins ->
outputFile.outputStream().use { ous ->
ins.copyTo(ous)
}
}
}

if (subDirs.isEmpty()) {
val demoDir = File(desktopDir, "ZDesktop")
demoDir.mkdir()
// todo 插入一篇说明文档
subDirs.add(demoDir)
JNAMessageBox.builder {
content("桌面上没有任何文件夹,是否要创建示例?", "ZDesktopManager")
questionIcon()
yesNo(yesCallback = {
val demoDir = File(desktopDir, "ZDesktop")
demoDir.mkdir()
subDirs.add(demoDir)

val outputFile = File(demoDir, "Guide.pdf")
if (!outputFile.exists()) {
val classLoader = App::class.java.classLoader
classLoader.getResourceAsStream("guide/Guide.pdf")?.use { ins ->
outputFile.outputStream().use { ous ->
ins.copyTo(ous)
}
}
}
}, noCallback = {
exitProcess(0)
})
}.build().showSync()
}
println(subDirs.joinToString())

val dimension: Dimension = Toolkit.getDefaultToolkit().screenSize

Expand All @@ -64,6 +70,15 @@ fun main() {
application {
val desktopChildrenDirs = remember { mutableStateListOf<File>(elements = subDirs.toTypedArray()) }

if (desktopChildrenDirs.isEmpty()) {
JNAMessageBox.builder {
content("桌面上不存在任何文件夹,管理工具即将退出。", "ZDesktopManager")
warningIcon()
buttonOk {
exitApplication()
}
}.build().showAsync()
}
var nextWindowTop = 16
var nextWindowRight = 16
desktopChildrenDirs.forEachIndexed { dirIndex, dir ->
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/top/ntutn/ui/JNAMessageBox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class JNAMessageBox {
building.iconFlags = IconFlags.NONE
}

fun questionIcon() = apply {
building.iconFlags = IconFlags.QUESTION
}

fun informationIcon() = apply {
building.iconFlags = IconFlags.INFORMATION
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/kotlin/top/ntutn/util/ApplicationUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ object ApplicationUtil {
val mutex = Kernel32.INSTANCE.CreateMutex(null, false, appName)
val timeOuted = Kernel32.INSTANCE.WaitForSingleObject(mutex, 10) == WinError.WAIT_TIMEOUT
val hasError = Kernel32.INSTANCE.GetLastError() != 0
return !(timeOuted || hasError)
val addedMutex = !(timeOuted || hasError)
if (addedMutex) {
Runtime.getRuntime().addShutdownHook(Thread {
Kernel32.INSTANCE.ReleaseMutex(mutex)
})
}
return addedMutex
}
}

0 comments on commit 903077f

Please sign in to comment.