Skip to content

Commit

Permalink
Merge pull request #154 from tillvit/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
tillvit authored Nov 18, 2024
2 parents 0854393 + d97ffb6 commit 63fc059
Show file tree
Hide file tree
Showing 14 changed files with 473 additions and 160 deletions.
64 changes: 53 additions & 11 deletions app/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -835,14 +835,6 @@ textarea {
margin-bottom: 12px;
}

.chart-properties ul .label {
font-weight: bold;
}

.chart-properties ul > *:last-child {
flex: 1;
}

div.inlineEdit[contenteditable="true"] {
min-width: 8px;
text-align: right;
Expand Down Expand Up @@ -2355,21 +2347,50 @@ input[type="color"] {
right: 15px;
bottom: 15px;
z-index: 10;
background-color: rgba(0, 0, 0, 0.5);
background-color: var(--primary-bg);
border-radius: 10px;
padding: 10px;
transition: 0.3s ease-out;
user-select: none;
cursor: pointer;
transform-origin: bottom right;
display: flex;
flex-direction: column;
align-items: center;
gap: 5px;
}

.update-popup.exiting {
transform: translateX(50px);
opacity: 0;
}

.update-popup .title {
font-weight: bold;
text-align: center;
}

.update-options {
display: flex;
flex-direction: row;
gap: 10px;
align-items: center;
justify-content: space-around;
width: 100%;
margin-top: 5px;
}

.update-options button {
max-width: 100px;
flex: 1;
}

.animated .update-popup {
transition: 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.875);
}
.animated .update-popup:hover {
scale: 1.03;
background-color: rgba(66, 66, 66, 0.5);
scale: 1.01;
background-color: var(--primary-bg-active);
}

.sync-container {
Expand Down Expand Up @@ -3119,3 +3140,24 @@ input[type="color"] {
border-radius: 5px;
overflow: hidden;
}

.markdown-container {
background-color: var(--secondary-bg);
border: 1px solid var(--secondary-border);
border-radius: 5px 5px 0 0;
flex: 1;
height: 100%;
overflow: auto;
padding: 15px;
}

.markdown-container hr {
border: 1px solid var(--secondary-border);
margin: 5px 0px;
}

.markdown-container ul {
padding-top: 5px;
padding-bottom: 5px;
padding-left: 30px;
}
42 changes: 34 additions & 8 deletions app/src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ import { Chart } from "./chart/sm/Chart"
import { ContextMenuPopup } from "./gui/element/ContextMenu"
import { MenubarManager } from "./gui/element/MenubarManager"
import { WaterfallManager } from "./gui/element/WaterfallManager"
import { UpdatePopup } from "./gui/popup/UpdatePopup"
import { AppUpdatePopup } from "./gui/popup/update/AppUpdatePopup"
import { CoreUpdatePopup } from "./gui/popup/update/CoreUpdatePopup"
import { OfflineUpdatePopup } from "./gui/popup/update/OfflineUpdatePopup"
import { DebugWidget } from "./gui/widget/DebugWidget"
import { ChangelogWindow } from "./gui/window/ChangelogWindow"
import { DirectoryWindow } from "./gui/window/DirectoryWindow"
import { InitialWindow } from "./gui/window/InitialWindow"
import { WindowManager } from "./gui/window/WindowManager"
Expand Down Expand Up @@ -53,7 +56,7 @@ declare global {
}
}

