Skip to content

Commit

Permalink
feat: optimize UI styles and UX effects to enhance user immersion
Browse files Browse the repository at this point in the history
pnpm tauri add process
  • Loading branch information
swordtraveller committed Jan 11, 2025
1 parent 2779a8f commit dcd6efc
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@tauri-apps/plugin-dialog": "~2",
"@tauri-apps/plugin-log": "~2",
"@tauri-apps/plugin-opener": "^2",
"@tauri-apps/plugin-process": "~2",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.2"
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

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

11 changes: 11 additions & 0 deletions src-tauri/Cargo.lock

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

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
tauri-plugin-log = "2"
tauri-plugin-dialog = "2"
tauri-plugin-process = "2"

6 changes: 5 additions & 1 deletion src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
],
"permissions": [
"core:default",
"core:window:allow-maximize",
"core:window:allow-unmaximize",
"core:window:allow-minimize",
"opener:default",
"log:default",
"dialog:default"
"dialog:default",
"process:default"
]
}
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ fn greet(name: &str) -> String {
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_log::Builder::new().build())
.plugin(tauri_plugin_opener::init())
Expand Down
1 change: 1 addition & 0 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"windows": [
{
"title": "pocketplayer",
"decorations": false,
"width": 800,
"height": 600
}
Expand Down
7 changes: 6 additions & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<mat-grid-tile
colspan="1"
rowspan="1"
(mouseenter)="handleMouseEnterButton()"
(mouseleave)="handleMouseLeaveButton()"
[ngStyle]="{ 'background-color': bgColor }"
>
<button
Expand All @@ -18,6 +20,7 @@
</button>
<button
mat-icon-button
(click)="handleMinimizeWindowButton()"
[ngStyle]="{ 'color': fgColor, 'background-color': bgColor, 'border-width': 0 }"
>
<mat-icon>
Expand All @@ -26,6 +29,7 @@
</button>
<button
mat-icon-button
(click)="handleMaximizeWindowButton()"
[ngStyle]="{ 'color': fgColor, 'background-color': bgColor, 'border-width': 0 }"
>
<mat-icon>
Expand All @@ -34,6 +38,7 @@
</button>
<button
mat-icon-button
(click)="handleExitAppButton()"
[ngStyle]="{ 'color': fgColor, 'background-color': bgColor, 'border-width': 0 }"
>
<mat-icon>
Expand All @@ -47,7 +52,7 @@
[ngStyle]="{ 'background-color': bgColor }"
>
<video
[src]="video_path"
[src]="videoPath"
controls
autoplay
(pause)="handleVideoPause()"
Expand Down
44 changes: 42 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { RouterOutlet } from '@angular/router';
import { MatIconModule } from '@angular/material/icon';
import { MatGridListModule } from '@angular/material/grid-list';
import { invoke, convertFileSrc } from "@tauri-apps/api/core";
import { getCurrentWindow } from '@tauri-apps/api/window';
import { trace, info, error, attachConsole } from '@tauri-apps/plugin-log';
import { open as openDialog } from '@tauri-apps/plugin-dialog';
import { exit, relaunch } from '@tauri-apps/plugin-process';

@Component({
selector: 'app-root',
Expand All @@ -24,11 +26,13 @@ import { open as openDialog } from '@tauri-apps/plugin-dialog';
})
export class AppComponent {

video_path = "";
videoPath = "";
blackHexString = "#000000";
whiteHexString = "#ffffff";
fgColor = this.blackHexString;
bgColor = this.whiteHexString;
isMaximized = false;
isFileOpen = false;

handleOpenVideoFileButton() {
info("OpenVideoFileButton is clicked.");
Expand All @@ -42,7 +46,8 @@ export class AppComponent {
const path = this.normalizePathString(file.toString());
info("The file selected by the user is: " + path);
// https://v2.tauri.app/reference/javascript/api/namespacecore/#convertfilesrc
this.video_path = convertFileSrc(path);
this.videoPath = convertFileSrc(path);
this.isFileOpen = true;
this.bgColor = this.blackHexString;
this.fgColor = this.whiteHexString;
}
Expand All @@ -61,6 +66,41 @@ export class AppComponent {
this.fgColor = this.blackHexString;
}

async handleMinimizeWindowButton() {
info("User minimized the window");
await getCurrentWindow().minimize();
}

async handleMaximizeWindowButton() {
info("User maximized the window");
if (this.isMaximized) {
await getCurrentWindow().unmaximize();
this.isMaximized = false;
} else {
await getCurrentWindow().maximize();
this.isMaximized = true;
}
}

async handleExitAppButton() {
info("User exit the app");
await exit(0);
}

handleMouseEnterButton() {
info("mouse entered.");
if (this.isFileOpen) {
this.fgColor = this.whiteHexString;
}
}

handleMouseLeaveButton() {
info("mouse left.");
if (this.isFileOpen) {
this.fgColor = this.blackHexString;
}
}

normalizePathString = (path: string) => {
// remove quotation marks from both ends of a string
if (path.startsWith('"')) {
Expand Down

0 comments on commit dcd6efc

Please sign in to comment.