Compare commits

..
Author SHA1 Message Date
James Brunton 39a8443676 Make quit behaviour more reliable on Mac 2026-07-10 15:25:07 +01:00
42 changed files with 457 additions and 270 deletions
File diff suppressed because it is too large Load Diff
@@ -6,12 +6,14 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import stirling.software.proprietary.access.model.PrincipalType;
import stirling.software.proprietary.access.model.ResourceGrant;
import stirling.software.proprietary.access.model.ResourceType;
import stirling.software.proprietary.security.model.User;
@Repository
public interface ResourceGrantRepository extends JpaRepository<ResourceGrant, Long> {
List<ResourceGrant> findByResourceTypeAndResourceId(
@@ -3,7 +3,9 @@ package stirling.software.proprietary.accountlink;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface DeviceCredentialRepository extends JpaRepository<DeviceCredential, Long> {
/** The singleton credential, if this instance has linked. */
@@ -1,5 +1,7 @@
package stirling.software.proprietary.classification.store;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface TeamLabelsRepository extends JpaRepository<TeamLabelsEntity, Long> {}
@@ -3,12 +3,14 @@ package stirling.software.proprietary.integration.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import stirling.software.proprietary.access.model.OwnerScope;
import stirling.software.proprietary.integration.model.IntegrationConfig;
import stirling.software.proprietary.model.Team;
import stirling.software.proprietary.security.model.User;
@Repository
public interface IntegrationConfigRepository extends JpaRepository<IntegrationConfig, Long> {
List<IntegrationConfig> findByOwnerUser(User ownerUser);
@@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
/**
@@ -14,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional;
* clause the state it was decided against, so a racing claim loses cleanly with 0 rows updated.
* Transactional per call so the ledger can run them without an enclosing transaction.
*/
@Repository
public interface ProcessedFileRepository
extends JpaRepository<ProcessedFileEntity, ProcessedFileId> {
@@ -7,8 +7,10 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@Repository
public interface SourceDocCountRepository
extends JpaRepository<SourceDocCountEntity, SourceDocCountId> {
@@ -7,8 +7,10 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@Repository
public interface SourceDocTotalRepository extends JpaRepository<SourceDocTotalEntity, String> {
/**
@@ -5,7 +5,9 @@ import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@Repository
public interface SourceRepository extends JpaRepository<SourceEntity, String> {
/**
@@ -6,9 +6,11 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import jakarta.persistence.LockModeType;
@Repository
public interface PolicyRepository extends JpaRepository<PolicyEntity, String> {
/** Enabled policies of a given trigger type, for background triggers to activate. */
@@ -10,10 +10,12 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import stirling.software.proprietary.model.security.PersistentAuditEvent;
@Repository
public interface PersistentAuditEventRepository extends JpaRepository<PersistentAuditEvent, Long> {
// Basic queries
@@ -3,9 +3,11 @@ package stirling.software.proprietary.security.database.repository;
import java.util.Set;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import stirling.software.proprietary.security.model.Authority;
@Repository
public interface AuthorityRepository extends JpaRepository<Authority, Long> {
// Set<Authority> findByUsername(String username);
Set<Authority> findByUser_Username(String username);
@@ -1,9 +1,11 @@
package stirling.software.proprietary.security.database.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import stirling.software.proprietary.security.model.PersistentLogin;
@Repository
public interface PersistentLoginRepository extends JpaRepository<PersistentLogin, String> {
void deleteByUsername(String username);
}
@@ -7,11 +7,13 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import jakarta.transaction.Transactional;
import stirling.software.proprietary.security.model.SessionEntity;
@Repository
public interface SessionRepository extends JpaRepository<SessionEntity, String> {
List<SessionEntity> findByPrincipalName(String principalName);
@@ -10,10 +10,12 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import stirling.software.proprietary.model.Team;
import stirling.software.proprietary.security.model.User;
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByUsernameIgnoreCase(String username);
@@ -8,9 +8,11 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import stirling.software.proprietary.security.model.InviteToken;
@Repository
public interface InviteTokenRepository extends JpaRepository<InviteToken, Long> {
Optional<InviteToken> findByToken(String token);
@@ -7,11 +7,13 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import stirling.software.common.model.enumeration.TeamRole;
import stirling.software.proprietary.model.TeamMembership;
import stirling.software.proprietary.security.model.User;
@Repository
public interface TeamMembershipRepository extends JpaRepository<TeamMembership, Long> {
/**
@@ -5,10 +5,12 @@ import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import stirling.software.proprietary.model.Team;
import stirling.software.proprietary.model.dto.TeamWithUserCountDTO;
@Repository
public interface TeamRepository extends JpaRepository<Team, Long> {
Optional<Team> findByName(String name);
@@ -3,9 +3,11 @@ package stirling.software.proprietary.security.repository;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import stirling.software.proprietary.model.UserLicenseSettings;
@Repository
public interface UserLicenseSettingsRepository extends JpaRepository<UserLicenseSettings, Long> {
/**
@@ -5,9 +5,11 @@ import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import stirling.software.proprietary.workflow.model.UserServerCertificateEntity;
@Repository
public interface UserServerCertificateRepository
extends JpaRepository<UserServerCertificateEntity, Long> {
@@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import stirling.software.proprietary.security.model.User;
@@ -14,6 +15,7 @@ import stirling.software.proprietary.workflow.model.ParticipantStatus;
import stirling.software.proprietary.workflow.model.WorkflowParticipant;
import stirling.software.proprietary.workflow.model.WorkflowSession;
@Repository
public interface WorkflowParticipantRepository extends JpaRepository<WorkflowParticipant, Long> {
/** Find participant by share token */
@@ -6,12 +6,14 @@ import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import stirling.software.proprietary.security.model.User;
import stirling.software.proprietary.workflow.model.WorkflowSession;
import stirling.software.proprietary.workflow.model.WorkflowStatus;
import stirling.software.proprietary.workflow.model.WorkflowType;
@Repository
public interface WorkflowSessionRepository extends JpaRepository<WorkflowSession, Long> {
/** Find workflow session by unique session ID */
@@ -7,10 +7,12 @@ import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import stirling.software.saas.billing.model.BillingSubscription;
/** Read/write access to the Stripe subscription mirror table. */
@Repository
public interface BillingSubscriptionRepository extends JpaRepository<BillingSubscription, String> {
List<BillingSubscription> findByUserId(UUID userId);
@@ -7,7 +7,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
/**
* Registers the {@code :saas} module's entities and repositories with Spring Data JPA. Any new
* package holding repository interfaces or {@code @Entity} classes must be added here, or the beans
* package holding {@code @Repository} or {@code @Entity} classes must be added here, or the beans
* won't wire at startup.
*/
@Configuration
@@ -9,12 +9,14 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import stirling.software.saas.payg.job.JobArtifactHash;
import stirling.software.saas.payg.job.JobArtifactHash.JobArtifactHashId;
import stirling.software.saas.payg.lineage.LineageMatch;
import stirling.software.saas.payg.model.JobStatus;
@Repository
public interface JobArtifactHashRepository
extends JpaRepository<JobArtifactHash, JobArtifactHashId> {
@@ -9,10 +9,12 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import stirling.software.saas.payg.meter.PaygMeterEventLog;
@Repository
public interface PaygMeterEventLogRepository extends JpaRepository<PaygMeterEventLog, Long> {
/**
@@ -8,9 +8,11 @@ import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import stirling.software.saas.payg.shadow.PaygShadowCharge;
@Repository
public interface PaygShadowChargeRepository extends JpaRepository<PaygShadowCharge, Long> {
@Query(
@@ -7,11 +7,13 @@ import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import jakarta.persistence.LockModeType;
import stirling.software.saas.payg.policy.PaygTeamExtensions;
@Repository
public interface PaygTeamExtensionsRepository extends JpaRepository<PaygTeamExtensions, Long> {
Optional<PaygTeamExtensions> findByStripeCustomerId(String stripeCustomerId);
@@ -5,9 +5,11 @@ import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import stirling.software.saas.payg.policy.PricingPolicy;
@Repository
public interface PricingPolicyRepository extends JpaRepository<PricingPolicy, Long> {
Optional<PricingPolicy> findByVersion(String version);
@@ -7,10 +7,12 @@ import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import stirling.software.saas.payg.job.ProcessingJob;
import stirling.software.saas.payg.model.JobStatus;
@Repository
public interface ProcessingJobRepository extends JpaRepository<ProcessingJob, UUID> {
List<ProcessingJob> findByOwnerUserIdAndStatus(Long ownerUserId, JobStatus status);
@@ -4,9 +4,11 @@ import java.util.List;
import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import stirling.software.saas.payg.job.ProcessingJobStep;
@Repository
public interface ProcessingJobStepRepository extends JpaRepository<ProcessingJobStep, Long> {
List<ProcessingJobStep> findByJobIdOrderByStartedAtAsc(UUID jobId);
@@ -3,10 +3,12 @@ package stirling.software.saas.payg.repository;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import stirling.software.saas.payg.entitlement.WalletEntitlementSnapshot;
import stirling.software.saas.payg.entitlement.WalletEntitlementSnapshot.WalletEntitlementSnapshotId;
@Repository
public interface WalletEntitlementSnapshotRepository
extends JpaRepository<WalletEntitlementSnapshot, WalletEntitlementSnapshotId> {
@@ -6,10 +6,12 @@ import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import stirling.software.saas.payg.model.LedgerEntryType;
import stirling.software.saas.payg.wallet.WalletLedgerEntry;
@Repository
public interface WalletLedgerRepository extends JpaRepository<WalletLedgerEntry, Long> {
/** Most recent entries for the Plan page activity feed. */
@@ -3,9 +3,11 @@ package stirling.software.saas.payg.repository;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import stirling.software.saas.payg.wallet.WalletPolicy;
@Repository
public interface WalletPolicyRepository extends JpaRepository<WalletPolicy, Long> {
Optional<WalletPolicy> findByTeamId(Long teamId);
@@ -6,9 +6,11 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import stirling.software.saas.model.SaasTeamExtensions;
@Repository
public interface SaasTeamExtensionsRepository extends JpaRepository<SaasTeamExtensions, Long> {
Optional<SaasTeamExtensions> findByTeamId(Long teamId);
@@ -6,9 +6,11 @@ import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import stirling.software.saas.model.SaasUserExtensions;
@Repository
public interface SaasUserExtensionsRepository extends JpaRepository<SaasUserExtensions, Long> {
Optional<SaasUserExtensions> findByUserId(Long userId);
@@ -9,9 +9,11 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import stirling.software.saas.model.SupabaseUser;
@Repository
public interface SupabaseUserRepository extends JpaRepository<SupabaseUser, UUID> {
/**
@@ -8,10 +8,12 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import stirling.software.common.model.enumeration.InvitationStatus;
import stirling.software.saas.model.TeamInvitation;
@Repository
public interface TeamInvitationRepository extends JpaRepository<TeamInvitation, Long> {
/**
@@ -43,7 +43,7 @@ class SaasJpaConfigScanTest {
Set<String> actual = Set.copyOf(Arrays.asList(annotation.basePackages()));
assertThat(actual)
.as("Every package holding repository interfaces must be listed")
.as("Every package holding @Repository interfaces must be listed")
.containsAll(EXPECTED_REPO_PACKAGES);
}
+4 -20
View File
@@ -2,11 +2,11 @@ plugins {
id "java"
id "jacoco"
id "io.spring.dependency-management" version "1.1.7"
id "org.springframework.boot" version "4.1.0"
id "org.springframework.boot" version "4.0.6"
id "org.springdoc.openapi-gradle-plugin" version "1.9.0"
id "io.swagger.swaggerhub" version "1.3.2"
id "com.diffplug.spotless" version "8.5.0"
id "com.github.jk1.dependency-license-report" version "3.1.4"
id "com.github.jk1.dependency-license-report" version "3.1.2"
//id "nebula.lint" version "19.0.3"
id "org.sonarqube" version "7.2.3.7755"
}
@@ -20,12 +20,12 @@ import org.gradle.api.tasks.testing.Test
import org.gradle.jvm.toolchain.JavaLanguageVersion
ext {
springBootVersion = "4.1.0"
springBootVersion = "4.0.6"
pdfboxVersion = "3.0.7"
imageioVersion = "3.13.1"
lombokVersion = "1.18.46"
bouncycastleVersion = "1.84"
springSecuritySamlVersion = "7.1.0"
springSecuritySamlVersion = "7.0.5"
openSamlVersion = "5.2.1"
commonmarkVersion = "0.28.0"
googleJavaFormatVersion = "1.28.0"
@@ -62,19 +62,6 @@ ext.isSecurityDisabled = { ->
System.getProperty('DISABLE_ADDITIONAL_FEATURES') == 'true')
}
ext.getEnv = { ->
def sel = System.getenv('SECURITY_ENABLELOGIN')
logger.lifecycle("SECURITY_ENABLELOGIN: ${sel}")
def des = System.getenv('DOCKER_ENABLE_SECURITY')
logger.lifecycle("DOCKER_ENABLE_SECURITY: ${des}")
def flavorValue = System.getenv('STIRLING_FLAVOR')
logger.lifecycle("STIRLING_FLAVOR: ${flavorValue}")
def saas = System.getenv('ENABLE_SAAS')
logger.lifecycle("ENABLE_SAAS: ${saas}")
def daf = System.getenv('DISABLE_ADDITIONAL_FEATURES')
logger.lifecycle("DISABLE_ADDITIONAL_FEATURES: ${daf}")
}
ext.mavenUrl = System.getenv("MAVEN_PUBLIC_URL") ?: ""
ext.username = System.getenv('MAVEN_USER') ?: ""
ext.password = System.getenv('MAVEN_PASSWORD') ?: ""
@@ -239,8 +226,6 @@ subprojects {
resolutionStrategy.force "org.bouncycastle:bcprov-jdk18on:${bouncycastleVersion}"
resolutionStrategy.force "org.bouncycastle:bcpkix-jdk18on:${bouncycastleVersion}"
resolutionStrategy.force "org.bouncycastle:bcutil-jdk18on:${bouncycastleVersion}"
resolutionStrategy.force "org.apache.santuario:xmlsec:4.0.4"
resolutionStrategy.force "com.google.guava:guava:${guavaVersion}"
}
dependencyManagement {
@@ -623,7 +608,6 @@ dependencies {
if (rootProject.ext.isSecurityDisabled()) {
implementation project(':proprietary')
}
rootProject.ext.getEnv()
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly "org.junit.platform:junit-platform-launcher"
+11
View File
@@ -2,6 +2,7 @@ use tauri::{AppHandle, Emitter, Manager, RunEvent, WindowEvent};
mod utils;
pub mod commands;
mod menu;
mod state;
use commands::{
@@ -74,6 +75,12 @@ fn parse_launch_files(args: &[String]) -> Vec<String> {
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.menu(menu::build_app_menu)
.on_menu_event(|app, event| {
if event.id() == menu::GRACEFUL_QUIT_MENU_ID {
menu::request_graceful_quit(app);
}
})
.plugin(
tauri_plugin_log::Builder::new()
.level(log::LevelFilter::Info)
@@ -209,6 +216,10 @@ pub fn run() {
// Use Tauri's built-in cleanup
app_handle.cleanup_before_exit();
}
RunEvent::Exit => {
add_log("🔄 App exiting, ensuring backend cleanup...".to_string());
cleanup_backend();
}
RunEvent::WindowEvent { event: WindowEvent::CloseRequested {.. }, .. } => {
add_log("🔄 Window close requested (will cleanup on actual exit)...".to_string());
// Don't cleanup here - let JavaScript handler prevent close if needed
+139
View File
@@ -0,0 +1,139 @@
use tauri::menu::Menu;
use tauri::{AppHandle, Manager, Runtime};
#[cfg(target_os = "macos")]
use tauri::menu::{
AboutMetadata, MenuItem, PredefinedMenuItem, Submenu, HELP_SUBMENU_ID, WINDOW_SUBMENU_ID,
};
use crate::utils::add_log;
// Id of our custom Quit item. macOS routes Cmd+Q / the app-menu Quit through
// [NSApp terminate:], which fires RunEvent::Exit (not ExitRequested) and never
// asks windows to close - so the frontend's unsaved-changes guard is bypassed.
// We intercept the shortcut with this item and route it through each window's
// close flow instead.
pub const GRACEFUL_QUIT_MENU_ID: &str = "graceful-quit";
// macOS: mirror Tauri's default menu (Menu::default) but replace the standard
// Quit item with a custom one so Cmd+Q goes through request_graceful_quit().
#[cfg(target_os = "macos")]
pub fn build_app_menu<R: Runtime>(app: &AppHandle<R>) -> tauri::Result<Menu<R>> {
let pkg = app.package_info();
let config = app.config();
let about = AboutMetadata {
name: Some(pkg.name.clone()),
version: Some(pkg.version.to_string()),
copyright: config.bundle.copyright.clone(),
authors: config.bundle.publisher.clone().map(|p| vec![p]),
..Default::default()
};
let quit = MenuItem::with_id(
app,
GRACEFUL_QUIT_MENU_ID,
format!("Quit {}", pkg.name),
true,
Some("CmdOrCtrl+Q"),
)?;
let app_menu = Submenu::with_items(
app,
pkg.name.clone(),
true,
&[
&PredefinedMenuItem::about(app, None, Some(about))?,
&PredefinedMenuItem::separator(app)?,
&PredefinedMenuItem::services(app, None)?,
&PredefinedMenuItem::separator(app)?,
&PredefinedMenuItem::hide(app, None)?,
&PredefinedMenuItem::hide_others(app, None)?,
&PredefinedMenuItem::separator(app)?,
&quit,
],
)?;
let file_menu = Submenu::with_items(
app,
"File",
true,
&[&PredefinedMenuItem::close_window(app, None)?],
)?;
let edit_menu = Submenu::with_items(
app,
"Edit",
true,
&[
&PredefinedMenuItem::undo(app, None)?,
&PredefinedMenuItem::redo(app, None)?,
&PredefinedMenuItem::separator(app)?,
&PredefinedMenuItem::cut(app, None)?,
&PredefinedMenuItem::copy(app, None)?,
&PredefinedMenuItem::paste(app, None)?,
&PredefinedMenuItem::select_all(app, None)?,
],
)?;
let view_menu = Submenu::with_items(
app,
"View",
true,
&[&PredefinedMenuItem::fullscreen(app, None)?],
)?;
let window_menu = Submenu::with_id_and_items(
app,
WINDOW_SUBMENU_ID,
"Window",
true,
&[
&PredefinedMenuItem::minimize(app, None)?,
&PredefinedMenuItem::maximize(app, None)?,
&PredefinedMenuItem::separator(app)?,
&PredefinedMenuItem::close_window(app, None)?,
],
)?;
let help_menu = Submenu::with_id_and_items(app, HELP_SUBMENU_ID, "Help", true, &[])?;
Menu::with_items(
app,
&[
&app_menu,
&file_menu,
&edit_menu,
&view_menu,
&window_menu,
&help_menu,
],
)
}
// Other platforms keep Tauri's default menu unchanged; the RunEvent::Exit
// cleanup path in lib.rs already guards against orphaned backends there.
#[cfg(not(target_os = "macos"))]
pub fn build_app_menu<R: Runtime>(app: &AppHandle<R>) -> tauri::Result<Menu<R>> {
Menu::default(app)
}
// Route a quit request through each window's close flow so the frontend's
// unsaved-changes guard (useExitWarning) runs. Closing the last window causes
// the runtime to emit RunEvent::ExitRequested, which kills the bundled backend.
// If somehow no windows exist, exit directly.
pub fn request_graceful_quit<R: Runtime>(app: &AppHandle<R>) {
let windows = app.webview_windows();
if windows.is_empty() {
add_log("Quit requested with no open windows; exiting.".to_string());
app.exit(0);
return;
}
add_log(format!(
"Quit requested; closing {} window(s) via close flow",
windows.len()
));
for (_, window) in windows {
let _ = window.close();
}
}