mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-02-16 17:30:27 +00:00
removed store.ts, working on local fs (https://web.dev/file-system-access/)
This commit is contained in:
parent
e82245d7bd
commit
658e161550
@ -55,6 +55,9 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
|
||||
<ul class="dropdown-menu dropdown-menu-left" aria-labelledby="dropdownMenuButton" style="left:auto">
|
||||
<li><a class="dropdown-item" href="#" id="item_new_file">New Project...</a></li>
|
||||
<li><a class="dropdown-item" href="#" id="item_upload_file">Upload...</a></li>
|
||||
<!--
|
||||
<li><a class="dropdown-item" href="#" id="item_open_directory">Open Local Directory...</a></li>
|
||||
-->
|
||||
<hr>
|
||||
<li class="dropdown dropdown-submenu">
|
||||
<a tabindex="-1" href="#">File</a>
|
||||
@ -567,6 +570,7 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
|
||||
var exports = {};
|
||||
function require(modname) {
|
||||
if (modname == 'jquery') return $;
|
||||
else if (modname == 'localforage') return localforage;
|
||||
else if (modname.startsWith('.')) return exports;
|
||||
else { console.log("Unknown require()", modname); return exports; }
|
||||
}
|
||||
@ -581,7 +585,6 @@ function require(modname) {
|
||||
<script src="gen/ide/vlist.js"></script>
|
||||
<script src="gen/common/video/tms9918a.js"></script>
|
||||
<script src="gen/common/util.js"></script>
|
||||
<script src="gen/ide/store.js"></script>
|
||||
<script src="gen/common/emu.js"></script>
|
||||
<script src="gen/common/baseplatform.js"></script>
|
||||
<script src="gen/common/analysis.js"></script>
|
||||
|
@ -3,13 +3,13 @@
|
||||
|
||||
import $ = require("jquery");
|
||||
import * as bootstrap from "bootstrap";
|
||||
import * as localforage from "localforage";
|
||||
import { CodeProject, LocalForageFilesystem, OverlayFilesystem, ProjectFilesystem, WebPresetsFileSystem } from "./project";
|
||||
import { WorkerResult, WorkerOutput, VerilogOutput, SourceFile, WorkerError, FileData } from "../common/workertypes";
|
||||
import { ProjectWindows } from "./windows";
|
||||
import { Platform, Preset, DebugSymbols, DebugEvalCondition, isDebuggable, EmuState } from "../common/baseplatform";
|
||||
import { PLATFORMS, EmuHalt, Toolbar } from "../common/emu";
|
||||
import * as Views from "./views";
|
||||
import { createNewPersistentStore } from "./store";
|
||||
import { getFilenameForPath, getFilenamePrefix, highlightDifferences, invertMap, byteArrayToString, compressLZG, stringToByteArray,
|
||||
byteArrayToUTF8, isProbablyBinary, getWithBinary, getBasePlatform, getRootBasePlatform, hex } from "../common/util";
|
||||
import { StateRecorderImpl } from "../common/recorder";
|
||||
@ -45,7 +45,7 @@ var userPaused : boolean; // did user explicitly pause?
|
||||
|
||||
var current_output : WorkerOutput; // current ROM
|
||||
var current_preset : Preset; // current preset object (if selected)
|
||||
var store; // persistent store
|
||||
var store : LocalForage; // persistent store
|
||||
|
||||
export var compparams; // received build params from worker
|
||||
export var lastDebugState : EmuState; // last debug state (object)
|
||||
@ -97,6 +97,14 @@ const TOOL_TO_HELPURL = {
|
||||
'fastbasic': 'https://github.com/dmsc/fastbasic/blob/master/manual.md'
|
||||
}
|
||||
|
||||
function createNewPersistentStore(storeid:string) {
|
||||
var store = localforage.createInstance({
|
||||
name: "__" + storeid,
|
||||
version: 2.0
|
||||
});
|
||||
return store;
|
||||
}
|
||||
|
||||
function gaEvent(category:string, action:string, label?:string, value?:string) {
|
||||
if (window['ga']) ga('send', 'event', category, action, label, value);
|
||||
}
|
||||
@ -180,12 +188,14 @@ function unsetLastPreset() {
|
||||
}
|
||||
}
|
||||
|
||||
function initProject() {
|
||||
async function initProject() {
|
||||
var basefs : ProjectFilesystem = new WebPresetsFileSystem(platform_id);
|
||||
//basefs = new FirebaseProjectFilesystem("TEST", "TEST");
|
||||
if (isElectron) {
|
||||
console.log('using electron with local filesystem', alternateLocalFilesystem);
|
||||
var filesystem = new OverlayFilesystem(basefs, alternateLocalFilesystem)
|
||||
var filesystem = new OverlayFilesystem(basefs, alternateLocalFilesystem);
|
||||
} else if (qs['localfs'] != null) {
|
||||
var filesystem = new OverlayFilesystem(basefs, await getLocalFilesystem(qs['localfs']));
|
||||
} else {
|
||||
var filesystem = new OverlayFilesystem(basefs, new LocalForageFilesystem(store));
|
||||
}
|
||||
@ -484,6 +494,74 @@ function handleFileUpload(files: File[]) {
|
||||
if (files) uploadNextFile();
|
||||
}
|
||||
|
||||
async function _openLocalDirectory(e) {
|
||||
var pickerfn = window['showDirectoryPicker'];
|
||||
if (!pickerfn) {
|
||||
bootbox.alert(`This browser can't open local files on your computer, yet. Try Chrome.`);
|
||||
}
|
||||
var dirHandle = await pickerfn();
|
||||
var repoid = dirHandle.name;
|
||||
var storekey = '__localfs__' + repoid;
|
||||
var fsdata = {
|
||||
handle: dirHandle,
|
||||
}
|
||||
var lstore = localforage.createInstance({
|
||||
name: storekey,
|
||||
version: 2.0
|
||||
});
|
||||
await lstore.setItem(storekey, fsdata);
|
||||
qs = {localfs: repoid};
|
||||
gotoNewLocation(true);
|
||||
}
|
||||
|
||||
async function promptUser(message: string) : Promise<string> {
|
||||
return new Promise( (resolve, reject) => {
|
||||
bootbox.prompt(message, (result) => {
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function getLocalFilesystem(repoid: string) : Promise<ProjectFilesystem> {
|
||||
const options = {mode:'readwrite'};
|
||||
var storekey = '__localfs__' + repoid;
|
||||
var lstore = localforage.createInstance({
|
||||
name: storekey,
|
||||
version: 2.0
|
||||
});
|
||||
var fsdata : any = await lstore.getItem(storekey);
|
||||
var dirHandle = fsdata.handle as any;
|
||||
console.log(fsdata, dirHandle);
|
||||
var granted = await dirHandle.queryPermission(options);
|
||||
console.log(granted);
|
||||
if (granted !== 'granted') {
|
||||
await promptUser(`Request permissions to access filesystem?`);
|
||||
granted = await dirHandle.requestPermission(options);
|
||||
}
|
||||
if (granted !== 'granted') {
|
||||
bootbox.alert(`Could not get permission to access filesystem.`);
|
||||
return;
|
||||
}
|
||||
for await (const entry of dirHandle.values()) {
|
||||
console.log(entry.kind, entry.name);
|
||||
}
|
||||
return {
|
||||
getFileData: async (path) => {
|
||||
console.log('getFileData', path);
|
||||
let fileHandle = await dirHandle.getFileHandle(path, { create: false });
|
||||
console.log('getFileData', fileHandle);
|
||||
let file = await fileHandle.getFile();
|
||||
console.log('getFileData', file);
|
||||
let contents = await (isProbablyBinary(path) ? file.binary() : file.text());
|
||||
console.log(fileHandle, file, contents);
|
||||
return contents;
|
||||
},
|
||||
setFileData: async (path, data) => {
|
||||
//let vh = await dirHandle.getFileHandle(path, { create: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getCurrentMainFilename() : string {
|
||||
return getFilenameForPath(current_project.mainPath);
|
||||
}
|
||||
@ -1735,6 +1813,7 @@ function setupDebugControls() {
|
||||
$(".dropdown-menu").collapse({toggle: false});
|
||||
$("#item_new_file").click(_createNewFile);
|
||||
$("#item_upload_file").click(_uploadNewFile);
|
||||
$("#item_open_directory").click(_openLocalDirectory);
|
||||
$("#item_github_login").click(_loginToGithub);
|
||||
$("#item_github_logout").click(_logoutOfGithub);
|
||||
$("#item_github_import").click(_importProjectFromGithub);
|
||||
|
Loading…
x
Reference in New Issue
Block a user