Skip to content

Commit

Permalink
get a lot more to work
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Aug 19, 2023
1 parent 2d7bf89 commit 9b9c467
Show file tree
Hide file tree
Showing 12 changed files with 449 additions and 199 deletions.
2 changes: 1 addition & 1 deletion scripts/download-packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const pathUtil = require('path');
const {fetch} = require('./lib');
const packagerInfo = require('./packager.json');

const path = pathUtil.join(__dirname, '../src-packager/packager/standalone.html');
const path = pathUtil.join(__dirname, '../src-renderer/packager/standalone.html');
const sha256 = (buffer) => crypto.createHash('sha256').update(buffer).digest('hex');

const isAlreadyDownloaded = () => {
Expand Down
4 changes: 2 additions & 2 deletions scripts/packager.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"src": "https://github.com/TurboWarp/packager/releases/download/v1.8.0/turbowarp-packager-standalone-1.8.0.html",
"sha256": "aea16dcafdff7a3fea9f247e74d0df7971f1182544993c48d6456ed89d45a372"
"src": "https://github.com/TurboWarp/packager/releases/download/v1.9.0/turbowarp-packager-standalone-1.9.0.html",
"sha256": "f84439fe27f4f892efe6a4b8cc19738fee2d10aaabc5c077fec1847beb41890d"
}
6 changes: 6 additions & 0 deletions src-main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ app.on('session-created', (session) => {
}
window.onHeadersReceived(details, callback);
});

session.on('will-download', (event, item, webContents) => {
item.setSaveDialogOptions({
title: item.getFilename()
});
});
});

app.on('web-contents-created', (event, webContents) => {
Expand Down
6 changes: 3 additions & 3 deletions src-main/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const settings = require('./settings');
const MigrateWindow = require('./windows/migrate');

const migrate = async () => {
if (settings.migrated) {
if (settings.dataVersion === MigrateWindow.LATEST_VERSION) {
return;
}

// Detect fresh installs
// Don't need to migrate anything on a fresh install
const cacheSize = await session.defaultSession.getCacheSize();
if (cacheSize === 0) {
settings.migrated = true;
settings.dataVersion = MigrateWindow.LATEST_VERSION;
await settings.save();
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src-main/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class Settings {
await writeFileAtomic(PATH, JSON.stringify(serialized, null, 2));
}

get migrated () {
return !!this.data.migrated;
get dataVersion () {
return this.data.dataVersion || 0;
}
set migrated (migrated) {
this.data.migrated = true;
set dataVersion (dataVersion) {
this.data.dataVersion = dataVersion;
}

get updateChecker () {
Expand Down
6 changes: 4 additions & 2 deletions src-main/windows/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const {translate} = require('../l10n');
const settings = require('../settings');

class MigrateWindow extends BaseWindow {
static LATEST_VERSION = 2;

constructor () {
super();

Expand All @@ -24,7 +26,7 @@ class MigrateWindow extends BaseWindow {
});

ipc.handle('done', async () => {
settings.migrated = true;
settings.dataVersion = MigrateWindow.LATEST_VERSION;
await settings.save();
this.resolveCallback();
this.window.close();
Expand All @@ -37,7 +39,7 @@ class MigrateWindow extends BaseWindow {
}

getDimensions () {
return [300, 300];
return [400, 400];
}

getPreload () {
Expand Down
42 changes: 25 additions & 17 deletions src-renderer-webpack/editor/gui/migrate-helper.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
</head>
<body>
<script>
window.addEventListener('message', async (e) => {
if (e.origin !== 'file://') {
return;
}

const data = e.data;

const importData = async (data) => {
if (data.theme) {
localStorage.setItem('tw:theme', data.theme);
}
Expand All @@ -20,17 +14,16 @@
localStorage.setItem('tw:addons', data.addons);
}

if (data.backpack) {
if (data.backpack && data.backpack.length) {
const items = data.backpack;
const DATABASE_NAME = 'TW_Backpack';
const DATABASE_VERSION = 1;
const STORE_NAME = 'backpack';

await new Promise((resolve) => {
await new Promise((resolve, reject) => {
const openRequest = indexedDB.open(DATABASE_NAME, DATABASE_VERSION);

openRequest.onerror = () => {
// TODO
reject(new Error(`Error opening DB: ${openRequest.error}`));
};

openRequest.onupgradeneeded = (e) => {
Expand All @@ -44,12 +37,11 @@
openRequest.onsuccess = () => {
const db = openRequest.result;
const transaction = db.transaction([STORE_NAME], 'readwrite');
const store = transaction.objectStore(STORE_NAME);

transaction.onerror = () => {
// TODO
reject(new Error(`Transaction error: ${transaction.error}`));
};

const store = transaction.objectStore(STORE_NAME);
const putNext = () => {
const request = store.put(items.shift());
request.onsuccess = () => {
Expand All @@ -60,16 +52,32 @@
}
};
};

putNext();
};
});
}
};

const PARENT_ORIGIN = 'file://';

window.addEventListener('message', async (e) => {
if (e.origin !== PARENT_ORIGIN) {
return;
}

window.parent.postMessage('finish-import', 'file://');
try {
await importData(e.data);
e.source.postMessage({ type: 'done' }, PARENT_ORIGIN);
} catch (error) {
console.error(error);
e.source.postMessage({
type: 'error',
error: `${error}`
}, PARENT_ORIGIN);
}
});

window.parent.postMessage('start-import', 'file://');
window.parent.postMessage({ type: 'start' }, PARENT_ORIGIN);
</script>
</body>
</html>
47 changes: 47 additions & 0 deletions src-renderer/migrate/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions src-renderer/migrate/error.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions src-renderer/migrate/loading.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9b9c467

Please sign in to comment.