From 10a6571875838b23d98dfaaed5ae6fa87f760e81 Mon Sep 17 00:00:00 2001 From: kakakaya Date: Sat, 10 Feb 2024 18:22:49 +0900 Subject: [PATCH 1/9] Revert frontend version change --- frontend/package.json | 6 +++--- frontend/package.json.md5 | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index 0ab58dd..8a93541 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -9,8 +9,8 @@ "preview": "vite preview" }, "devDependencies": { - "@sveltejs/vite-plugin-svelte": "^3.0.2", - "svelte": "^4.2.10", - "vite": "^5.1.1" + "@sveltejs/vite-plugin-svelte": "^1.0.1", + "svelte": "^3.49.0", + "vite": "^3.0.0" } } \ No newline at end of file diff --git a/frontend/package.json.md5 b/frontend/package.json.md5 index 07fbd9a..d69931e 100755 --- a/frontend/package.json.md5 +++ b/frontend/package.json.md5 @@ -1 +1 @@ -c75f81b1299f8d3675e8103348403c41 \ No newline at end of file +3369211da39dcc63e89750b11fced2dd \ No newline at end of file From 2b12266c15187b7bb6b7761efd0d738066f5701c Mon Sep 17 00:00:00 2001 From: kakakaya Date: Sun, 11 Feb 2024 00:17:34 +0900 Subject: [PATCH 2/9] Use runtime.Quit, and add better default config --- app.go | 9 +++++---- config.go | 9 +++++++-- main.go | 8 +------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app.go b/app.go index 35575a9..e36a13a 100644 --- a/app.go +++ b/app.go @@ -5,7 +5,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "os" "strings" @@ -75,6 +75,7 @@ func (a *App) startup(ctx context.Context) { a.OpenConfigDirectory() } a.logger.Warn("Missing credentials") + runtime.Quit(ctx) } auth, err := createSession(cred.Host, cred.Identifier, cred.Password) @@ -97,7 +98,7 @@ func (a *App) startup(ctx context.Context) { } a.logger.Warn("Failed creating session, bad identifier or password?", "error", err) - panic(err) + runtime.Quit(ctx) } xrpcc := &xrpc.Client{ @@ -118,7 +119,7 @@ func createSession(host string, identifier string, password string) (*xrpc.AuthI url := fmt.Sprintf("%s/xrpc/com.atproto.server.createSession", host) req, err := http.NewRequest("POST", url, bytes.NewBuffer([]byte(payload))) if err != nil { - return nil, fmt.Errorf("Error creating HTTP request:", err) + return nil, fmt.Errorf("Error creating HTTP request: %r", err) } req.Header.Set("Content-Type", "application/json") @@ -132,7 +133,7 @@ func createSession(host string, identifier string, password string) (*xrpc.AuthI if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("Error: Unexpected status code: %d", resp.StatusCode) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("Error reading response body: %v", err) } diff --git a/config.go b/config.go index e97eae7..2a4989f 100644 --- a/config.go +++ b/config.go @@ -2,8 +2,8 @@ package main import ( "bytes" - "io/ioutil" "log" + "os" "github.com/BurntSushi/toml" "github.com/adrg/xdg" @@ -57,6 +57,11 @@ func loadOrCreateConfig(configPath string) (Config, error) { AlwaysOnTop: true, Transparent: true, }, + Credential: credConfig{ + Identifier: "ID (e.g. example.bsky.social)", + Password: "App Password (see https://tokimekibluesky-docs.vercel.app/ja/apppassword)", + Host: "https://bsky.social", + }, } buf := new(bytes.Buffer) err = toml.NewEncoder(buf).Encode(defaultConfig) @@ -69,7 +74,7 @@ func loadOrCreateConfig(configPath string) (Config, error) { buf.String(), "=========================================", ) - ioutil.WriteFile(configFile, buf.Bytes(), 0644) + os.WriteFile(configFile, buf.Bytes(), 0644) config = defaultConfig } return config, nil diff --git a/main.go b/main.go index 6d0eaaf..c6e18b7 100644 --- a/main.go +++ b/main.go @@ -121,13 +121,7 @@ func main() { BackdropType: windows.Acrylic, DisableWindowIcon: false, DisableFramelessWindowDecorations: false, - // Theme: windows.SystemDefault, - // User messages that can be customised - // Messages *windows.Messages - // OnSuspend is called when Windows enters low power mode - // OnSuspend func(), - // OnResume is called when Windows resumes from low power mode - // OnResume func(), + Theme: windows.SystemDefault, }, Mac: &mac.Options{ TitleBar: &mac.TitleBar{ From c07aa9f2a80ac5541274a25205f4e98a9c46e59e Mon Sep 17 00:00:00 2001 From: kakakaya Date: Sun, 11 Feb 2024 13:16:53 +0900 Subject: [PATCH 3/9] Delete unused README --- frontend/README.md | 63 ---------------------------------------------- 1 file changed, 63 deletions(-) delete mode 100644 frontend/README.md diff --git a/frontend/README.md b/frontend/README.md deleted file mode 100644 index a346289..0000000 --- a/frontend/README.md +++ /dev/null @@ -1,63 +0,0 @@ -# Svelte + Vite - -This template should help get you started developing with Svelte in Vite. - -## Recommended IDE Setup - -[VS Code](https://code.visualstudio.com/) - -+ [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). - -## Need an official Svelte framework? - -Check out [SvelteKit](https://github.com/sveltejs/kit#readme), which is also powered by Vite. Deploy anywhere with its -serverless-first approach and adapt to various platforms, with out of the box support for TypeScript, SCSS, and Less, -and easily-added support for mdsvex, GraphQL, PostCSS, Tailwind CSS, and more. - -## Technical considerations - -**Why use this over SvelteKit?** - -- It brings its own routing solution which might not be preferable for some users. -- It is first and foremost a framework that just happens to use Vite under the hood, not a Vite app. - `vite dev` and `vite build` wouldn't work in a SvelteKit environment, for example. - -This template contains as little as possible to get started with Vite + Svelte, while taking into account the developer -experience with regards to HMR and intellisense. It demonstrates capabilities on par with the other `create-vite` -templates and is a good starting point for beginners dipping their toes into a Vite + Svelte project. - -Should you later need the extended capabilities and extensibility provided by SvelteKit, the template has been -structured similarly to SvelteKit so that it is easy to migrate. - -**Why `global.d.ts` instead of `compilerOptions.types` inside `jsconfig.json` or `tsconfig.json`?** - -Setting `compilerOptions.types` shuts out all other types not explicitly listed in the configuration. Using triple-slash -references keeps the default TypeScript setting of accepting type information from the entire workspace, while also -adding `svelte` and `vite/client` type information. - -**Why include `.vscode/extensions.json`?** - -Other templates indirectly recommend extensions via the README, but this file allows VS Code to prompt the user to -install the recommended extension upon opening the project. - -**Why enable `checkJs` in the JS template?** - -It is likely that most cases of changing variable types in runtime are likely to be accidental, rather than deliberate. -This provides advanced typechecking out of the box. Should you like to take advantage of the dynamically-typed nature of -JavaScript, it is trivial to change the configuration. - -**Why is HMR not preserving my local component state?** - -HMR state preservation comes with a number of gotchas! It has been disabled by default in both `svelte-hmr` -and `@sveltejs/vite-plugin-svelte` due to its often surprising behavior. You can read the -details [here](https://github.com/rixo/svelte-hmr#svelte-hmr). - -If you have state that's important to retain within a component, consider creating an external store which would not be -replaced by HMR. - -```js -// store.js -// An extremely simple external store -import { writable } from 'svelte/store' -export default writable(0) -``` From 9c62f21b6bf069a221bc5feea38c63aadca7cc1b Mon Sep 17 00:00:00 2001 From: kakakaya Date: Sun, 11 Feb 2024 13:22:27 +0900 Subject: [PATCH 4/9] Delete importing no longer exist file --- frontend/src/App.svelte | 4 ---- 1 file changed, 4 deletions(-) diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index 74013b2..5de4ea4 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -13,10 +13,6 @@ Quit } from '../wailsjs/runtime/runtime.js' - import { - GenerateDummyInviteCode, - } from './topping/invite-code.js' - import { ConvertRichUnicode } from './topping/unicode.js' From bc95c418258a54a27cc790ea9cbd86e7ab93e631 Mon Sep 17 00:00:00 2001 From: kakakaya Date: Sun, 11 Feb 2024 14:49:24 +0900 Subject: [PATCH 5/9] Use stable slog as logger --- app.go | 2 +- main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app.go b/app.go index e36a13a..2fca03f 100644 --- a/app.go +++ b/app.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "io" + "log/slog" "net/http" "os" "strings" @@ -15,7 +16,6 @@ import ( "github.com/bluesky-social/indigo/xrpc" "github.com/gen2brain/beeep" "github.com/wailsapp/wails/v2/pkg/runtime" - "golang.org/x/exp/slog" ) // App struct diff --git a/main.go b/main.go index c6e18b7..eff41fb 100644 --- a/main.go +++ b/main.go @@ -3,11 +3,11 @@ package main import ( "embed" "fmt" + "log/slog" "os" "time" "github.com/adrg/xdg" - "golang.org/x/exp/slog" "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/menu" From 783678d1eca76a38c348cd8216acc17797069247 Mon Sep 17 00:00:00 2001 From: kakakaya Date: Sun, 11 Feb 2024 14:49:46 +0900 Subject: [PATCH 6/9] Fix lexcon arg --- bluesky.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bluesky.go b/bluesky.go index 7875327..bae93f0 100644 --- a/bluesky.go +++ b/bluesky.go @@ -15,10 +15,12 @@ func BskyFeedPost(xrpcc *xrpc.Client, text string) (string, error) { resp, err := comatproto.RepoCreateRecord(context.TODO(), xrpcc, &comatproto.RepoCreateRecord_Input{ Collection: "app.bsky.feed.post", Repo: xrpcc.Auth.Did, - Record: &lexutil.LexiconTypeDecoder{&appbsky.FeedPost{ - Text: text, - CreatedAt: time.Now().Format("2006-01-02T15:04:05.000Z"), - }}, + Record: &lexutil.LexiconTypeDecoder{ + Val: &appbsky.FeedPost{ + Text: text, + CreatedAt: time.Now().Format("2006-01-02T15:04:05.000Z"), + }, + }, }) if err != nil { return "", fmt.Errorf("failed to create post: %w", err) From e951226da8a978a419efaf864df2ca58c081e0e6 Mon Sep 17 00:00:00 2001 From: kakakaya Date: Sun, 11 Feb 2024 14:51:23 +0900 Subject: [PATCH 7/9] Reset XRPC Client using gocron --- app.go | 145 ++++++++++++++++++++++++++++++++++++++------------------ go.mod | 10 ++-- go.sum | 19 +++++--- main.go | 7 +-- 4 files changed, 120 insertions(+), 61 deletions(-) diff --git a/app.go b/app.go index 2fca03f..2bc64aa 100644 --- a/app.go +++ b/app.go @@ -15,6 +15,7 @@ import ( "github.com/adrg/xdg" "github.com/bluesky-social/indigo/xrpc" "github.com/gen2brain/beeep" + "github.com/go-co-op/gocron/v2" "github.com/wailsapp/wails/v2/pkg/runtime" ) @@ -25,6 +26,7 @@ type App struct { xrpcc *xrpc.Client logger *slog.Logger environment runtime.EnvironmentInfo + scheduler gocron.Scheduler } // dialogResults is used for casting Dialog's response to boolean. Note that keys are lowercase. @@ -56,70 +58,36 @@ func (a *App) startup(ctx context.Context) { } a.logger.Info("Startup", "environment", a.environment) - // Build xrpc.Client - var auth *xrpc.AuthInfo - cred := a.config.Credential - if cred.Host == "" || cred.Identifier == "" || cred.Password == "" { - a.logger.Warn("Credentials not set!") - result, err := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{ - Type: runtime.QuestionDialog, - Title: "認証情報がないよ", - Message: "config.tomlにIDとパスワードを入力してね。\nこのまま沈没するけど、設定ファイルの場所を開く?", - DefaultButton: "Yes", - }) - if err != nil { - a.logger.Warn("Error creds not set dialog", "error", err) - } - a.logger.Info(result) - if dialogResults[strings.ToLower(result)] { - a.OpenConfigDirectory() - } - a.logger.Warn("Missing credentials") + err := a.SetXRPCClient() + if err != nil { runtime.Quit(ctx) } - auth, err := createSession(cred.Host, cred.Identifier, cred.Password) - + err = a.SetScheduler() if err != nil { - // If auth failed, - result, err := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{ - Type: runtime.QuestionDialog, - Title: "認証に失敗しました", - Message: fmt.Sprintf("%sへの認証に失敗しました。\nIDとパスワードを確認してください。\nこのまま沈没するけど、設定ファイルの場所を開く?", cred.Host), - DefaultButton: "Yes", - }) - - if err != nil { - a.logger.Warn("Error creds not set dialog", "error", err) - } - a.logger.Info(result) - if dialogResults[strings.ToLower(result)] { - a.OpenConfigDirectory() - } - - a.logger.Warn("Failed creating session, bad identifier or password?", "error", err) runtime.Quit(ctx) } +} - xrpcc := &xrpc.Client{ - Client: NewHttpClient(), - Host: cred.Host, - Auth: auth, +func (a *App) beforeClose(ctx context.Context) bool { + err := a.scheduler.Shutdown() + if err != nil { + a.logger.Warn("Error on scheduler shutdown:", err) } - a.xrpcc = xrpcc + return false } // createSession calls "/xrpc/com.atproto.server.createSession" and returns xrpc.AuthInfo. func createSession(host string, identifier string, password string) (*xrpc.AuthInfo, error) { payload := fmt.Sprintf(`{"identifier": "%s", "password": "%s"}`, identifier, password) if host == "" { - return nil, fmt.Errorf("Error: host not set. Check [Credential] section in config file.") + return nil, fmt.Errorf("host not set. check [Credential] section in config file") } url := fmt.Sprintf("%s/xrpc/com.atproto.server.createSession", host) req, err := http.NewRequest("POST", url, bytes.NewBuffer([]byte(payload))) if err != nil { - return nil, fmt.Errorf("Error creating HTTP request: %r", err) + return nil, fmt.Errorf("failed creating HTTP request: %r", err) } req.Header.Set("Content-Type", "application/json") @@ -131,11 +99,11 @@ func createSession(host string, identifier string, password string) (*xrpc.AuthI defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("Error: Unexpected status code: %d", resp.StatusCode) + return nil, fmt.Errorf("unexpected status code: %d", resp.StatusCode) } body, err := io.ReadAll(resp.Body) if err != nil { - return nil, fmt.Errorf("Error reading response body: %v", err) + return nil, fmt.Errorf("failed reading response body: %v", err) } var auth xrpc.AuthInfo err = json.Unmarshal(body, &auth) @@ -199,3 +167,86 @@ func (a *App) OpenLogDirectory() error { func (a *App) GetVersion() string { return Version } + +func (a *App) SetXRPCClient() error { + + // Build xrpc.Client + var auth *xrpc.AuthInfo + cred := a.config.Credential + if cred.Host == "" || cred.Identifier == "" || cred.Password == "" { + a.logger.Warn("Credentials not set!") + result, dialogErr := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{ + Type: runtime.QuestionDialog, + Title: "認証情報がないよ", + Message: "config.tomlにIDとパスワードを入力してね。\nこのまま沈没するけど、設定ファイルの場所を開く?", + DefaultButton: "Yes", + }) + if dialogErr != nil { + a.logger.Warn("Error creds not set dialog", "error", dialogErr) + } + a.logger.Info(result) + if dialogResults[strings.ToLower(result)] { + a.OpenConfigDirectory() + } + a.logger.Warn("Missing credentials") + return fmt.Errorf("Couldn't load valid credentials.") + } + + auth, authErr := createSession(cred.Host, cred.Identifier, cred.Password) + + if authErr != nil { + // If auth failed, + result, dialogErr := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{ + Type: runtime.QuestionDialog, + Title: "認証に失敗したよ", + Message: fmt.Sprintf("%sへの認証に失敗しました。\nIDとパスワードを確認してね。\nこのまま沈没するけど、設定ファイルの場所を開く?", cred.Host), + DefaultButton: "Yes", + }) + + if dialogErr != nil { + a.logger.Warn("Error creds not set dialog", "error", dialogErr) + } + a.logger.Info(result) + if dialogResults[strings.ToLower(result)] { + a.OpenConfigDirectory() + } + + a.logger.Warn("Failed creating session, bad identifier or password?", "error", authErr) + return authErr + } + + xrpcc := &xrpc.Client{ + Client: NewHttpClient(), + Host: cred.Host, + Auth: auth, + } + a.xrpcc = xrpcc + a.logger.Info("Set XRPCC succeeded.") + return nil +} + +func (a *App) SetScheduler() error { + s, err := gocron.NewScheduler() + if err != nil { + return err + } + a.scheduler = s + // add a job to the scheduler + j, err := a.scheduler.NewJob( + gocron.DurationJob( + 10*time.Minute, + ), + gocron.NewTask( + a.SetXRPCClient, + ), + ) + if err != nil { + a.logger.Warn("Error occurred on SetScheduler: ", err, j) + } + + // start the scheduler + a.scheduler.Start() + + // err = s.Shutdown() + return nil +} diff --git a/go.mod b/go.mod index 058781a..d7d26f2 100644 --- a/go.mod +++ b/go.mod @@ -9,8 +9,8 @@ require ( github.com/adrg/xdg v0.4.0 github.com/bluesky-social/indigo v0.0.0-20230724215300-9108e264e3c1 github.com/gen2brain/beeep v0.0.0-20230602101333-f384c29b62dd + github.com/go-co-op/gocron/v2 v2.2.4 github.com/wailsapp/wails/v2 v2.8.0 - golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 ) require ( @@ -19,7 +19,7 @@ require ( github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/google/uuid v1.3.0 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-retryablehttp v0.7.4 // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect @@ -37,8 +37,9 @@ require ( github.com/ipfs/go-metrics-interface v0.0.1 // indirect github.com/jbenet/goprocess v0.1.4 // indirect github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect + github.com/jonboulle/clockwork v0.4.0 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect - github.com/kr/text v0.2.0 // indirect + github.com/kr/pretty v0.2.1 // indirect github.com/labstack/echo/v4 v4.11.1 // indirect github.com/labstack/gommon v0.4.0 // indirect github.com/leaanthony/go-ansi-parser v1.6.1 // indirect @@ -60,6 +61,7 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/polydawn/refmt v0.89.1-0.20221221234430-40501e09de1f // indirect github.com/rivo/uniseg v0.4.4 // indirect + github.com/robfig/cron/v3 v3.0.1 // indirect github.com/samber/lo v1.38.1 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect @@ -73,11 +75,11 @@ require ( go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.24.0 // indirect golang.org/x/crypto v0.18.0 // indirect + golang.org/x/exp v0.0.0-20231219180239-dc181d75b848 // indirect golang.org/x/net v0.20.0 // indirect golang.org/x/sys v0.16.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect - gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect lukechampine.com/blake3 v1.2.1 // indirect ) diff --git a/go.sum b/go.sum index 2888dbe..26ba0fe 100644 --- a/go.sum +++ b/go.sum @@ -10,12 +10,13 @@ github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3IS github.com/bluesky-social/indigo v0.0.0-20230724215300-9108e264e3c1 h1:hjw+jin6LO1OhHOSMNHSSP33Ebn3mh0cOplHK1Y5Nnw= github.com/bluesky-social/indigo v0.0.0-20230724215300-9108e264e3c1/go.mod h1:kXtzhQS670OIkBw5a2STyGRy6RG5kgi9u5382NpxD3E= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gen2brain/beeep v0.0.0-20230602101333-f384c29b62dd h1:eVPIv7aXHQYJ5lbhXHoJyfPhivIn+BvH2xPoG62lT2w= github.com/gen2brain/beeep v0.0.0-20230602101333-f384c29b62dd/go.mod h1:0W7dI87PvXJ1Sjs0QPvWXKcQmNERY77e8l7GFhZB/s4= +github.com/go-co-op/gocron/v2 v2.2.4 h1:fL6a8/U+BJQ9UbaeqKxua8wY02w4ftKZsxPzLSNOCKk= +github.com/go-co-op/gocron/v2 v2.2.4/go.mod h1:igssOwzZkfcnu3m2kwnCf/mYj4SmhP9ecSgmYjCOHkk= github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE= @@ -27,8 +28,8 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= @@ -72,6 +73,8 @@ github.com/jbenet/goprocess v0.1.4 h1:DRGOFReOMqqDNXwW70QkacFW0YN9QnwLV0Vqk+3oU0 github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4= github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e h1:Q3+PugElBCf4PFpxhErSzU3/PY5sFL5Z6rfv4AbGAck= github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs= +github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4= +github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -148,6 +151,8 @@ github.com/polydawn/refmt v0.89.1-0.20221221234430-40501e09de1f/go.mod h1:/zvteZ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= +github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM= @@ -194,8 +199,8 @@ go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= -go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= -go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= @@ -212,8 +217,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 h1:Di6/M8l0O2lCLc6VVRWhgCiApHV8MnQurBnFSHsQtNY= -golang.org/x/exp v0.0.0-20230725093048-515e97ebf090/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/exp v0.0.0-20231219180239-dc181d75b848 h1:+iq7lrkxmFNBM7xx+Rae2W6uyPfhPeDWD+n+JgppptE= +golang.org/x/exp v0.0.0-20231219180239-dc181d75b848/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= diff --git a/main.go b/main.go index eff41fb..0276219 100644 --- a/main.go +++ b/main.go @@ -58,7 +58,7 @@ func main() { // menu ================ AppMenu := menu.NewMenu() FileMenu := AppMenu.AddSubmenu("ファイル") - FileMenu.AddText("Quit", keys.Key("Escape"), func(_ *menu.CallbackData) { + FileMenu.AddText("沈没", keys.Key("Escape"), func(_ *menu.CallbackData) { runtime.Quit(app.ctx) }) FileMenu.AddText("設定の場所を開く", keys.CmdOrCtrl(","), func(_ *menu.CallbackData) { @@ -109,8 +109,9 @@ func main() { BackgroundColour: &options.RGBA{R: 48, G: 128, B: 48, A: 0}, - OnStartup: app.startup, - Menu: AppMenu, + OnStartup: app.startup, + OnBeforeClose: app.beforeClose, + Menu: AppMenu, Bind: []interface{}{ app, }, From 19f65d431ed07a0be106922b6b2045014b5a4e7d Mon Sep 17 00:00:00 2001 From: kakakaya Date: Sun, 11 Feb 2024 20:48:08 +0900 Subject: [PATCH 8/9] Fix window problem on windows --- frontend/wailsjs/go/main/App.d.ts | 4 ++++ frontend/wailsjs/go/main/App.js | 8 ++++++++ main.go | 13 ++++++------- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts index 24df55f..19b8b73 100755 --- a/frontend/wailsjs/go/main/App.d.ts +++ b/frontend/wailsjs/go/main/App.d.ts @@ -12,3 +12,7 @@ export function OpenLogDirectory():Promise; export function Post(arg1:string):Promise; export function PostAndForget(arg1:string):Promise; + +export function SetScheduler():Promise; + +export function SetXRPCClient():Promise; diff --git a/frontend/wailsjs/go/main/App.js b/frontend/wailsjs/go/main/App.js index f24b0a8..a600a0a 100755 --- a/frontend/wailsjs/go/main/App.js +++ b/frontend/wailsjs/go/main/App.js @@ -25,3 +25,11 @@ export function Post(arg1) { export function PostAndForget(arg1) { return window['go']['main']['App']['PostAndForget'](arg1); } + +export function SetScheduler() { + return window['go']['main']['App']['SetScheduler'](); +} + +export function SetXRPCClient() { + return window['go']['main']['App']['SetXRPCClient'](); +} diff --git a/main.go b/main.go index 0276219..52af4d7 100644 --- a/main.go +++ b/main.go @@ -104,12 +104,12 @@ func main() { Assets: assets, }, Frameless: true, - // CSSDragProperty: "windows", - // CSSDragValue: "1", - BackgroundColour: &options.RGBA{R: 48, G: 128, B: 48, A: 0}, + // Windows allows A: 0 or 255 only, therefore we'll use 0 for simple. + BackgroundColour: &options.RGBA{R: 48, G: 48, B: 48, A: 0}, OnStartup: app.startup, + OnDomReady: app.onDomReady, OnBeforeClose: app.beforeClose, Menu: AppMenu, Bind: []interface{}{ @@ -118,10 +118,9 @@ func main() { Windows: &windows.Options{ WebviewIsTransparent: true, WindowIsTranslucent: true, - // BackdropType: windows.Auto, - BackdropType: windows.Acrylic, + // BackdropType: windows.None, DisableWindowIcon: false, - DisableFramelessWindowDecorations: false, + DisableFramelessWindowDecorations: true, // this makes true transparent Theme: windows.SystemDefault, }, Mac: &mac.Options{ @@ -144,6 +143,6 @@ func main() { }) if err != nil { - println("Error:", err.Error()) + app.logger.Warn("error on app close: ", err.Error()) } } From 656eb57fd6d1155291aaca3e5dcacb9c05905172 Mon Sep 17 00:00:00 2001 From: kakakaya Date: Sun, 11 Feb 2024 20:48:22 +0900 Subject: [PATCH 9/9] Implementing window background config, but not completed yet --- app.go | 7 ++++++- config.go | 8 ++++++++ frontend/src/App.svelte | 11 ++++++++++- frontend/src/style.css | 37 ++++++++++++------------------------- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/app.go b/app.go index 2bc64aa..7fdfb60 100644 --- a/app.go +++ b/app.go @@ -69,6 +69,11 @@ func (a *App) startup(ctx context.Context) { } } +func (a *App) onDomReady(ctx context.Context) { + slog.Info("Emitting OnDomReady", a.config) + runtime.EventsEmit(ctx, "OnDomReady", "hello") +} + func (a *App) beforeClose(ctx context.Context) bool { err := a.scheduler.Shutdown() if err != nil { @@ -129,7 +134,7 @@ func NewHttpClient() *http.Client { func (a *App) Post(text string) string { a.logger.Info("Post", "text", text) - err := beeep.Notify("まぜそば大陸", fmt.Sprintf("BskyFeedPost: %s", text), "") + beeep.Notify("まぜそば大陸", fmt.Sprintf("BskyFeedPost: %s", text), "") if a.environment.BuildType == "dev" { return "" diff --git a/config.go b/config.go index 2a4989f..9101550 100644 --- a/config.go +++ b/config.go @@ -27,6 +27,10 @@ type windowConfig struct { Height int AlwaysOnTop bool Transparent bool + BackgroundR int + BackgroundG int + BackgroundB int + BackgroundA float64 } type credConfig struct { @@ -56,6 +60,10 @@ func loadOrCreateConfig(configPath string) (Config, error) { Height: 200, AlwaysOnTop: true, Transparent: true, + BackgroundR: 27, + BackgroundG: 38, + BackgroundB: 54, + BackgroundA: 0.5, }, Credential: credConfig{ Identifier: "ID (e.g. example.bsky.social)", diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index 5de4ea4..3b6492f 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -10,7 +10,8 @@ WindowCenter, WindowHide, WindowShow, - Quit + Quit, + LogInfo, } from '../wailsjs/runtime/runtime.js' import { @@ -55,6 +56,10 @@ charCounter = countGrapheme(text) } + function setBackgroundColor(r, g, b, a) { + const newBackgroundStyle = `background-color: rgba(${r}, ${g}, ${b}, ${a});` + // FIXME: implement, I've tired for now + } // Setup Events EventsOn("call-clearText", () => { @@ -66,6 +71,10 @@ EventsOn("call-chikuwa", () => { chikuwa() }) + EventsOn("OnDomReady", (args) => { + LogInfo("OnDomReady"); + LogInfo(args); + })
diff --git a/frontend/src/style.css b/frontend/src/style.css index 68bde19..e83c4a5 100644 --- a/frontend/src/style.css +++ b/frontend/src/style.css @@ -75,22 +75,18 @@ select { } body { - font-family: "Avenir-Roman", "Arial", "游ゴシック体", YuGothic, "游ゴシック Medium", "Yu Gothic Medium", "游ゴシック", "Yu Gothic", sans-serif, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif, Helvetica Neue, Arial, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji; -} - - -body { - margin: 0; - color: white; + /* + margin: 0%; + padding: 0%; + */ font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; display: flex; display: grid; background: transparent; - background-color: rgba(27, 38, 54, 0.1); + background-color: rgba(27, 38, 54, 0.5); text-align: center; - color: white; } @font-face { @@ -101,23 +97,14 @@ body { url("assets/fonts/nunito-v16-latin-regular.woff2") format("woff2"); } -#app { - height: 100vh; - text-align: center; -} - -.result { - height: 1em; - line-height: 2em; - margin: 1.5rem auto; -} - -textarea { - color: black; +#inputbox { + background: transparent; + color: white; + height: 95%; + width: 95%; resize: none; - border: 0 none; - width: 100vw; - height: 100vh + border: none; + outline: none; } .char-count {