2024-10-04 11:08:39 +02:00
|
|
|
|
if( typeof emulator != 'undefined' ){
|
|
|
|
|
// inside worker-thread
|
|
|
|
|
|
2024-10-04 17:49:15 +02:00
|
|
|
|
this['emulator.restore_state'] = async function(data){
|
|
|
|
|
await emulator.restore_state(data)
|
|
|
|
|
console.log("restored state")
|
2024-10-04 11:08:39 +02:00
|
|
|
|
this.postMessage({event:"state_restored",data:false})
|
|
|
|
|
}
|
|
|
|
|
this['emulator.save_state'] = async function(){
|
2024-10-04 17:49:15 +02:00
|
|
|
|
console.log("saving session")
|
|
|
|
|
let state = await emulator.save_state()
|
2024-10-15 12:32:16 +02:00
|
|
|
|
this.postMessage({event:"state_saved",data:state},[state])
|
2024-10-04 11:08:39 +02:00
|
|
|
|
}
|
2024-09-23 16:58:48 +02:00
|
|
|
|
|
|
|
|
|
|
2024-10-04 11:08:39 +02:00
|
|
|
|
}else{
|
|
|
|
|
// inside browser-thread
|
|
|
|
|
ISOTerminal.addEventListener('emulator-started', function(e){
|
|
|
|
|
this.autorestore(e)
|
2024-09-17 18:59:38 +02:00
|
|
|
|
})
|
|
|
|
|
|
2024-10-04 11:08:39 +02:00
|
|
|
|
ISOTerminal.prototype.autorestore = async function(e){
|
|
|
|
|
|
|
|
|
|
localforage.setDriver([
|
|
|
|
|
localforage.INDEXEDDB,
|
|
|
|
|
localforage.WEBSQL,
|
|
|
|
|
localforage.LOCALSTORAGE
|
|
|
|
|
]).then( () => {
|
|
|
|
|
|
|
|
|
|
localforage.getItem("state", async (err,stateBase64) => {
|
|
|
|
|
if( stateBase64 && !err && confirm('continue last session?') ){
|
|
|
|
|
this.noboot = true // see feat/boot.js
|
|
|
|
|
state = this.convert.base64ToArrayBuffer( stateBase64 )
|
|
|
|
|
|
|
|
|
|
this.addEventListener('state_restored', function(){
|
2024-10-04 17:49:15 +02:00
|
|
|
|
// simulate / fastforward boot events
|
2024-10-18 13:50:56 +02:00
|
|
|
|
this.postBoot( () => {
|
|
|
|
|
this.send("l\n")
|
|
|
|
|
this.send("hook wakeup\n")
|
|
|
|
|
})
|
2024-10-04 11:08:39 +02:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
this.worker.postMessage({event:'emulator.restore_state',data:state})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
this.save = async () => {
|
2024-10-04 17:49:15 +02:00
|
|
|
|
const state = await this.worker.postMessage({event:"emulator.save_state",data:false})
|
2024-10-04 11:08:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-04 17:49:15 +02:00
|
|
|
|
this.addEventListener('state_saved', function(e){
|
|
|
|
|
const state = e.detail
|
|
|
|
|
localforage.setItem("state", this.convert.arrayBufferToBase64(state) )
|
|
|
|
|
console.log("state saved")
|
2024-10-04 11:08:39 +02:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
window.addEventListener("beforeunload", function (e) {
|
|
|
|
|
var confirmationMessage = "Sure you want to leave?\nTIP: enter 'save' to continue this session later";
|
|
|
|
|
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
|
|
|
|
|
return confirmationMessage; //Webkit, Safari, Chrome
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|