Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify iframe container when the user Downloads the uf2 file #68

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// Place your settings in this file to overwrite default and user settings.
{
"file.autoSave": "afterDelay",
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/built/**": true,
"**/node_modules/**": true,
"**/yotta_modules/**": true,
"**/yotta_targets": true,
"**/pxt_modules/**": true
},
"search.exclude": {
"**/node_modules": true,
"**/yotta_modules/**": true,
"**/yotta_targets": true,
"**/pxt_modules/**": true
},
"tslint.enable": true,
"tslint.rulesDirectory": "node_modules/tslint-microsoft-contrib",
"typescript.tsdk": "./node_modules/typescript/lib",
"editor.tabSize": 4
}
"file.autoSave": "afterDelay",
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/built/**": true,
"**/node_modules/**": true,
"**/yotta_modules/**": true,
"**/yotta_targets": true,
"**/pxt_modules/**": true
},
"search.exclude": {
"**/node_modules": true,
"**/yotta_modules/**": true,
"**/yotta_targets": true,
"**/pxt_modules/**": true
},
"tslint.enable": true,
"tslint.rulesDirectory": "node_modules/tslint-microsoft-contrib",
"typescript.tsdk": "./node_modules/typescript/lib",
"editor.tabSize": 4
}
185 changes: 113 additions & 72 deletions editor/extension.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,90 +3,131 @@
/// <reference path="../node_modules/pxt-core/built/pxtcompiler.d.ts" />
/// <reference path="../node_modules/pxt-core/built/pxtlib.d.ts" />
/// <reference path="../node_modules/pxt-core/built/pxteditor.d.ts" />
import * as React from "react";
import * as React from 'react'

