From fbca94881f39d137f28b890c1393f35d184d7dd3 Mon Sep 17 00:00:00 2001 From: Kodai Aoyama Date: Fri, 5 Apr 2024 19:49:01 +0900 Subject: [PATCH] fix --- package.json | 2 +- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/migrations/001.sql | 1 + src-tauri/src/module/permissions.rs | 41 +++++++++++++++++++---------- src-tauri/src/module/sqlite.rs | 15 +++++++++++ src-tauri/tauri.conf.json | 2 +- 7 files changed, 47 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 9bdbefb..524880f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "lycoris", "private": true, - "version": "0.9.7", + "version": "0.9.8", "type": "module", "license": "MIT", "engines": { diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 6906982..1a94ba3 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2571,7 +2571,7 @@ dependencies = [ [[package]] name = "lycoris" -version = "0.9.7" +version = "0.9.8" dependencies = [ "chrono", "core-graphics 0.23.1", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index b0ea876..a8b175b 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lycoris" -version = "0.9.7" +version = "0.9.8" description = "Lycoris is an offline voice memo" authors = ["solaoi"] license = "MIT" diff --git a/src-tauri/migrations/001.sql b/src-tauri/migrations/001.sql index 1524dc7..efdde68 100644 --- a/src-tauri/migrations/001.sql +++ b/src-tauri/migrations/001.sql @@ -31,6 +31,7 @@ INSERT INTO settings(setting_name, setting_status) VALUES("settingHook", ""); INSERT INTO settings(setting_name, setting_status) VALUES("settingResource", ""); INSERT INTO settings(setting_name, setting_status) VALUES("settingModel", "gpt-3.5-turbo"); INSERT INTO settings(setting_name, setting_status) VALUES("settingAILanguage", "None"); +INSERT INTO settings(setting_name, setting_status) VALUES("settingHasAccessedScreenCapturePermission", "never"); CREATE TABLE models ( id INTEGER PRIMARY KEY AUTOINCREMENT, model_name TEXT, diff --git a/src-tauri/src/module/permissions.rs b/src-tauri/src/module/permissions.rs index 5873e2e..b1c465b 100644 --- a/src-tauri/src/module/permissions.rs +++ b/src-tauri/src/module/permissions.rs @@ -12,6 +12,8 @@ use objc_id::Id; use core_graphics::access::ScreenCaptureAccess; use tauri::{api::dialog::confirm, Window}; +use super::sqlite::Sqlite; + pub fn has_accessibility_permission() -> bool { let trusted = macos_accessibility_client::accessibility::application_is_trusted_with_prompt(); return trusted; @@ -42,20 +44,31 @@ pub fn has_microphone_permission(window: Window) -> bool { } pub fn has_screen_capture_permission(window: Window) -> bool { + let sqlite = Sqlite::new(); + let has_accessed_screen_capture_permission = sqlite + .select_has_accessed_screen_capture_permission() + .unwrap(); let access = ScreenCaptureAccess::default(); - let trusted = access.preflight(); - if !trusted { - let func = |ok: bool| { - if ok { - std::process::Command::new("open") - .arg( - "x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture", - ) - .spawn() - .expect("failed to open system preferences"); - } - }; - confirm(Some(&window),"システム設定の\"セキュリティとプライバシー\"設定で、このアプリケーションへのアクセスを許可してください。", "\"Lycoris.app\"から画面収録にアクセスしようとしています。",func); + if has_accessed_screen_capture_permission == "has_accessed" { + let trusted = access.preflight(); + if !trusted { + let func = |ok: bool| { + if ok { + std::process::Command::new("open") + .arg( + "x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture", + ) + .spawn() + .expect("failed to open system preferences"); + } + }; + confirm(Some(&window),"システム設定の\"セキュリティとプライバシー\"設定で、このアプリケーションへのアクセスを許可してください。", "\"Lycoris.app\"から画面収録にアクセスしようとしています。",func); + } + return trusted; + } else { + sqlite + .update_has_accessed_screen_capture_permission() + .unwrap(); + return access.request(); } - return trusted; } diff --git a/src-tauri/src/module/sqlite.rs b/src-tauri/src/module/sqlite.rs index 1df3c38..788bdcc 100644 --- a/src-tauri/src/module/sqlite.rs +++ b/src-tauri/src/module/sqlite.rs @@ -140,6 +140,21 @@ impl Sqlite { ); } + pub fn select_has_accessed_screen_capture_permission(&self) -> Result { + return self.conn.query_row( + "SELECT setting_status FROM settings WHERE setting_name = \"settingHasAccessedScreenCapturePermission\"", + params![], + |row| Ok(row.get_unwrap(0)), + ); + } + + pub fn update_has_accessed_screen_capture_permission(&self) -> Result { + self.conn.execute( + "UPDATE settings SET setting_status = \"has_accessed\" WHERE setting_name = \"settingHasAccessedScreenCapturePermission\"", + params![], + ) + } + pub fn update_model_vosk_to_whisper( &self, id: u16, diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 4b7b01e..84d7524 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "Lycoris", - "version": "0.9.7" + "version": "0.9.8" }, "tauri": { "allowlist": {