Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src-tauri/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
fn main() {
#[cfg(target_os = "windows")]
{
let profile = std::env::var("PROFILE").unwrap_or_default();
let mut windows = tauri_build::WindowsAttributes::new();
// リリースビルドのみ requireAdministrator マニフェストを適用する。
// デバッグビルドで適用すると `cargo run` が os error 740 で失敗するため。
if profile == "release" {
windows = windows.app_manifest(include_str!("locksun.exe.manifest"));
}
let attrs = tauri_build::Attributes::new().windows_attributes(windows);
tauri_build::try_build(attrs).expect("failed to run tauri-build");
return;
}
tauri_build::build();
}
28 changes: 28 additions & 0 deletions src-tauri/locksun.exe.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 / Windows 11 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
</application>
</compatibility>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
8 changes: 3 additions & 5 deletions src-tauri/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ use crate::{
};
use chrono::Local;
use serde::{Deserialize, Serialize};
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use tauri::State;
use tokio::sync::Notify;

/// アプリ共有状態
pub struct AppState {
pub update_notify: Arc<Notify>,
/// 権限エラー通知済みフラグ(重複通知を防ぐ)
pub permission_notified: Mutex<bool>,
}

/// 設定を取得する
Expand Down Expand Up @@ -93,7 +91,7 @@ pub async fn preview_image_enhanced() -> Result<String, String> {
};

// Gemini AI 強化
let enhanced = crate::gemini::enhance_image(&cfg.gemini, &pos, &png_bytes)
let enhanced = crate::gemini::enhance_image(&cfg.gemini, &pos, png_bytes)
.await
.map_err(|e| e.to_string())?;

Expand Down Expand Up @@ -151,7 +149,7 @@ pub async fn preview_image_enhanced_with_config(cfg: config::AppConfig) -> Resul
buf.into_inner()
};

let enhanced = crate::gemini::enhance_image(&cfg.gemini, &pos, &png_bytes)
let enhanced = crate::gemini::enhance_image(&cfg.gemini, &pos, png_bytes)
.await
.map_err(|e| e.to_string())?;

Expand Down
12 changes: 1 addition & 11 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod renderer;
pub mod scheduler;
pub mod sun;

use std::sync::{Arc, Mutex};
use std::sync::Arc;
use tauri::{
menu::{Menu, MenuItem},
tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
Expand All @@ -24,7 +24,6 @@ pub fn run() {
tauri::Builder::default()
.manage(commands::AppState {
update_notify: Arc::new(tokio::sync::Notify::new()),
permission_notified: Mutex::new(false),
})
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_autostart::init(
Expand Down Expand Up @@ -87,15 +86,6 @@ pub fn run() {
})
.build(app)?;

// 起動時権限チェック: 管理者権限がなければトレイツールチップに警告を設定する
#[cfg(target_os = "windows")]
if !lockscreen::check_permission() {
log::warn!("管理者権限なし: ロックスクリーンを変更できません");
let _ = _tray.set_tooltip(Some("⚠️ Locksun: 管理者権限が必要です"));
let state = app.state::<commands::AppState>();
*state.permission_notified.lock().unwrap() = true;
}

// スケジューラーをバックグラウンドで開始
let app_handle = app.handle().clone();
tauri::async_runtime::spawn(async move {
Expand Down
25 changes: 2 additions & 23 deletions src-tauri/src/scheduler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,7 @@ pub async fn start(app: AppHandle) {

loop {
if let Err(e) = run_once(&app).await {
// Windows のみ: 権限エラーを検知してトレイ通知する(1回のみ)
#[cfg(target_os = "windows")]
{
if !lockscreen::check_permission() {
log::warn!("権限エラーを検出: {e:#}");
let state = app.state::<AppState>();
let mut notified = state.permission_notified.lock().unwrap();
if !*notified {
*notified = true;
if let Some(tray) = app.tray_by_id("main") {
let _ = tray.set_tooltip(Some("⚠️ Locksun: 管理者権限が必要です"));
}
log::warn!("権限エラー: トレイ通知を更新しました");
}
} else {
log::error!("更新サイクルエラー: {e:#}");
}
}
#[cfg(not(target_os = "windows"))]
{
log::error!("更新サイクルエラー: {e:#}");
}
log::error!("更新サイクルエラー: {e:#}");
}

let interval = config::load()
Expand Down Expand Up @@ -82,7 +61,7 @@ pub async fn run_once_with_config(app: &AppHandle, cfg: &config::AppConfig) -> a

// Gemini AI 強化が有効な場合は画像を加工する(失敗時はベース画像にフォールバック)
let final_bytes = if cfg.gemini.enabled && !cfg.gemini.api_key.is_empty() {
match gemini::enhance_image(&cfg.gemini, &pos, &base_png).await {
match gemini::enhance_image(&cfg.gemini, &pos, base_png.clone()).await {
Ok(enhanced_bytes) => {
log::info!("Gemini AI 強化済み画像を保存しました");
enhanced_bytes
Expand Down
Loading