Skip to content

Commit

Permalink
Update nw.js, add apple silicon, add window size options
Browse files Browse the repository at this point in the history
  • Loading branch information
tillvit committed Aug 13, 2024
1 parent 100beca commit 832b9ea
Show file tree
Hide file tree
Showing 10 changed files with 5,573 additions and 2,988 deletions.
45 changes: 39 additions & 6 deletions app/src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,54 @@ export class App {
tippy.setDefaultProps({ duration: [200, 100], theme: "sm" })

if (window.nw) {
const activeWin = nw.Window.get()
const win = nw.Window.get()

window.addEventListener("keydown", e => {
if ((e.key == "r" && (e.metaKey || e.ctrlKey)) || e.key == "F5") {
e.preventDefault()
activeWin.reload()
win.reload()
}
if (
process.versions["nw-flavor"] == "sdk" &&
e.code == "KeyI" &&
e.metaKey &&
e.altKey
) {
e.preventDefault()
win.showDevTools()
}
})
win.on("enter-fullscreen", () => {
console.log("enter-fullscreen")
})
win.on("maximize", () => {
console.log("maximize")
})
win.on("minimize", () => {
console.log("minimize")
})
win.on("resize", (x, y) => {
console.log("resize", x, y)
})
win.on("restore", () => {
console.log("restore")
})
this.checkAppVersion()
}

Options.loadOptions()
loadFlags()
Keybinds.load(this)

if (window.nw) {
const win = nw.Window.get()
if (Options.app.fullscreen) {
win.enterFullscreen()
} else {
win.resizeTo(Options.app.width, Options.app.height)
}
}

setInterval(() => Options.saveOptions(), 10000)
if (Options.general.smoothAnimations)
document.body.classList.add("animated")
Expand Down Expand Up @@ -126,7 +160,7 @@ export class App {
})

