Skip to content

Commit

Permalink
Add state logging
Browse files Browse the repository at this point in the history
  • Loading branch information
1whatleytay committed Nov 16, 2024
1 parent ed4683b commit 67d8a95
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-tauri.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
with:
tagName: app-v__VERSION__ # the action automatically replaces \_\_VERSION\_\_ with the app version
releaseName: 'Saturn v__VERSION__'
tagName: app-v0.1.10l # the action automatically replaces \_\_VERSION\_\_ with the app version
releaseName: 'Saturn v0.1.10l'
releaseBody: 'See attached builds.'
releaseDraft: true
prerelease: false
Expand Down
15 changes: 15 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ uuid = "1.5.0"
notify = "6.1.1"
base64 = "0.22.1"
num = "0.4.1"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
tracing-appender = "0.2.3"

saturn_backend = { path = "../src-backend" }
titan = { git = "https://github.com/1whatleytay/titan.git", branch = "main" }
Expand Down
18 changes: 18 additions & 0 deletions src-tauri/src/access_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,30 +124,48 @@ impl AccessManager {
return
};

tracing::info!("FS event for {}: {:?}", path.to_string_lossy(), event);

match event.kind {
notify::EventKind::Create(_) => {
tracing::info!("Emitting CREATE access_manager event for {}", path.to_string_lossy());

app.emit_all("save:create", path).ok();
}
notify::EventKind::Remove(_) => {
tracing::info!("Emitting REMOVE access_manager event for {}", path.to_string_lossy());

app.emit_all("save:remove", path).ok();
}
notify::EventKind::Modify(ModifyKind::Name(_)) => {
if path.exists() {
tracing::info!("Emitting MODIFY + CREATE access_manager event for {}", path.to_string_lossy());

app.emit_all("save:create", path).ok();
} else {
tracing::info!("Emitting MODIFY + REMOVE access_manager event for {}", path.to_string_lossy());

app.emit_all("save:remove", path).ok();
}
}
notify::EventKind::Modify(ModifyKind::Data(_) | ModifyKind::Any) => {
tracing::info!("Emitting MODIFY + DATA access_manager event for {}", path.to_string_lossy());

// If the path is in dismiss, we probably caused the save.
if details.dismiss.remove(path) {
tracing::info!("Dismissed modify to {}", path.to_string_lossy());

return
}

if let Ok(data) = fs::read_to_string(path) {
tracing::info!("Reading full data again from {} ({} bytes)", path.to_string_lossy(), data.len());

app.emit_all("save:modify", AccessModify {
path: path.to_string_lossy().to_string(), data: Text(data)
}).ok();
} else {
tracing::info!("Failed to read {}, skipping event", path.to_string_lossy());
}
}
_ => {}
Expand Down
22 changes: 22 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,26 @@ fn is_debug() -> bool {
cfg!(debug_assertions)
}

#[tauri::command]
fn send_trace(text: String) {
tracing::info!("(JS) {text}");
}

fn main() {
let mut desktop = tauri::api::path::home_dir().unwrap();

desktop.push("Desktop/");

let appender = tracing_appender::rolling::daily(desktop.clone(), "saturn-log");
let (writer, _guard) = tracing_appender::non_blocking(appender);

tracing_subscriber::fmt()
.with_writer(writer)
.with_ansi(false)
.init();

tracing::info!("Logging initialized. Hello world!");

let menu = create_menu();

tauri::Builder::default()
Expand All @@ -58,6 +77,8 @@ fn main() {
.on_window_event(|event| {
match event.event() {
FileDrop(FileDropEvent::Dropped(paths)) => {
tracing::info!("File drop.");

let app = event.window().app_handle();
let manager: tauri::State<AccessManager> = app.state();

Expand Down Expand Up @@ -110,6 +131,7 @@ fn main() {
export_hex_regions,
export_hex_contents,
export_binary_contents,
send_trace,
])
.register_uri_scheme_protocol("midi", midi_protocol)
.register_uri_scheme_protocol("display", display_protocol)
Expand Down
7 changes: 7 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@

<script setup lang="ts">
import Editor from './components/Editor.vue'
import { onErrorCaptured } from 'vue'
import { invoke } from '@tauri-apps/api'
onErrorCaptured((err, instance, info) => {
invoke('send_trace', { text: `![VUE ERROR]! ${err.name}, ${err.message}, ${instance?.$el}, ${info}` })
.then(() => { })
})
</script>
8 changes: 8 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import { setupEvents } from './utils/events'
import { setupShortcuts } from './utils/platform-shortcuts'
import { setupWindow } from './utils/window'
import { setupBackend } from './state/backend'
import { invoke } from '@tauri-apps/api'

invoke('send_trace', { text: 'wake' })
.then(() => { })

window.addEventListener('error', async e => {
await invoke('send_trace', { text: `![JS ERROR]! ${e.message} - (${e.filename}, ${e.lineno}, ${e.colno}) - ${e.error}` })
})

createApp(App).mount('#app')

Expand Down
4 changes: 4 additions & 0 deletions src/utils/cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { hasActionKey, hasAltKey } from './query/shortcut-key'
import { selectionRange, CursorState } from './tabs'
import { EditorSettings } from './settings'
import { grabWhitespace } from './languages/language'
import { invoke } from '@tauri-apps/api'

export interface CursorPosition {
offsetX: number
Expand Down Expand Up @@ -642,6 +643,9 @@ export function useCursor(
const last = pressedBackspace
pressedBackspace = false

invoke('send_trace', { text: `keydown ${event.key} s: ${event.shiftKey} m: ${hasActionKey(event)} a: ${event.altKey}` })
.then(() => { })

switch (event.key) {
case 'ArrowLeft':
if (hasActionKey(event)) {
Expand Down
8 changes: 8 additions & 0 deletions src/utils/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { tab, settings } from '../state/state'
import { format } from 'date-fns'
import { PromptType, saveCurrentTab } from './events'
import { computed, toRaw } from 'vue'
import { invoke } from '@tauri-apps/api'

export async function setBreakpoint(line: number, remove: boolean) {
const currentTab = tab()
Expand Down Expand Up @@ -178,6 +179,8 @@ export async function resume() {
return
}

await invoke('send_trace', { text: 'resuming' })

clearDebug()

const current = tab()
Expand All @@ -195,12 +198,15 @@ export async function resume() {
await saveCurrentTab(PromptType.NeverPrompt)

consoleData.execution = await backend.createExecution(text, path, settings.execution.timeTravel, current.profile)

await invoke('send_trace', { text: 'created execution' })
}

consoleData.showConsole = true
consoleData.mode = ExecutionModeType.Running

const assemblerResult = await consoleData.execution.configure()
await invoke('send_trace', { text: `configured asm result ${JSON.stringify(assemblerResult)}` })

if (assemblerResult) {
postBuildMessage(assemblerResult)
Expand All @@ -217,6 +223,8 @@ export async function resume() {
toRaw(usedBreakpoints)
)

await invoke('send_trace', { text: `resume finished ${JSON.stringify(result)}` })

if (result) {
await postDebugInformationWithPcHint(result)
} else {
Expand Down
42 changes: 33 additions & 9 deletions src/utils/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from './query/alt-consume'
import { grabWhitespace } from './languages/language'
import { splitLines } from './split-lines'
import { invoke } from '@tauri-apps/api'

export interface SelectionIndex {
line: number
Expand Down Expand Up @@ -176,7 +177,9 @@ export class Editor {

this.redoOperations = []

console.log('try again')
invoke('send_trace', { text: `mutate: @${line} -${count} +${insert} - ${this.lineCount()}` })
.then(() => { })

this.onDirty(line, count, this.data.slice(line, line + insert))
}

Expand Down Expand Up @@ -246,6 +249,7 @@ export class Editor {
drop(range: SelectionRange, inclusive: boolean = false) {
if (range.startLine == range.endLine) {
if (inclusive) {
invoke('send_trace', { text: `editor DROPLINEi: ${JSON.stringify(range)}` }).then(() => {})
this.mutate(range.startLine, 1, 0, () => {
this.data.splice(range.startLine, 1)
})
Expand All @@ -255,6 +259,8 @@ export class Editor {
const leading = text.substring(0, range.startIndex)
const trailing = text.substring(range.endIndex)

invoke('send_trace', { text: `editor DROPLINE: ${JSON.stringify(range)}` }).then(() => {})

this.mutateLine(range.startLine, () => {
this.data[range.startLine] = leading + trailing
})
Expand All @@ -263,6 +269,8 @@ export class Editor {
const leading = this.data[range.startLine].substring(0, range.startIndex)
const trailing = this.data[range.endLine].substring(range.endIndex)

invoke('send_trace', { text: `editor DROP: ${JSON.stringify(range)} ${inclusive}` }).then(() => {})

this.mutate(
range.startLine,
range.endLine - range.startLine + 1,
Expand All @@ -287,6 +295,8 @@ export class Editor {
) {
const count = end - start + 1

invoke('send_trace', { text: `editor PREFIX: ${start} ${end} ${character} ${whitespace}` }).then(() => {})

this.mutate(start, count, count, () => {
for (let a = start; a <= end; a++) {
if (whitespace) {
Expand All @@ -305,6 +315,8 @@ export class Editor {
}

crop(start: number, ranges: (LineRange | null)[]) {
invoke('send_trace', { text: `editor CROP: ${start} ${ranges} (${ranges.length})` }).then(() => {})

this.mutate(start, ranges.length, ranges.length, () => {
ranges.forEach((range, index) => {
if (!range) {
Expand All @@ -325,6 +337,8 @@ export class Editor {
const leading = line.substring(0, index.index)
const trailing = line.substring(index.index)

invoke('send_trace', { text: `editor PUT: ${JSON.stringify(index)} ${character}` }).then(() => {})

// Mutate
this.mutateLine(index.line, () => {
this.data[index.line] = leading + character + trailing
Expand Down Expand Up @@ -355,6 +369,8 @@ export class Editor {
const last = rest[rest.length - 1].length
rest[rest.length - 1] += trailing

invoke('send_trace', { text: `editor PASTE: ${JSON.stringify(index)} ${text}` }).then(() => {})

// Mutate
this.mutate(index.line, 1, textLines.length, () => {
this.data[index.line] = leading + first
Expand All @@ -368,7 +384,11 @@ export class Editor {
const regex = new RegExp(`^( {1,${spacing}}|\\t)`, 'g')
const match = this.data[line].match(regex)

invoke('send_trace', { text: `editor DROPTAB: ${line} ${spacing}` }).then(() => {})

if (match && match.length) {
invoke('send_trace', { text: `editor DROPTAB done` }).then(() => {})

const text = match[0]

this.mutateLine(line, () => {
Expand Down Expand Up @@ -396,6 +416,8 @@ export class Editor {
? trailing.substring(endMatch[0].length)
: trailing

invoke('send_trace', { text: `editor NEWLINE: ${JSON.stringify(index)}` }).then(() => {})

// Mutate
this.mutate(index.line, 1, 2, () => {
this.data[index.line] = leading
Expand All @@ -405,14 +427,6 @@ export class Editor {
return { line: index.line + 1, index: spacing.length }
}

dropLines(
index: SelectionIndex
) {
this.mutate(index.line, 1, 0, () => {
this.data.splice(index.line, 1)
})
}

backspace(
index: SelectionIndex,
alt: boolean = false,
Expand All @@ -428,6 +442,8 @@ export class Editor {
const leading = line.substring(0, index.index - consumption)
const trailing = line.substring(index.index)

invoke('send_trace', { text: `editor BACKSPACEi: ${JSON.stringify(index)} ${alt} ${space}` }).then(() => {})

// Mutate
this.mutateLine(index.line, () => {
this.data[index.line] = leading + trailing
Expand All @@ -438,6 +454,8 @@ export class Editor {
const leading = this.data[index.line - 1]
const trailing = this.data[index.line]

invoke('send_trace', { text: `editor BACKSPACE: ${JSON.stringify(index)} ${alt} ${space}` }).then(() => {})

this.mutate(index.line - 1, 2, 1, () => {
this.data[index.line - 1] = leading + trailing
this.data.splice(index.line, 1)
Expand All @@ -458,6 +476,8 @@ export class Editor {
const leading = line.substring(0, index.index)
const trailing = line.substring(index.index + consumption)

invoke('send_trace', { text: `editor DELFORWARDSi: ${JSON.stringify(index)} ${alt}` }).then(() => {})

// Mutate
this.mutateLine(index.line, () => {
this.data[index.line] = leading + trailing
Expand All @@ -468,6 +488,8 @@ export class Editor {
const leading = this.data[index.line]
const trailing = this.data[index.line + 1]

invoke('send_trace', { text: `editor DELFORWARDS: ${JSON.stringify(index)} ${alt}` }).then(() => {})

this.mutate(index.line, 2, 1, () => {
this.data[index.line] = leading + trailing
this.data.splice(index.line + 1, 1)
Expand Down Expand Up @@ -498,6 +520,8 @@ export class Editor {
replaceAll(text: string) {
const textLines = splitLines(text)

invoke('send_trace', { text: `editor REPLACEALL: ${text} (${text.length})` }).then(() => {})

this.mutate(0, this.data.length, textLines.length, () => {
this.data.splice(0, Infinity, ...textLines)
})
Expand Down
Loading

0 comments on commit 67d8a95

Please sign in to comment.