function showUploadInstructionsAsync(fn: string, url: string, confirmAsync?: (options: any) => Promise<number>) {
let resolve: (thenableOrResult?: void | PromiseLike<void>) => void;
let reject: (error: any) => void;
const deferred = new Promise<void>((res, rej) => {
resolve = res;
reject = rej;
});
const boardName = pxt.appTarget.appTheme.boardName || "???";
const boardDriveName = pxt.appTarget.appTheme.driveDisplayName || pxt.appTarget.compile.driveName || "???";
function showUploadInstructionsAsync(
fn: string,
url: string,
confirmAsync?: (options: any) => Promise<number>
) {
console.log('THE URL', url)
window.parent.postMessage({ type: 'upload_file', url }, '*')

// https://msdn.microsoft.com/en-us/library/cc848897.aspx
// "For security reasons, data URIs are restricted to downloaded resources.
// Data URIs cannot be used for navigation, for scripting, or to populate frame or iframe elements"
const downloadAgain = !pxt.BrowserUtils.isIE() && !pxt.BrowserUtils.isEdge();
const docUrl = pxt.appTarget.appTheme.usbDocs;
let resolve: (thenableOrResult?: void | PromiseLike<void>) => void
let reject: (error: any) => void
const deferred = new Promise<void>((res, rej) => {
resolve = res
reject = rej
})
const boardName = pxt.appTarget.appTheme.boardName || '???'
const boardDriveName =
pxt.appTarget.appTheme.driveDisplayName ||
pxt.appTarget.compile.driveName ||
'???'

const jsx = <div className="ui three column grid stackable center aligned">
<div className="column">
<div className="ui">
<div className="image" style={{'margin-bottom': '10px'}}>
<img className="ui medium rounded" style={{height:'200px'}} src="./docs/static/download/connect.png" />
</div>
<div className="content">
<div className="description">
{lf("1. Connect the bluebird to your computer with a USB cable.\nUse the microUSB port on the top of the bluebird.")}
</div>
</div>
// https://msdn.microsoft.com/en-us/library/cc848897.aspx
// "For security reasons, data URIs are restricted to downloaded resources.
// Data URIs cannot be used for navigation, for scripting, or to populate frame or iframe elements"
const downloadAgain = !pxt.BrowserUtils.isIE() && !pxt.BrowserUtils.isEdge()
const docUrl = pxt.appTarget.appTheme.usbDocs
alert('Saving file')
const jsx = (
<div className='ui three column grid stackable center aligned'>
<div className='column'>
<div className='ui'>
<div className='image' style={{ 'margin-bottom': '10px' }}>
<img
className='ui medium rounded'
style={{ height: '200px' }}
src='./docs/static/download/connect.png'
/>
</div>
<div className='content'>
<div className='description'>
{lf(
'888888. Connect the bluebird to your computer with a USB cable.\nUse the microUSB port on the top of the bluebird.'
)}
</div>
</div>
</div>
<div className="column">
<div className="ui">
<div className="image" style={{'margin-bottom': '10px'}}>
<img className="ui medium rounded" style={{height:'200px'}} src="./docs/static/download/reset.png" />
</div>
<div className="content">
<div className="description">
{lf("2. Push the reset button on the bluebird twice quickly.\nLED gets green and you can see the bluebird drive in your computer.")}
</div>
</div>
</div>
<div className='column'>
<div className='ui'>
<div className='image' style={{ 'margin-bottom': '10px' }}>
<img
className='ui medium rounded'
style={{ height: '200px' }}
src='./docs/static/download/reset.png'
/>
</div>
<div className='content'>
<div className='description'>
{lf(
'2. Push the reset button on the bluebird twice quickly.\nLED gets green and you can see the bluebird drive in your computer.'
)}
</div>
</div>
</div>
<div className="column">
<div className="ui">
<div className="image" style={{'margin-bottom': '10px'}}>
<img className="ui medium rounded" style={{height:'200px'}} src="./docs/static/download/transfer.png" />
</div>
<div className="content">
<div className="description">
{lf("3. Download the BLEmode_bluebird.uf2 file.\nLocate the downloaded .uf2 file and drag it to the bluebird drive.")}
</div>
</div>
</div>
<div className='column'>
<div className='ui'>
<div className='image' style={{ 'margin-bottom': '10px' }}>
<img
className='ui medium rounded'
style={{ height: '200px' }}
src='./docs/static/download/transfer.png'
/>
</div>
<div className='content'>
<div className='description'>
{lf(
'3. Download the BLEmode_bluebird.uf2 file.\nLocate the downloaded .uf2 file and drag it to the bluebird drive.'
)}
</div>
</div>
</div>
</div>;
</div>
</div>
)

return confirmAsync({
header: lf("Download completed..."),
jsx,
hasCloseIcon: true,
hideCancel: true,
hideAgree: true,
size: 'large',
buttons: [downloadAgain ? {
return confirmAsync({
header: lf('Download completed...'),
jsx,
hasCloseIcon: true,
hideCancel: true,
hideAgree: true,
size: 'large',
buttons: [
downloadAgain
? {
label: fn,
icon: "download",
class: "lightgrey focused",
icon: 'download',
class: 'lightgrey focused',
url,
fileName: fn
} : undefined, docUrl ? {
label: lf("Help"),
icon: "help",
class: "lightgrey focused",
url: docUrl
} : undefined]
//timeout: 20000
}).then(() => { });
fileName: fn,
}
: undefined,
docUrl
? {
label: lf('Help'),
icon: 'help',
class: 'lightgrey focused',
url: docUrl,
}
: undefined,
],
//timeout: 20000
}).then(() => {
alert('Saving file')
})
}

pxt.editor.initExtensionsAsync = function (opts: pxt.editor.ExtensionOptions): Promise<pxt.editor.ExtensionResult> {
pxt.debug('loading pxt-adafruit target extensions...')
const res: pxt.editor.ExtensionResult = {
showUploadInstructionsAsync: showUploadInstructionsAsync
};
return Promise.resolve<pxt.editor.ExtensionResult>(res);
pxt.editor.initExtensionsAsync = function (
opts: pxt.editor.ExtensionOptions
): Promise<pxt.editor.ExtensionResult> {
pxt.debug('loading pxt-adafruit target extensions...')
const res: pxt.editor.ExtensionResult = {
showUploadInstructionsAsync: showUploadInstructionsAsync,
}
return Promise.resolve<pxt.editor.ExtensionResult>(res)
}
Loading