this.ticker = new Ticker()
this.ticker.maxFPS = 120
this.ticker.maxFPS = 0
this.ticker.add(() => {
const startTime = performance.now()
this.renderer.render(this.stage)
Expand Down Expand Up @@ -437,9 +471,8 @@ function init() {
canvas.getContext("experimental-webgl")) as WebGLRenderingContext

if (!gl) {
document.querySelector(
"body"
)!.innerHTML = `<div class='browser-unsupported'>
document.querySelector("body")!.innerHTML =
`<div class='browser-unsupported'>
<div class='browser-unsupported-item'>
<h1>WebGL is not enabled</h1>
<div>Please visit your browser settings and enable WebGL.</div>
Expand Down
83 changes: 77 additions & 6 deletions app/src/data/UserOptionsWindowData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ export interface UserOptionGroup {
id: string
label: string
children: UserOption[]
disable?: (app: App) => boolean
}

interface UserOptionSubgroup {
type: "subgroup"
label?: string
children: UserOption[]
disable?: (app: App) => boolean
}

interface UserOptionItem {
Expand All @@ -22,6 +24,7 @@ interface UserOptionItem {
label: string
tooltip?: string
input: UserOptionInput<any>
disable?: (app: App) => boolean
}

interface UserOptionTextInput {
Expand All @@ -30,21 +33,21 @@ interface UserOptionTextInput {
serialize: (value: string) => string
deserialize: (value: string) => string
}
onChange?: (value: string) => void
onChange?: (app: App, value: string) => void
}

type UserOptionDropdownInput<T> =
| {
type: "dropdown"
items: readonly string[]
advanced: false
onChange?: (value: string | number) => void
onChange?: (app: App, value: string | number) => void
}
| {
type: "dropdown"
items: readonly number[]
advanced: false
onChange?: (value: string | number) => void
onChange?: (app: App, value: string | number) => void
}
| {
type: "dropdown"
Expand All @@ -54,7 +57,7 @@ type UserOptionDropdownInput<T> =
serialize: (value: string | number | boolean) => T
deserialize: (value: T) => string | number | boolean
}
onChange?: (value: string | number | boolean) => void
onChange?: (app: App, value: string | number | boolean) => void
}

interface UserOptionNumberInput {
Expand All @@ -67,7 +70,7 @@ interface UserOptionNumberInput {
serialize: (value: number) => number
deserialize: (value: number) => number
}
onChange?: (value: number) => void
onChange?: (app: App, value: number) => void
}

interface UserOptionSliderInput {
Expand All @@ -81,7 +84,7 @@ interface UserOptionSliderInput {
serialize: (value: number) => number
deserialize: (value: number) => number
}
onChange?: (value: number) => void
onChange?: (app: App, value: number) => void
}

interface UserOptionCheckboxInput {
Expand All @@ -102,6 +105,74 @@ type UserOptionInput<T> =
| UserOptionColorInput

export const USER_OPTIONS_WINDOW_DATA: UserOption[] = [
{
type: "group",
id: "app",
label: "App",
disable: () => window.nw === undefined,
children: [
{
type: "subgroup",
children: [
{
type: "item",
label: "Window Width",
id: "app.width",
input: {
type: "number",
step: 50,
min: 300,
onChange: (_, value) => {
const win = nw.Window.get()
if (!win.isFullscreen) {
win.width = value
}
},
},
},
{
type: "item",
label: "Window Height",
id: "app.height",
input: {
type: "number",
step: 50,
min: 300,
onChange: (_, value) => {
const win = nw.Window.get()
if (!win.isFullscreen) {
win.height = value
}
},
},
},
],
},
{
type: "subgroup",
children: [
{
type: "item",
label: "Fullscreen",
id: "app.fullscreen",
input: {
type: "checkbox",
onChange: (_, value) => {
const win = nw.Window.get()
if (value) {
nw.Window.get().enterFullscreen()
} else {
win.hide()
nw.Window.get().leaveFullscreen()
win.show()
}
},
},
},
],
},
],
},
{
type: "group",
id: "general",
Expand Down
28 changes: 15 additions & 13 deletions app/src/gui/window/UserOptionsWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ export class UserOptionsWindow extends Window {
}

private createOptions(options: UserOption[]) {
return options.map(option => {
const element = this.makeOption(option)
if (option.type == "group") {
this.observer!.observe(element)
this.sectionContainer?.appendChild(this.createEmptyGroup(option))
}
return element
})
return options
.filter(option => !option.disable?.(this.app))
.map(option => {
const element = this.makeOption(option)
if (option.type == "group") {
this.observer!.observe(element)
this.sectionContainer?.appendChild(this.createEmptyGroup(option))
}
return element
})
}

private makeOption(option: UserOption): HTMLDivElement {
Expand Down Expand Up @@ -183,7 +185,7 @@ export class UserOptionsWindow extends Window {
Options.getOption(option.id)
? "none"
: "block"
callback?.(deserializer(value))
callback?.(this.app, deserializer(value))
})
dropdown.view.classList.add("pref-input", "dropdown-right")
input = dropdown.view
Expand All @@ -198,7 +200,7 @@ export class UserOptionsWindow extends Window {
Options.getOption(option.id)
? "none"
: "block"
callback?.(value)
callback?.(this.app, value)
})
dropdown.view.classList.add("pref-input", "dropdown-right")
input = dropdown.view
Expand Down Expand Up @@ -230,7 +232,7 @@ export class UserOptionsWindow extends Window {
Options.getOption(option.id)
? "none"
: "block"
callback?.(deserializer(value))
callback?.(this.app, deserializer(value))
}
input = spinner.view
break
Expand Down Expand Up @@ -282,7 +284,7 @@ export class UserOptionsWindow extends Window {
Options.getOption(option.id)
? "none"
: "block"
callback?.(deserializer(value))
callback?.(this.app, deserializer(value))
}
slider.oninput = () => {
const value = parseFloat(slider.value)
Expand Down Expand Up @@ -316,7 +318,7 @@ export class UserOptionsWindow extends Window {
Options.getOption(option.id)
? "none"
: "block"
callback?.(textInput.value)
callback?.(this.app, textInput.value)
}
textInput.onkeydown = ev => {
if (ev.key == "Enter") textInput.blur()
Expand Down
5 changes: 5 additions & 0 deletions app/src/util/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const SAVE_BLACKLIST = [
]

export class DefaultOptions {
static app = {
width: 800,
height: 600,
fullscreen: true,
}
static general = {
spinnerStep: 1,
smoothAnimations: true,
Expand Down
3 changes: 1 addition & 2 deletions nw/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<html lang="en">
<head>
<script>
const process = nw.require("process")
if (process.env.EXECUTION_MODE == "DEBUG") {
if (nw.App.argv.includes("--debug")) {
window.location = "http://127.0.0.1:5173/smeditor/app/"
} else {
window.location = "https://tillvit.github.io/smeditor/app/"
Expand Down
2 changes: 1 addition & 1 deletion nw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"http://127.0.0.1:5173/smeditor/app",
"https://tillvit.github.io/smeditor/app"
],
"chromium-args": "--enable-logging --v=1 --disable-gpu-sandbox --no-sandbox --enable-webgl2-compute-context --force-discrete-gpu=1 --enable-high-resolution-time --enable-zero-copy --ignore-gpu-blacklist --autoplay-policy no-user-gesture-required"
"chromium-args": "--enable-logging --v=1 --enable-gpu-rasterization --enable-drdc --enable-webgl2-compute-context --enable-high-resolution-time --enable-zero-copy --ignore-gpu-blocklist --autoplay-policy=no-user-gesture-required --disable-gpu-sandbox"
}
15 changes: 11 additions & 4 deletions nwbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,24 @@ const baseOptions = {
arch: "x64",
}

const mac = Object.assign(structuredClone(baseOptions), {
outDir: "build/mac/SMEditor",
const mac_x64 = Object.assign(structuredClone(baseOptions), {
outDir: "build/mac-x64/SMEditor",
platform: "osx",
app: {
name: "SMEditor",
genericName: "SMEditor",
icon: "./public/assets/icon/mac.icns",
comment: "Open source tool to view and edit StepMania charts",
CFBundleIdentifier: "io.github.tillvit.smeditor"
CFBundleIdentifier: "io.github.tillvit.smeditor",
NSHumanReadableCopyright: ""
}
})

const mac_arm = Object.assign(structuredClone(mac_x64), {
outDir: "build/mac-arm/SMEditor",
arch: "arm64",
})


const win = Object.assign(structuredClone(baseOptions), {
outDir: "build/win/SMEditor",
Expand All @@ -48,6 +54,7 @@ const linux = Object.assign(structuredClone(baseOptions), {
}
})

await nwbuild(mac)
await nwbuild(mac_arm)
await nwbuild(mac_x64)
await nwbuild(win)
await nwbuild(linux)
10 changes: 0 additions & 10 deletions nwrun.js

This file was deleted.

Loading

0 comments on commit 832b9ea

Please sign in to comment.