Skip to content

Commit

Permalink
feature: splashscreen (#36)
Browse files Browse the repository at this point in the history
* feat: move all pages to app folder, add splashscreen

* feat: use Dance as splashscreen

* feat: add zoom in for splashscreen logo

* refactor: move svelte files into app folder

* fix: url prefix with /app

* refactor: remove platform-specific tauri conf

Merge windows back to main tauri config. The reason I separated them was
because I need decoration: true on mac and false on windows and linux.
Now I use tauri rust API to set decorations to false for win and linux.
  • Loading branch information
HuakunShen authored Dec 21, 2024
1 parent 80ad705 commit caa252b
Show file tree
Hide file tree
Showing 57 changed files with 437 additions and 390 deletions.
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main*"],
"windows": ["main*", "splashscreen"],
"permissions": [
{
"identifier": "http:default",
Expand Down
16 changes: 14 additions & 2 deletions apps/desktop/src-tauri/src/setup/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,19 @@ impl<R: Runtime> WindowExt for WebviewWindow<R> {
}

pub fn setup_window<R: Runtime>(app: &AppHandle<R>) {
let window = app.get_webview_window("main").unwrap();
#[cfg(target_os = "macos")]
window.set_transparent_titlebar(true, true);
{
let main_win = app.get_webview_window("main").unwrap();
main_win.set_transparent_titlebar(true, true);
let splashscreen_win = app.get_webview_window("splashscreen").unwrap();
splashscreen_win.set_transparent_titlebar(true, true);
}
#[cfg(not(target_os = "macos"))]
{
// on linux or windows, set decorations to false
let main_win = app.get_webview_window("main").unwrap();
main_win
.set_decorations(false)
.expect("Failed to set decorations");
}
}
18 changes: 17 additions & 1 deletion apps/desktop/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,23 @@
"macOSPrivateApi": true,
"security": {
"csp": null
}
},
"windows": [
{
"hiddenTitle": true,
"url": "/app",
"title": "Kunkun",
"width": 800,
"visible": false,
"height": 600,
"decorations": true
},
{
"url": "/splashscreen",
"visible": false,
"label": "splashscreen"
}
]
},
"bundle": {
"createUpdaterArtifacts": true,
Expand Down
14 changes: 0 additions & 14 deletions apps/desktop/src-tauri/tauri.linux.conf.json

This file was deleted.

13 changes: 0 additions & 13 deletions apps/desktop/src-tauri/tauri.macos.conf.json

This file was deleted.

14 changes: 0 additions & 14 deletions apps/desktop/src-tauri/tauri.windows.conf.json

This file was deleted.

48 changes: 32 additions & 16 deletions apps/desktop/src/lib/cmds/builtin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { derived } from "svelte/store"
import * as clipboard from "tauri-plugin-clipboard-api"
import { open } from "tauri-plugin-shellx-api"
import { v4 as uuidv4 } from "uuid"
import { hexColor } from "valibot"

export const rawBuiltinCmds: BuiltinCmd[] = [
{
Expand All @@ -25,7 +24,7 @@ export const rawBuiltinCmds: BuiltinCmd[] = [
description: "Go to Extension Store",
function: async () => {
appState.clearSearchTerm()
goto("/extension/store")
goto("/app/extension/store")
}
},
{
Expand All @@ -36,7 +35,7 @@ export const rawBuiltinCmds: BuiltinCmd[] = [
},
description: "",
function: async () => {
goto("/auth")
goto("/app/auth")
}
},
{
Expand Down Expand Up @@ -73,6 +72,23 @@ export const rawBuiltinCmds: BuiltinCmd[] = [
}, 2_000)
}
},
{
name: "Splashscreen (Dev)",
icon: {
type: IconEnum.Iconify,
value: "material-symbols:skeleton"
},
description: "",
flags: {
dev: true
},
function: async () => {
new WebviewWindow(`splashscreen`, {
url: "/splashscreen"
})
appState.clearSearchTerm()
}
},
{
name: "File Transfer",
icon: {
Expand All @@ -81,7 +97,7 @@ export const rawBuiltinCmds: BuiltinCmd[] = [
},
description: "",
function: async () => {
goto("/extension/file-transfer")
goto("/app/extension/file-transfer")
appState.clearSearchTerm()
}
},
Expand All @@ -95,7 +111,7 @@ export const rawBuiltinCmds: BuiltinCmd[] = [
description: "",
function: async () => {
appState.clearSearchTerm()
goto("/settings/add-dev-extension")
goto("/app/settings/add-dev-extension")
}
},
{
Expand All @@ -120,7 +136,7 @@ export const rawBuiltinCmds: BuiltinCmd[] = [
function: async () => {
// const appStateStore = useAppStateStore()
appState.clearSearchTerm()
goto("/settings/set-dev-ext-path")
goto("/app/settings/set-dev-ext-path")
}
},
{
Expand All @@ -132,11 +148,11 @@ export const rawBuiltinCmds: BuiltinCmd[] = [
description: "",
function: async () => {
appState.clearSearchTerm()
// goto("/window-troubleshooter")
// goto("/app/window-troubleshooter")
const winLabel = `main:extension-window-troubleshooter-${uuidv4()}`
console.log(winLabel)
new WebviewWindow(winLabel, {
url: "/troubleshooters/extension-window",
url: "/app/troubleshooters/extension-window",
title: "Extension Window Troubleshooter"
})
},
Expand All @@ -151,7 +167,7 @@ export const rawBuiltinCmds: BuiltinCmd[] = [
description: "",
function: async () => {
appState.clearSearchTerm()
goto("/extension/permission-inspector")
goto("/app/extension/permission-inspector")
},
keywords: ["extension"]
},
Expand All @@ -164,7 +180,7 @@ export const rawBuiltinCmds: BuiltinCmd[] = [
description: "",
function: async () => {
appState.clearSearchTerm()
goto("/troubleshooters/extension-loading")
goto("/app/troubleshooters/extension-loading")
},
keywords: ["extension", "troubleshooter"]
},
Expand All @@ -177,7 +193,7 @@ export const rawBuiltinCmds: BuiltinCmd[] = [
description: "Create a Quicklink",
function: async () => {
appState.clearSearchTerm()
goto("/extension/create-quick-link")
goto("/app/extension/create-quick-link")
}
},
{
Expand All @@ -188,7 +204,7 @@ export const rawBuiltinCmds: BuiltinCmd[] = [
},
description: "Open Settings",
function: async () => {
goto("/settings")
goto("/app/settings")
appState.clearSearchTerm()
}
},
Expand Down Expand Up @@ -248,7 +264,7 @@ export const rawBuiltinCmds: BuiltinCmd[] = [
},
description: "Dance",
function: async () => {
goto("/dance")
goto("/app/dance")
}
},
{
Expand Down Expand Up @@ -289,7 +305,7 @@ export const rawBuiltinCmds: BuiltinCmd[] = [
description: "Clipboard History",
function: async () => {
appState.clearSearchTerm()
goto("/extension/clipboard")
goto("/app/extension/clipboard")
}
},
{
Expand All @@ -306,7 +322,7 @@ export const rawBuiltinCmds: BuiltinCmd[] = [
return
}
const window = new WebviewWindow(`main:pinned-screenshot-${uuidv4()}`, {
url: "/extension/pin-screenshot",
url: "/app/extension/pin-screenshot",
title: "Pinned Screenshot",
hiddenTitle: true,
titleBarStyle: "transparent",
Expand All @@ -326,7 +342,7 @@ export const rawBuiltinCmds: BuiltinCmd[] = [
},
description: "MDNS Debugger",
function: async () => {
goto("/troubleshooters/mdns-debugger")
goto("/app/troubleshooters/mdns-debugger")
},
flags: {
developer: true
Expand Down
8 changes: 4 additions & 4 deletions apps/desktop/src/lib/cmds/ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function onTemplateUiCmdSelect(
) {
await createExtSupportDir(ext.extPath)
// console.log("onTemplateUiCmdSelect", ext, cmd, isDev, hmr)
const url = `/extension/ui-worker?extPath=${encodeURIComponent(ext.extPath)}&cmdName=${encodeURIComponent(cmd.name)}`
const url = `/app/extension/ui-worker?extPath=${encodeURIComponent(ext.extPath)}&cmdName=${encodeURIComponent(cmd.name)}`
if (cmd.window) {
const winLabel = await winExtMap.registerExtensionWithWindow({ extPath: ext.extPath })
const window = launchNewExtWindow(winLabel, url, cmd.window)
Expand Down Expand Up @@ -52,7 +52,7 @@ export async function onCustomUiCmdSelect(
} else {
url = decodeURIComponent(convertFileSrc(`${trimSlash(cmd.main)}`, "ext"))
}
let url2 = `/extension/ui-iframe?url=${encodeURIComponent(url)}&extPath=${encodeURIComponent(ext.extPath)}`
let url2 = `/app/extension/ui-iframe?url=${encodeURIComponent(url)}&extPath=${encodeURIComponent(ext.extPath)}`
if (cmd.window) {
const winLabel = await winExtMap.registerExtensionWithWindow({
extPath: ext.extPath,
Expand All @@ -61,7 +61,7 @@ export async function onCustomUiCmdSelect(
if (platform() === "windows" && !useDevMain) {
const addr = await spawnExtensionFileServer(winLabel)
const newUrl = `http://${addr}`
url2 = `/extension/ui-iframe?url=${encodeURIComponent(newUrl)}&extPath=${encodeURIComponent(ext.extPath)}`
url2 = `/app/extension/ui-iframe?url=${encodeURIComponent(newUrl)}&extPath=${encodeURIComponent(ext.extPath)}`
}
const window = launchNewExtWindow(winLabel, url2, cmd.window)
window.onCloseRequested(async (event) => {
Expand All @@ -78,7 +78,7 @@ export async function onCustomUiCmdSelect(
const addr = await spawnExtensionFileServer(winLabel) // addr has format "127.0.0.1:<port>"
console.log("Extension file server address: ", addr)
const newUrl = `http://${addr}`
url2 = `/extension/ui-iframe?url=${encodeURIComponent(newUrl)}&extPath=${encodeURIComponent(ext.extPath)}`
url2 = `/app/extension/ui-iframe?url=${encodeURIComponent(newUrl)}&extPath=${encodeURIComponent(ext.extPath)}`
}
goto(url2)
}
Expand Down
8 changes: 6 additions & 2 deletions apps/desktop/src/lib/components/dance/dance.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { cn } from "@/utils"
import { GridAnimation } from "@kksh/ui"
import { decompressFrame, decompressString, deserializeFrame } from "@kksh/utils"
import compressedDance from "$lib/../data/dance.bin?raw"
Expand All @@ -7,11 +8,14 @@
const { fps, frames: rawFrames }: { fps: number; frames: string[] } = rawData
const decodedFrames = rawFrames.map((frame) => deserializeFrame(decompressFrame(frame)))
let { scale = 1 } = $props()
let { scale = 1, class: className }: { scale?: number; class?: string } = $props()
</script>

<GridAnimation
class="pointer-events-none max-h-full max-w-full select-none invert dark:invert-0"
class={cn(
"pointer-events-none max-h-full max-w-full select-none invert dark:invert-0",
className
)}
{fps}
frames={decodedFrames}
{scale}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
async function pickExtFiles() {
if (!$appConfig.devExtensionPath) {
toast.warning("Please set the dev extension path in the settings")
return goto("/settings/set-dev-ext-path")
return goto("/app/settings/set-dev-ext-path")
}
const selected = await openFileSelector({
directory: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
toast.warning(
"Please set the dev extension path in the settings to install tarball extension"
)
return goto("/settings/set-dev-ext-path")
return goto("/app/settings/set-dev-ext-path")
}
await extensions
.installFromNpmPackageName(data.name, $appConfig.devExtensionPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
toast.warning(
"Please set the dev extension path in the settings to install tarball extension"
)
return goto("/settings/set-dev-ext-path")
return goto("/app/settings/set-dev-ext-path")
}
await extensions
.installFromTarballUrl(data.url, $appConfig.devExtensionPath)
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/utils/deeplink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function handleKunkunProtocol(parsedUrl: URL) {
if (parsed.identifier) {
goto(`/extension/store/${parsed.identifier}`)
} else {
goto("/extension/store")
goto("/app/extension/store")
}
} else if (href.startsWith(DEEP_LINK_PATH_REFRESH_DEV_EXTENSION)) {
emitRefreshDevExt()
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/utils/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export async function globalKeyDownHandler(e: KeyboardEvent) {
if ((_platform === "macos" && e.metaKey) || (_platform === "windows" && e.ctrlKey)) {
if (e.key === ",") {
e.preventDefault()
goto("/settings")
goto("/app/settings")
}
}
// Toggle Devtools with control + shift + I
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/utils/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function goBack() {
}

export function goHome() {
goto("/")
goto("/app/")
}

export function goHomeOrCloseDependingOnWindow() {
Expand Down
Loading

0 comments on commit caa252b

Please sign in to comment.