diff --git a/src/common/util.ts b/src/common/util.ts index 13c358a3..b5a44282 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -701,3 +701,15 @@ export function replaceAll(s:string, search:string, replace:string) : string { if (search == '') return s; return s.split(search).join(replace); } + +export function getCookie(name: string) : string { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for(var i=0;i < ca.length;i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1,c.length); + if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); + } + return null; +} + diff --git a/src/ide/analytics.ts b/src/ide/analytics.ts new file mode 100644 index 00000000..f399bedc --- /dev/null +++ b/src/ide/analytics.ts @@ -0,0 +1,14 @@ + +declare var ga; + +export function gaEvent(category: string, action: string, label?: string, value?: string) { + if (window['ga']) { + ga('send', 'event', category, action, label, value); + } +} + +export function gaPageView(page: string) { + if (window['ga']) { + ga('send', 'pageview', page); + } +} diff --git a/src/ide/dialogs.ts b/src/ide/dialogs.ts new file mode 100644 index 00000000..3ef50b88 --- /dev/null +++ b/src/ide/dialogs.ts @@ -0,0 +1,34 @@ +import DOMPurify from "dompurify"; + +export function setWaitDialog(b: boolean) { + if (b) { + setWaitProgress(0); + $("#pleaseWaitModal").modal('show'); + } else { + setWaitProgress(1); + $("#pleaseWaitModal").modal('hide'); + } +} + +export function setWaitProgress(prog: number) { + $("#pleaseWaitProgressBar").css('width', (prog * 100) + '%').show(); +} + +export function alertError(s: string) { + setWaitDialog(false); + bootbox.alert({ + title: ' Alert', + message: DOMPurify.sanitize(s) + }); +} + +export function alertInfo(s: string) { + setWaitDialog(false); + bootbox.alert(DOMPurify.sanitize(s)); +} + +export function fatalError(s: string) { + alertError(s); + throw new Error(s); +} + diff --git a/src/ide/shareexport.ts b/src/ide/shareexport.ts new file mode 100644 index 00000000..38f3394b --- /dev/null +++ b/src/ide/shareexport.ts @@ -0,0 +1,290 @@ +import { OutputSoundFile, TAPFile } from '../common/audio/CommodoreTape'; +import { byteArrayToString, compressLZG, getBasePlatform, getFilenameForPath, getFilenamePrefix, loadScript } from '../common/util'; +import { alertError, alertInfo, setWaitDialog, setWaitProgress } from './dialogs'; +import { getCurrentEditorFilename, getCurrentMainFilename, getCurrentOutput, getCurrentProject, getPlatformStore, getWorkerParams, platform, platform_id, projectWindows } from './ui'; +import { saveAs } from "file-saver"; + +declare var GIF; + +export function _shareEmbedLink(e) { + if (getCurrentOutput() == null) { + alertError("Please fix errors before sharing."); + return true; + } + if (!(getCurrentOutput() instanceof Uint8Array)) { + alertError("Can't share a Verilog executable yet. (It's not actually a ROM...)"); + return true; + } + loadClipboardLibrary(); + loadScript('lib/liblzg.js').then(() => { + // TODO: Module is bad var name (conflicts with MAME) + var lzgrom = compressLZG(window['Module'], Array.from(getCurrentOutput())); + window['Module'] = null; // so we load it again next time + var lzgb64 = btoa(byteArrayToString(lzgrom)); + var embed = { + p: platform_id, + //n: current_project.mainPath, + r: lzgb64 + }; + var linkqs = $.param(embed); + var fulllink = get8bitworkshopLink(linkqs, 'player.html'); + var iframelink = '