@@ -3,8 +3,13 @@ import {
33 DEFAULT_TERMINAL_SETTINGS ,
44 TerminalThemeManager ,
55} from "components/terminal" ;
6+ import toast from "components/toast" ;
7+ import alert from "dialogs/alert" ;
8+ import fsOperation from "fileSystem" ;
69import fonts from "lib/fonts" ;
710import appSettings from "lib/settings" ;
11+ import FileBrowser from "pages/fileBrowser" ;
12+ import Url from "utils/Url" ;
813
914export default function terminalSettings ( ) {
1015 const title = strings [ "terminal settings" ] ;
@@ -153,6 +158,16 @@ export default function terminalSettings() {
153158 checkbox : terminalValues . fontLigatures ,
154159 info : "Whether font ligatures are enabled in the terminal." ,
155160 } ,
161+ {
162+ key : "backup" ,
163+ text : strings . backup . capitalize ( ) ,
164+ info : "Creates a backup of the terminal installation" ,
165+ } ,
166+ {
167+ key : "restore" ,
168+ text : strings . restore . capitalize ( ) ,
169+ info : "Restores a backup of the terminal installation" ,
170+ } ,
156171 ] ;
157172
158173 return settingsPage ( title , items , callback ) ;
@@ -163,15 +178,87 @@ export default function terminalSettings() {
163178 * @param {string } value
164179 */
165180 function callback ( key , value ) {
166- appSettings . update ( {
167- terminalSettings : {
168- ...values . terminalSettings ,
169- [ key ] : value ,
170- } ,
171- } ) ;
181+ switch ( key ) {
182+ case "backup" :
183+ terminalBackup ( ) ;
184+ return ;
185+
186+ case "restore" :
187+ terminalRestore ( ) ;
188+ return ;
189+
190+ default :
191+ appSettings . update ( {
192+ terminalSettings : {
193+ ...values . terminalSettings ,
194+ [ key ] : value ,
195+ } ,
196+ } ) ;
197+
198+ // Update any active terminal instances
199+ updateActiveTerminals ( key , value ) ;
200+ break ;
201+ }
202+ }
203+
204+ /**
205+ * Creates a backup of the terminal installation
206+ */
207+ async function terminalBackup ( ) {
208+ try {
209+ // Ask user to select backup location
210+ const { url } = await FileBrowser ( "folder" , strings [ "select folder" ] ) ;
211+
212+ // Create backup
213+ const backupPath = await Terminal . backup ( ) ;
214+ const backupFilename = "aterm_backup.tar" ;
215+ const destinationPath = Url . join ( url , backupFilename ) ;
216+ const sourceFS = fsOperation ( backupPath ) ;
172217
173- // Update any active terminal instances
174- updateActiveTerminals ( key , value ) ;
218+ const res = await sourceFS . moveTo ( destinationPath ) ;
219+
220+ alert (
221+ strings . success . toUpperCase ( ) ,
222+ `${ strings [ "backup successful" ] } \n${ res } .` ,
223+ ) ;
224+ } catch ( error ) {
225+ console . error ( "Terminal backup failed:" , error ) ;
226+ toast ( error . toString ( ) ) ;
227+ }
228+ }
229+
230+ /**
231+ * Restores terminal installation
232+ */
233+ async function terminalRestore ( ) {
234+ try {
235+ sdcard . openDocumentFile (
236+ async ( data ) => {
237+ const backupFilename = "aterm_backup.tar" ;
238+ const tempBackupPath = cordova . file . dataDirectory + backupFilename ;
239+ const sourceFS = fsOperation ( data . uri ) ;
240+ const tempFS = fsOperation ( tempBackupPath ) ;
241+
242+ await sourceFS . copyTo ( tempBackupPath ) ;
243+
244+ // Restore
245+ await Terminal . restore ( ) ;
246+
247+ // Clean up
248+ await tempFS . delete ( ) ;
249+
250+ alert (
251+ strings . success . toUpperCase ( ) ,
252+ "Terminal restored successfully" ,
253+ ) ;
254+ } ,
255+ toast ,
256+ "application/octet-stream" ,
257+ ) ;
258+ } catch ( error ) {
259+ console . error ( "Terminal restore failed:" , error ) ;
260+ toast ( error . toString ( ) ) ;
261+ }
175262 }
176263}
177264
0 commit comments