diff --git a/docs/style.css b/docs/style.css index 8daed7a..c541b2b 100644 --- a/docs/style.css +++ b/docs/style.css @@ -100,3 +100,18 @@ canvas.emscripten { .settings section > div { padding-left: 2rem; } + +.toast-container { + position: fixed; + bottom: 0; + left: 0; + width: 400px; + padding: 30px; + z-index: 500; +} + +.toast { + -webkit-animation: slide-down .2s ease 1; + animation: slide-down .2s ease 1; + margin: 5px; +} diff --git a/docs/xsystem35.html b/docs/xsystem35.html index f759ea6..78e74d9 100644 --- a/docs/xsystem35.html +++ b/docs/xsystem35.html @@ -92,6 +92,8 @@ +
+ diff --git a/shell/settings.ts b/shell/settings.ts index 09d44f9..132b630 100644 --- a/shell/settings.ts +++ b/shell/settings.ts @@ -73,11 +73,13 @@ namespace xsystem35 { } else if (file.name.toLowerCase().endsWith('.asd')) { addSaveFile(file.name, await readFileAsArrayBuffer(file)); } else { - throw('ファイルを認識できません。'); + throw('Unknown file type: ' + file.name); } xsystem35.shell.syncfs(0); + xsystem35.shell.addToast('成功しました。', 'success'); } catch (err) { - console.log(err); + xsystem35.shell.addToast('セーブデータを復元できませんでした。', 'danger'); + console.warn(err); } } } diff --git a/shell/shell.ts b/shell/shell.ts index 5cd19cb..02074e4 100644 --- a/shell/shell.ts +++ b/shell/shell.ts @@ -97,6 +97,22 @@ namespace xsystem35 { this.zoom.handleZoom(); } + addToast(msg: string, type?: 'success' | 'danger') { + let container = $('.toast-container'); + let div = document.createElement('div'); + div.classList.add('toast'); + if (type) + div.classList.add('toast-' + type); + div.innerText = msg; + let btn = document.createElement('button'); + btn.setAttribute('class', 'btn btn-clear float-right'); + function dismiss() { container.removeChild(div); } + btn.addEventListener('click', dismiss); + setTimeout(dismiss, 5000); + div.insertBefore(btn, div.firstChild); + container.insertBefore(div, container.firstChild); + } + private fsyncTimer: number; syncfs(timeout = 100) { window.clearTimeout(this.fsyncTimer);