1- using ElectronNET . API ;
2- using ElectronNET . API . Entities ;
3- using Microsoft . Extensions . Configuration ;
41using Nine . Core . Interfaces ;
52
63namespace Nine . Services ;
@@ -19,7 +16,7 @@ public ElectronPathService(IConfiguration configuration)
1916 }
2017
2118 /// <inheritdoc/>
22- public bool IsActive => HybridSupport . IsElectronActive ;
19+ public bool IsActive => true ; // App is Electron-only
2320
2421 /// <inheritdoc/>
2522 public async Task < string > GetConnectionStringAsync ( object configuration )
@@ -32,31 +29,16 @@ public async Task<string> GetConnectionStringAsync(object configuration)
3229 public async Task < string > GetDatabasePathAsync ( )
3330 {
3431 var dbFileName = _configuration [ "ApplicationSettings:DatabaseFileName" ] ?? "app.db" ;
35-
36- if ( HybridSupport . IsElectronActive )
37- {
38- var userDataPath = await GetUserDataPathAsync ( ) ;
39- var dbPath = Path . Combine ( userDataPath , dbFileName ) ;
40-
41- // Ensure the directory exists
42- var directory = Path . GetDirectoryName ( dbPath ) ;
43- if ( ! string . IsNullOrEmpty ( directory ) && ! Directory . Exists ( directory ) )
44- {
45- Directory . CreateDirectory ( directory ) ;
46- }
47-
48- return dbPath ;
49- }
50- else
32+ var userDataPath = await GetUserDataPathAsync ( ) ;
33+ var dbPath = Path . Combine ( userDataPath , dbFileName ) ;
34+
35+ var directory = Path . GetDirectoryName ( dbPath ) ;
36+ if ( ! string . IsNullOrEmpty ( directory ) && ! Directory . Exists ( directory ) )
5137 {
52- // Fallback to local path if not in Electron mode
53- var dataDir = Path . Combine ( Directory . GetCurrentDirectory ( ) , "Data" ) ;
54- if ( ! Directory . Exists ( dataDir ) )
55- {
56- Directory . CreateDirectory ( dataDir ) ;
57- }
58- return Path . Combine ( dataDir , dbFileName ) ;
38+ Directory . CreateDirectory ( directory ) ;
5939 }
40+
41+ return dbPath ;
6042 }
6143
6244 /// <summary>
@@ -65,91 +47,54 @@ public async Task<string> GetDatabasePathAsync()
6547 public string GetDatabasePathSync ( )
6648 {
6749 var dbFileName = _configuration [ "ApplicationSettings:DatabaseFileName" ] ?? "app.db" ;
68-
69- if ( HybridSupport . IsElectronActive )
70- {
71- // Use OS-specific user data path without requiring Electron to be initialized
72- var userDataPath = GetUserDataPathSync ( ) ;
73- var dbPath = Path . Combine ( userDataPath , dbFileName ) ;
74-
75- // Ensure the directory exists
76- var directory = Path . GetDirectoryName ( dbPath ) ;
77- if ( ! string . IsNullOrEmpty ( directory ) && ! Directory . Exists ( directory ) )
78- {
79- Directory . CreateDirectory ( directory ) ;
80- }
81-
82- return dbPath ;
83- }
84- else
50+ var userDataPath = GetUserDataPathSync ( ) ;
51+ var dbPath = Path . Combine ( userDataPath , dbFileName ) ;
52+
53+ var directory = Path . GetDirectoryName ( dbPath ) ;
54+ if ( ! string . IsNullOrEmpty ( directory ) && ! Directory . Exists ( directory ) )
8555 {
86- // Fallback to local path if not in Electron mode
87- var dataDir = Path . Combine ( Directory . GetCurrentDirectory ( ) , "Data" ) ;
88- if ( ! Directory . Exists ( dataDir ) )
89- {
90- Directory . CreateDirectory ( dataDir ) ;
91- }
92- return Path . Combine ( dataDir , dbFileName ) ;
56+ Directory . CreateDirectory ( directory ) ;
9357 }
58+
59+ return dbPath ;
9460 }
9561
9662 /// <inheritdoc/>
97- public async Task < string > GetUserDataPathAsync ( )
63+ public Task < string > GetUserDataPathAsync ( )
9864 {
99- if ( HybridSupport . IsElectronActive )
100- {
101- // Use sync method to ensure consistent path resolution
102- // This matches the startup behavior and uses "Nine" as the app name
103- return GetUserDataPathSync ( ) ;
104- }
105- else
106- {
107- // Fallback for non-Electron mode
108- return Path . Combine ( Directory . GetCurrentDirectory ( ) , "Data" ) ;
109- }
65+ return Task . FromResult ( GetUserDataPathSync ( ) ) ;
11066 }
11167
11268 /// <summary>
113- /// Gets the user data path synchronously .
69+ /// Gets the OS-specific user data path for the Nine app .
11470 /// </summary>
11571 private string GetUserDataPathSync ( )
11672 {
117- if ( HybridSupport . IsElectronActive )
73+ string basePath ;
74+
75+ if ( OperatingSystem . IsWindows ( ) )
76+ {
77+ basePath = Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) ;
78+ }
79+ else if ( OperatingSystem . IsMacOS ( ) )
11880 {
119- // Determine OS-specific user data path without Electron API
120- string basePath ;
121- var appName = "Nine" ;
122-
123- if ( OperatingSystem . IsWindows ( ) )
124- {
125- basePath = Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) ;
126- }
127- else if ( OperatingSystem . IsMacOS ( ) )
128- {
129- basePath = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) ,
130- "Library" , "Application Support" ) ;
131- }
132- else // Linux
133- {
134- basePath = Environment . GetEnvironmentVariable ( "XDG_CONFIG_HOME" )
135- ?? Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) , ".config" ) ;
136- }
137-
138- var userDataPath = Path . Combine ( basePath , appName ) ;
139-
140- // Ensure directory exists
141- if ( ! Directory . Exists ( userDataPath ) )
142- {
143- Directory . CreateDirectory ( userDataPath ) ;
144- }
145-
146- return userDataPath ;
81+ basePath = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) ,
82+ "Library" , "Application Support" ) ;
14783 }
148- else
84+ else // Linux
14985 {
150- // Fallback for non-Electron mode
151- return Path . Combine ( Directory . GetCurrentDirectory ( ) , "Data " ) ;
86+ basePath = Environment . GetEnvironmentVariable ( "XDG_CONFIG_HOME" )
87+ ?? Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) , ".config " ) ;
15288 }
89+
90+ var userDataPath = Path . Combine ( basePath , "Nine" ) ;
91+
92+ if ( ! Directory . Exists ( userDataPath ) )
93+ {
94+ Directory . CreateDirectory ( userDataPath ) ;
95+ }
96+
97+ return userDataPath ;
15398 }
15499
155100}
0 commit comments