Skip to content

Commit

Permalink
feat: webassembly demo for golang
Browse files Browse the repository at this point in the history
  • Loading branch information
JuckZ committed Sep 25, 2023
1 parent 5baff44 commit 222c501
Show file tree
Hide file tree
Showing 10 changed files with 688 additions and 2,893 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ It's not too long now. Just finish reading.🤣

### 调试方法

#### 编译ntfy

```powershell
$env:GOOS = "js"
$env:GOARCH = "wasm"
go build -o src/utils/ntfy.wasm ntfy.go
```

```sh
GOOS=js GOARCH=wasm go build -o src/utils/ntfy.wasm ntfy.go
```

#### Windows(cmd.exe)

```cmd
Expand Down
14 changes: 13 additions & 1 deletion README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ It's not too long now. Just finish reading.🤣
<a href="ttps://www.bilibili.com/video/BV1ne4y1P7qf/?spm_id_from=333.999.0.0">
<img src="https://raw.githubusercontent.com/JuckZ/awesome-brain-manager/master/public/recording/preview/文档方向.png" alt="文档方向切换功能展示" width="49%">
</a>

</details>

<details open>
Expand Down Expand Up @@ -191,6 +191,18 @@ Open the Settings panel with the 'Enable debug' option under the 'Advance' group

### Debugging method

#### compile ntfy

```powershell
$env:GOOS = "js"
$env:GOARCH = "wasm"
go build -o src/utils/ntfy.wasm ntfy.go
```

```sh
GOOS=js GOARCH=wasm go build -o src/utils/ntfy.wasm ntfy.go
```

#### Windows(cmd.exe)

```cmd
Expand Down
18 changes: 18 additions & 0 deletions ntfy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// main.go
package main

import (
"fmt"
"syscall/js"
)

func main() {
c := make(chan struct{}, 0)
js.Global().Set("hello", js.FuncOf(hello))
<-c
}

func hello(this js.Value, inputs []js.Value) interface{} {
fmt.Println("Hello, WebAssembly!")
return nil
}
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { eventTypes } from '@/types/types';
import { onCodeMirrorChange, toggleBlast, toggleShake } from '@/render/Blast';
import { notifyNtfy } from '@/api';
import '@/main.scss';
import { NotifyUtil } from '@/utils/notify';
import { NotifyUtil, loadNtfy } from '@/utils/ntfy/notify';
import { EditorUtil, EditorUtils } from '@/utils/editor';
import t from '@/i18n';
import { UpdateModal } from '@/ui/modal/UpdateModal';
Expand Down Expand Up @@ -322,6 +322,7 @@ export default class AwesomeBrainManagerPlugin extends Plugin {
this.setupUI();
this.watchVault();
setTimeout(() => {
loadNtfy();
// workaround to ensure our plugin shows up properly within Style Settings
this.app.workspace.trigger('css-change');
}, 2000);
Expand Down
4 changes: 1 addition & 3 deletions src/utils/db/sqljs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import initSqlJs from 'sql.js';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import sqlWasm from '@/utils/db/sqljs/sql-wasm.wasm?url';
import sqlWasm from 'sql.js/dist/sql-wasm.wasm?url';

export const loadSQL = async () => {
const sql = await initSqlJs({
Expand Down
Loading

0 comments on commit 222c501

Please sign in to comment.