Skip to content

Commit

Permalink
Merge pull request #5 from fksms/i18n
Browse files Browse the repository at this point in the history
Supported i18n
  • Loading branch information
fksms authored Jan 21, 2025
2 parents cf08359 + 6648989 commit 7fdb5dc
Show file tree
Hide file tree
Showing 16 changed files with 343 additions and 92 deletions.
71 changes: 71 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@tauri-apps/plugin-shell": "^2.2.0",
"d3": "^7.9.0",
"vue": "^3.5.12",
"vue-i18n": "^11.0.1",
"vuetify": "^3.7.3"
},
"devDependencies": {
Expand All @@ -26,4 +27,4 @@
"vite": "^5.3.6",
"vite-plugin-vuetify": "^2.0.3"
}
}
}
19 changes: 15 additions & 4 deletions src-tauri/src/init_walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::dir_walker::WalkData;
use crate::node::Node;
use crate::progress::ErrorHandler;
use crate::progress::ProgressHandler;
use crate::progress::ORDERING;
use crate::progress::{indicator_spawn, indicator_stop};
use crate::utils::normalize_path;

Expand Down Expand Up @@ -90,11 +91,21 @@ pub fn init_walk(

// Progressを終了
indicator_stop(indicator_handler);
println!();

// WebViewに送信
app.emit("ProgressNotification", "Post-processing...".to_string())
.unwrap();
// ステータスを更新
let prog_data = progress.clone();
prog_data.scan_complete.store(true, ORDERING);

let encode_result: Result<String, _> = serde_json::to_string(&prog_data);
match encode_result {
// 正常にエンコードできた場合
Ok(str) => {
// WebViewに送信
app.emit("ProgressNotification", str).unwrap();
}
// エンコードに失敗した場合
Err(_) => println!("Progress encode error."),
}

// 強制終了
if errors_final.lock().unwrap().abort {
Expand Down
33 changes: 15 additions & 18 deletions src-tauri/src/progress.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use serde::Serialize;
use std::{
collections::HashSet,
io::Write,
sync::{
atomic::{AtomicU64, AtomicUsize, Ordering},
atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering},
mpsc::{self, RecvTimeoutError, Sender},
Arc,
},
Expand All @@ -19,16 +19,18 @@ pub const ORDERING: Ordering = Ordering::Relaxed;

/* -------------------------------------------------------------------------- */

#[derive(Default)]
#[derive(Default, Serialize)]
pub struct ProgressHandler {
pub num_files: AtomicUsize,
pub total_file_size: AtomicU64,
pub scan_complete: AtomicBool,
}

impl ProgressHandler {
pub fn clear_state(&self) {
self.total_file_size.store(0, ORDERING);
self.num_files.store(0, ORDERING);
self.scan_complete.store(false, ORDERING);
}
}

Expand All @@ -52,26 +54,21 @@ pub fn indicator_spawn(
let (sender, receiver) = mpsc::channel::<()>();

let indicator_thread = std::thread::spawn(move || {
let mut stdout = std::io::stdout();
let mut msg = "".to_string();

// While the timeout triggers we go round the loop
// If we disconnect or the sender sends its message we exit the while loop
while let Err(RecvTimeoutError::Timeout) =
receiver.recv_timeout(Duration::from_millis(INDICATOR_UPDATE_INTERVAL))
{
// Clear the text written by 'write!'& Return at the start of line
print!("\r{:width$}", " ", width = msg.len());

let file_count = prog_data.num_files.load(ORDERING);
let size_count = prog_data.total_file_size.load(ORDERING);
msg = format!("Scanned: {file_count} files, {size_count} bytes");

// WebViewに送信
app.emit("ProgressNotification", msg.clone()).unwrap();

write!(stdout, "\r{msg}").unwrap();
stdout.flush().unwrap();
let encode_result: Result<String, _> = serde_json::to_string(&prog_data);
match encode_result {
// 正常にエンコードできた場合
Ok(str) => {
// WebViewに送信
app.emit("ProgressNotification", str).unwrap();
}
// エンコードに失敗した場合
Err(_) => println!("Progress encode error."),
}
}
});

Expand Down
3 changes: 2 additions & 1 deletion src/components/ViewDirectoryFileList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { ref } from "vue";
import i18n from "./i18n";
import { detectOS } from "./DetectOS";
// 親から渡されたコンポーネントの参照を受け取る
Expand Down Expand Up @@ -53,7 +54,7 @@ function generateDirectoryList(node, option) {
});
ownColor.value = option.color;
ownName.value = option.title;
ownName.value = i18n.global.t("directory_file_list.small_size_items");
ownSize.value = array2String(toReadable(otherSize));
}
}
Expand Down
42 changes: 31 additions & 11 deletions src/components/ViewHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ref, onMounted } from "vue";
import { invoke } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event";
import i18n from "./i18n";
import { detectOS } from "./DetectOS";
import ViewSettings from "./dialog/ViewSettings.vue";
Expand Down Expand Up @@ -69,13 +70,17 @@ async function walkStart() {
// OS対象外の場合は終了
if (detectOS() == null) {
progressMessage.value = "OS Error";
progressMessage.value = i18n.global.t("progress_messages.os_error")
// ボタンの状態を戻す
buttonState.value = false;
return;
}
// ターゲットディレクトリ未設定の場合
if (walkParams.value.target_directory == "") {
progressMessage.value = "Please set the target directory.";
progressMessage.value = i18n.global.t("progress_messages.not_set_target")
// ボタンの状態を戻す
buttonState.value = false;
return;
}
Expand All @@ -87,39 +92,54 @@ async function walkStart() {
// Progressメッセージを受信するためのリスナーを起動
const unlisten = await listen("ProgressNotification", event => {
// 受信メッセージを格納
progressMessage.value = event.payload;
// デコード
const progressNotification = JSON.parse(event.payload)
// スキャン中
if (progressNotification.scan_complete == false) {
// スキャン済みのファイル総数
const numFiles = progressNotification.num_files;
// スキャン済みのファイル総サイズ
const totalFileSize = progressNotification.total_file_size;
progressMessage.value = `${i18n.global.t("progress_messages.scanned")} ${numFiles} files, ${totalFileSize} bytes`;
}
// スキャン完了、後処理に移行
else {
progressMessage.value = i18n.global.t("progress_messages.post_processing")
}
});
// バックエンド側の関数を実行
// スキャン実行
await invoke("walk_start", { str_params: JSON.stringify(walkParams.value) })
// 成功した場合
.then((success) => {
walkData = success;
})
// 失敗した場合
.catch((failure) => {
error = "Error: " + failure;
error = failure;
});
// リスナーを停止
unlisten();
// エラーが発生した場合
// エラーが発生した場合("walkData"がnull)
if (walkData == null) {
progressMessage.value = error;
progressMessage.value = `${i18n.global.t("progress_messages.scan_error")} ${error}`
}
// 強制終了した場合
// 強制終了した場合("walkData"が空)
else if (walkData == "") {
progressMessage.value = "Abort!";
progressMessage.value = i18n.global.t("progress_messages.aborted")
}
// 正常に受信できた場合
else {
// Sunburstの作成
await generateSunburst(JSON.parse(walkData));
progressMessage.value = "Completion!";
progressMessage.value = i18n.global.t("progress_messages.completed")
}
// ボタンの状態を戻す
Expand Down
17 changes: 9 additions & 8 deletions src/components/ViewSunburstChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { writeText } from "@tauri-apps/plugin-clipboard-manager";
import * as d3 from "d3";
import i18n from "./i18n";
// 親から渡されたコンポーネントの参照を受け取る
const props = defineProps(["viewDirectoryFileList", "viewBreadcrumbsList"]);
Expand Down Expand Up @@ -471,7 +473,6 @@ function updateArc(node, isFirstCalled) {
// リスト生成時のオプションを指定
const option = {
title: "Other small size items",
color: squashedColorCode,
threshold: value.head // リスト生成時の閾値
}
Expand Down Expand Up @@ -784,19 +785,19 @@ async function showContextMenu(node) {
// メニューアイテムの生成
const menuItems = [
await MenuItem.new({
text: "Copy path",
text: i18n.global.t("context_menu.copy_path"),
action: async () => {
await writeToClipboard(node.data.name);
},
}),
await MenuItem.new({
text: "Open",
text: i18n.global.t("context_menu.open"),
action: async () => {
await openFileManager(node.children ? node.data.name : node.parent.data.name);
},
}),
await MenuItem.new({
text: "Remove",
text: i18n.global.t("context_menu.remove"),
action: async () => {
await removeFileOrDirectory(node.data.name, node);
},
Expand Down Expand Up @@ -836,12 +837,12 @@ async function removeFileOrDirectory(path, node) {
let dialogMessage = "";
if (node.children) {
dialogTitle = "Remove Directory";
dialogMessage = "Are you sure you want to remove directory?" + "\n\n\n" + path + "\n";
dialogTitle = i18n.global.t("remove_alert.directory");
dialogMessage = i18n.global.t("remove_alert.directory_desc") + "\n\n\n" + path + "\n";
}
else {
dialogTitle = "Remove File";
dialogMessage = "Are you sure you want to remove file?" + "\n\n\n" + path + "\n";
dialogTitle = i18n.global.t("remove_alert.file");
dialogMessage = i18n.global.t("remove_alert.file_desc") + "\n\n\n" + path + "\n";
}
const result = await ask(dialogMessage, dialogTitle);
Expand Down
Loading

0 comments on commit 7fdb5dc

Please sign in to comment.