interface Version {
interface AppVersion {
version: string
type: string
date: number
Expand All @@ -66,6 +69,12 @@ interface Version {
changelog: string[]
}

interface CoreVersion {
version: string
date: number
changelog: string
}

export class App {
options = Options
events = EventHandler
Expand Down Expand Up @@ -463,7 +472,7 @@ export class App {
} else if (process.platform == "linux") os = "linux"
fetch("/smeditor/assets/app/versions.json")
.then(data => data.json())
.then((versions: Version[]) => {
.then((versions: AppVersion[]) => {
versions = versions.sort((a, b) => {
if (BUILD_TYPES[a.type] != BUILD_TYPES[b.type])
return BUILD_TYPES[b.type] - BUILD_TYPES[a.type]
Expand All @@ -474,23 +483,40 @@ export class App {
semver.lt(gui.App.manifest.version, version.version) &&
localStorage.getItem("downloadedVersion") !== version.version
) {
UpdatePopup.open(
AppUpdatePopup.open(
version.version,
version.downloads[os as keyof Version["downloads"]]
version.downloads[os as keyof AppVersion["downloads"]]
)
}
})
}

checkCoreVersion() {
registerSW({
const update = registerSW({
onNeedRefresh() {
console.log("need refresh")
CoreUpdatePopup.open(update)
console.log("Found new version")
},
onOfflineReady() {
console.log("offline ready")
OfflineUpdatePopup.open()
console.log("Offline use ready")
},
})
fetch("/smeditor/assets/app/changelog.json")
.then(data => data.json())
.then((versions: CoreVersion[]) => {
const version = versions[0]
const localVersion = localStorage.getItem("coreVersion")
if (localVersion !== null && semver.lt(localVersion, version.version)) {
this.windowManager.openWindow(
new ChangelogWindow(this, {
version: version.version,
markdown: version.changelog,
})
)
}
localStorage.setItem("coreVersion", version.version)
})
}
}

Expand Down
8 changes: 6 additions & 2 deletions app/src/chart/ChartManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { App } from "../App"
import { AUDIO_EXT } from "../data/FileData"
import { IS_OSX, KEYBIND_DATA } from "../data/KeybindData"
import { WaterfallManager } from "../gui/element/WaterfallManager"
import { UpdatePopup } from "../gui/popup/UpdatePopup"
import { AppUpdatePopup } from "../gui/popup/update/AppUpdatePopup"
import { CoreUpdatePopup } from "../gui/popup/update/CoreUpdatePopup"
import { OfflineUpdatePopup } from "../gui/popup/update/OfflineUpdatePopup"
import { DebugWidget } from "../gui/widget/DebugWidget"
import { WidgetManager } from "../gui/widget/WidgetManager"
import { ChartListWindow } from "../gui/window/ChartListWindow"
Expand Down Expand Up @@ -693,7 +695,9 @@ export class ChartManager {
* @memberof ChartManager
*/
async loadSM(path?: string) {
UpdatePopup.close()
AppUpdatePopup.close()
CoreUpdatePopup.close()
OfflineUpdatePopup.close()
// Save confirmation
if (ActionHistory.instance.isDirty()) {
const window = new ConfirmationWindow(
Expand Down
7 changes: 5 additions & 2 deletions app/src/chart/component/edit/Waveform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ export class Waveform extends Sprite implements ChartRendererComponent {
)
this.trackVariable(() => this.renderer.chartManager.chartAudio.hasFilters())

const onUpdate = () => this.getData()

this.anchor.set(0.5)
this.renderer.chartManager.chartAudio.onUpdate(() => this.getData())
this.renderer.chartManager.chartAudio.onUpdate(onUpdate)
this.getData()
this.resizeWaveform()

Expand All @@ -131,7 +133,7 @@ export class Waveform extends Sprite implements ChartRendererComponent {
const audioChanged = () => {
this.getData()
this.resizeWaveform()
this.renderer.chartManager.chartAudio.onUpdate(() => this.getData())
this.renderer.chartManager.chartAudio.onUpdate(onUpdate)
}
EventHandler.on("timingModified", timingHandler)
this.on("destroyed", () => {
Expand All @@ -140,6 +142,7 @@ export class Waveform extends Sprite implements ChartRendererComponent {
EventHandler.on("audioLoaded", audioChanged)
this.on("destroyed", () => {
EventHandler.off("audioLoaded", audioChanged)
this.renderer.chartManager.chartAudio.offUpdate(onUpdate)
})
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/chart/component/notefield/NoteContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class NoteContainer extends Container {
EventHandler.on("chartModified", purgeNotes)
this.on("destroyed", () => {
EventHandler.off("timeSigChanged", timeSig)
EventHandler.on("chartModified", purgeNotes)
EventHandler.off("chartModified", purgeNotes)
})
}

Expand Down
33 changes: 0 additions & 33 deletions app/src/gui/popup/UpdatePopup.ts

This file was deleted.

26 changes: 26 additions & 0 deletions app/src/gui/popup/update/AppUpdatePopup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { UpdatePopup } from "./UpdatePopup"

export class AppUpdatePopup extends UpdatePopup {
static open(versionName: string, downloadLink: string) {
super.build({
title: `A new version of the desktop app is available! (${versionName})`,
desc: "Click here to download the new version.",
options: [
{
label: "Close",
type: "default",
callback: () => this.close(),
},
{
label: "Download",
type: "confirm",
callback: () => {
localStorage.setItem("downloadedVersion", versionName)
nw.require("nw.gui").Shell.openExternal(downloadLink)
this.close()
},
},
],
})
}
}
24 changes: 24 additions & 0 deletions app/src/gui/popup/update/CoreUpdatePopup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { UpdatePopup } from "./UpdatePopup"

export class CoreUpdatePopup extends UpdatePopup {
static open(callback: () => void) {
super.build({
title: `A new version of the app is available!`,
desc: "Refresh the page to get the new version.",
options: [
{
label: "Close",
type: "default",
callback: () => this.close(),
},
{
label: "Refresh",
type: "confirm",
callback: () => {
callback()
},
},
],
})
}
}
12 changes: 12 additions & 0 deletions app/src/gui/popup/update/OfflineUpdatePopup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { UpdatePopup } from "./UpdatePopup"

export class OfflineUpdatePopup extends UpdatePopup {
static open() {
super.build({
title: `SMEditor was loaded offline!`,
desc: "You can now use SMEditor without an internet connection.",
options: [],
})
setTimeout(() => this.close(), 5000)
}
}
55 changes: 55 additions & 0 deletions app/src/gui/popup/update/UpdatePopup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
interface UpdatePopupOptions {
title: string
desc: string
options: UpdateOption[]
}

interface UpdateOption {
label: string
callback?: (popup: UpdatePopup) => void
type: "delete" | "confirm" | "default"
}

export abstract class UpdatePopup {
static popup?: HTMLDivElement

protected static build(opt: UpdatePopupOptions) {
const popup = document.createElement("div")
popup.classList.add("update-popup")

const title = document.createElement("div")
title.classList.add("title")
title.innerText = opt.title

const desc = document.createElement("div")
desc.classList.add("desc")
desc.innerText = opt.desc

const options = document.createElement("div")
options.classList.add("update-options")

popup.replaceChildren(title, desc)

if (opt.options.length > 0) {
for (const o of opt.options) {
const button = document.createElement("button")
button.innerText = o.label
button.onclick = () => {
o.callback?.(this)
}
button.classList.add(o.type)
options.appendChild(button)
}
popup.appendChild(options)
}
this.popup = popup
document.getElementById("popups")?.appendChild(this.popup)
}

static close() {
if (!this.popup) return
this.popup.classList.add("exiting")
this.popup.style.pointerEvents = "none"
setTimeout(() => this.popup!.remove(), 300)
}
}
Loading

0 comments on commit 63fc059

Please sign in to comment.