asticode / go-astilectron-demo

Discover the power of Astilectron through a demo app
MIT License
404 stars 83 forks source link

Bundler Issue #73

Closed linclt closed 2 years ago

linclt commented 2 years ago

when i use astilectron-bundler, i change the bundler.json like this: { "app_name": "Astilectron demo1", "icon_path_darwin": "resources/icon.icns", "icon_path_linux": "resources/icon.png", "icon_path_windows": "resources/icon.ico" } ,i get this error: image

linclt commented 2 years ago

Sometimes update the index and static in the resource/app folder, the exe file generated after astilectron-bundler still uses the previous index and static

linclt commented 2 years ago

I have change the index.html and static, but after bundler, the application still gives me the former page

asticode commented 2 years ago

Can you share your code where you call bootstrap.Run ?

linclt commented 2 years ago

Can you share your code where you call bootstrap.Run ?

image

I just use the demo

linclt commented 2 years ago

package main

import ( "encoding/json" "flag" "fmt" "log" "os" "time"

"github.com/asticode/go-astikit"
"github.com/asticode/go-astilectron"
bootstrap "github.com/asticode/go-astilectron-bootstrap"
"github.com/asticode/go-astilectron-demo/goend/cache"
"github.com/asticode/go-astilectron-demo/goend/regedit"
"github.com/asticode/go-astilectron-demo/parameters"

)

// Constants const htmlAbout = Welcome on <b>Astilectron</b> demo!<br> This is using the bootstrap and the bundler.

// Vars injected via ldflags by bundler var ( AppName string BuiltAt string VersionAstilectron string VersionElectron string )

// Application Vars var ( fs = flag.NewFlagSet(os.Args[0], flag.ContinueOnError) debug = fs.Bool("d", false, "enables the debug mode") W astilectron.Window h Handler R *regedit.Regedit )

func main() { // 初始化全局变量

// 初始化message handler
handler := new(Handler)
handler.Parameters = parameters.New()

// 初始化cache
cache.InitGoCache()
cache.GoCache.Set("cacheStatus", "cache is ready", 24*time.Hour)

// 初始化配置注册表
R = regedit.New("`SOFTWARE\\NeMatRepair`").Init()

// Create logger
l := log.New(log.Writer(), log.Prefix(), log.Flags())

// Parse flags
fs.Parse(os.Args[1:])

// Run bootstrap
l.Printf("Running app built at %s\n", BuiltAt)
if err := bootstrap.Run(bootstrap.Options{
    AstilectronOptions: astilectron.Options{
        AppName:            AppName,
        AppIconDarwinPath:  "resources/bitbug_favicon.icns",
        AppIconDefaultPath: "resources/bitbug_favicon.ico",
        SingleInstance:     true, //true只能启动一个,false能启动多个
        VersionAstilectron: VersionAstilectron,
        VersionElectron:    VersionElectron,
    },
    Debug:  *debug,
    Logger: l,
    OnWait: func(app *astilectron.Astilectron, ws []*astilectron.Window, _ *astilectron.Menu, _ *astilectron.Tray, _ *astilectron.Menu) error {

        W = ws[0]
        W.OpenDevTools()

        SendMessage("goToJs", "go send to js", func(m *bootstrap.MessageIn) {

            // Unmarshal
            var s string
            if err := json.Unmarshal(m.Payload, &s); err != nil {
                return
            }

            SendMessage("goToJs", s, func(m *bootstrap.MessageIn) {

                // Unmarshal
                var s string
                if err := json.Unmarshal(m.Payload, &s); err != nil {
                    return
                }

                // Process message
                log.Printf("received %s\n", s)
            })

            // Process message
            log.Printf("received %s\n", s)
        })

        return nil
    },
    Windows: []*bootstrap.Window{{
        Homepage:       "index.html",
        MessageHandler: handler.handleMessages,
        Options: &astilectron.WindowOptions{
            Width:           astikit.IntPtr(780),
            Height:          astikit.IntPtr(850),
            MinWidth:        astikit.IntPtr(780),
            MinHeight:       astikit.IntPtr(850),
            BackgroundColor: astikit.StrPtr("#0d0e13"),
            UseContentSize:  astikit.BoolPtr(true),
            Center:          astikit.BoolPtr(true),
            Frame:           astikit.BoolPtr(false), //取消标题栏
            WebPreferences: &astilectron.WebPreferences{
                DevTools:           astikit.BoolPtr(true),
                EnableRemoteModule: astikit.BoolPtr(true),
                WebviewTag:         astikit.BoolPtr(true),
                WebSecurity:        astikit.BoolPtr(true),
            },
            // Icon: astikit.StrPtr("C:/Users/Administrator/go/src/github.com/asticode/go-astilectron-demo/resources/icon.ico"),
        },
    }},
    // 任务栏右下角功能区出现了icon
    // TrayOptions: &astilectron.TrayOptions{
    //  Image: astikit.StrPtr("C:/Users/Administrator/go/src/github.com/asticode/go-astilectron-demo/resources/icon.ico"),
    // },
}); err != nil {
    l.Fatal(fmt.Errorf("running bootstrap failed: %w", err))
}

}

asticode commented 2 years ago

Can you share the content of your resources/app folder ?

linclt commented 2 years ago

Can you share the content of your resources/app folder ?

sure image index.html: <!DOCTYPE html>demo

image

it`s a vue example

asticode commented 2 years ago

Can you tell me whether the index.html file is present in C:/Users/Administrator/AppData/Roaming/Astilectron Demo1/resources/app ?

linclt commented 2 years ago

Can you tell me whether the index.html file is present in C:/Users/Administrator/AppData/Roaming/Astilectron Demo1/resources/app ?

it is not present in that file

linclt commented 2 years ago

Can you tell me whether the index.html file is present in C:/Users/Administrator/AppData/Roaming/Astilectron Demo1/resources/app ?

it is not present in that file

just have vendor, and don`t have resources

asticode commented 2 years ago

Can you share the file/folder structure in your go project ? You should have the resources folder there

linclt commented 2 years ago

Can you share the file/folder structure in your go project ? You should have the resources folder there

yes,it`s here image

asticode commented 2 years ago

This is really weird 🤔

Can you share the ouput logs when you run the bundler ?

linclt commented 2 years ago

This is really weird 🤔

Can you share the ouput logs when you run the bundler ?

C:\Users\Administrator\go\src\github.com\asticode\go-astilectron-demo>astilectron-bundler 2021/11/05 09:52:30 Bundling for environment windows/amd64 2021/11/05 09:52:30 Binding data 2021/11/05 09:52:30 Removing C:\Users\ADMINI~1\AppData\Local\Temp\2\astibundler\bind 2021/11/05 09:52:30 Creating C:\Users\ADMINI~1\AppData\Local\Temp\2\astibundler\bind 2021/11/05 09:52:30 Creating C:\Users\ADMINI~1\AppData\Local\Temp\2\astibundler\bind\vendor_astilectron_bundler 2021/11/05 09:52:30 Creating C:\Users\ADMINI~1\AppData\Local\Temp\2\astibundler\cache 2021/11/05 09:52:30 C:\Users\ADMINI~1\AppData\Local\Temp\2\astibundler\cache\astilectron-0.49.0.zip already exists, skipping download of https://github.com/asticode/astilectron/archive/v0.49.0.zip 2021/11/05 09:52:30 Copying C:\Users\ADMINI~1\AppData\Local\Temp\2\astibundler\cache\astilectron-0.49.0.zip to C:\Users\ADMINI~1\AppData\Local\Temp\2\astibundler\bind\vendor_astilectron_bundler\astilectron.zip 2021/11/05 09:52:30 C:\Users\ADMINI~1\AppData\Local\Temp\2\astibundler\cache\electron-windows-amd64-11.4.3.zip already exists, skipping download of https://github.com/electron/electron/releases/download/v11.4.3/electron-v11.4.3-win32-x64.zip 2021/11/05 09:52:30 Copying C:\Users\ADMINI~1\AppData\Local\Temp\2\astibundler\cache\electron-windows-amd64-11.4.3.zip to C:\Users\ADMINI~1\AppData\Local\Temp\2\astibundler\bind\vendor_astilectron_bundler\electron.zip 2021/11/05 09:52:30 Creating C:\Users\ADMINI~1\AppData\Local\Temp\2\astibundler\bind\resources 2021/11/05 09:52:30 Copying C:\Users\Administrator\go\src\github.com\asticode\go-astilectron-demo\resources to C:\Users\ADMINI~1\AppData\Local\Temp\2\astibundler\bind\resources 2021/11/05 09:52:30 Generating C:\Users\Administrator\go\src\github.com\asticode\go-astilectron-demo\bind_windows_amd64.go 2021/11/05 09:52:35 Running rsrc for icon C:\Users\Administrator\go\src\github.com\asticode\go-astilectron-demo\resources\icon.ico into C:\Users\Administrator\go\src\github.com\asticode\go-astilectron-demo\windows.syso 2021/11/05 09:52:35 Removing C:\Users\Administrator\go\src\github.com\asticode\go-astilectron-demo\output\windows-amd64 2021/11/05 09:52:35 Creating C:\Users\Administrator\go\src\github.com\asticode\go-astilectron-demo\output\windows-amd64 2021/11/05 09:52:35 Building for os windows and arch amd64 astilectron: 0.49.0 electron: 11.4.3 2021/11/05 09:52:35 Executing go build -ldflags -H "windowsgui" -X "main.AppName=test" -X "main.BuiltAt=2021-11-05 09:52:35.0766983 +0000 GMT m=+4.792497401" -X "main.VersionAstilectron=0.49.0" -X "main.VersionElectron=11.4.3" -o C:\Users\Administrator\go\src\github.com\asticode\go-astilectron-demo\output\windows-amd64\binary github.com\asticode\go-astilectron-demo 2021/11/05 09:52:50 Moving C:\Users\Administrator\go\src\github.com\asticode\go-astilectron-demo\output\windows-amd64\binary to C:\Users\Administrator\go\src\github.com\asticode\go-astilectron-demo\output\windows-amd64\test.exe

C:\Users\Administrator\go\src\github.com\asticode\go-astilectron-demo>

linclt commented 2 years ago

This is really weird 🤔

Can you share the ouput logs when you run the bundler ?

image

linclt commented 2 years ago

This is really weird 🤔

Can you share the ouput logs when you run the bundler ?

image

linclt commented 2 years ago

This is really weird 🤔

Can you share the ouput logs when you run the bundler ? image

asticode commented 2 years ago

Can you share logs when you run the generated binary in a Windows terminal ?

linclt commented 2 years ago

Can you share logs when you run the generated binary in a Windows terminal ?

image

asticode commented 2 years ago

Sorry, I meant logs when you run test.exe in a terminal

linclt commented 2 years ago

Sorry, I meant logs when you run test.exe in a terminal

sorry, i am not sure that i understand your meaning, do you mean this: image

linclt commented 2 years ago

Sorry, I meant logs when you run test.exe in a terminal

it just start and looks like this: image

asticode commented 2 years ago

Could you replace

// Create logger
l := log.New(log.Writer(), log.Prefix(), log.Flags())

with

// Create logger
f, err := os.Open("/your/path/log.txt")
if err != nil {
  log.Fatal(err)
}
defer f.Close()
l := log.New(f, log.Prefix(), log.Flags())

Make sure to replace "/your/path/log.txt" with a valid path for a new log file.

Run test.exe again and share the content of this new log file.

linclt commented 2 years ago

Could you replace

// Create logger
l := log.New(log.Writer(), log.Prefix(), log.Flags())

with

// Create logger
f, err := os.Open("/your/path/log.txt")
if err != nil {
  log.Fatal(err)
}
defer f.Close()
l := log.New(f, log.Prefix(), log.Flags())

Make sure to replace "/your/path/log.txt" with a valid path for a new log file.

Run test.exe again and share the content of this new log file.

ok

linclt commented 2 years ago

Could you replace

// Create logger
l := log.New(log.Writer(), log.Prefix(), log.Flags())

with

// Create logger
f, err := os.Open("/your/path/log.txt")
if err != nil {
  log.Fatal(err)
}
defer f.Close()
l := log.New(f, log.Prefix(), log.Flags())

Make sure to replace "/your/path/log.txt" with a valid path for a new log file.

Run test.exe again and share the content of this new log file.

package main

import ( "flag" "fmt" "log" "os" "time"

"github.com/asticode/go-astikit"
"github.com/asticode/go-astilectron"
bootstrap "github.com/asticode/go-astilectron-bootstrap"
"github.com/asticode/go-astilectron-demo/goend/cache"
"github.com/asticode/go-astilectron-demo/goend/regedit"
"github.com/asticode/go-astilectron-demo/parameters"

)

// Constants const htmlAbout = Welcome on <b>Astilectron</b> demo!<br> This is using the bootstrap and the bundler.

// Vars injected via ldflags by bundler var ( AppName string BuiltAt string VersionAstilectron string VersionElectron string )

// Application Vars var ( fs = flag.NewFlagSet(os.Args[0], flag.ContinueOnError) debug = fs.Bool("d", false, "enables the debug mode") W astilectron.Window h Handler R *regedit.Regedit )

func main() { // 初始化全局变量

// 初始化message handler
handler := new(Handler)
handler.Parameters = parameters.New()

// 初始化cache
cache.InitGoCache()
cache.GoCache.Set("cacheStatus", "cache is ready", 24*time.Hour)

// 初始化配置注册表
R = regedit.New("`SOFTWARE\\NeMatRepair`").Init()

// Create logger
// Create logger
f, err := os.Open("C:/Users/Administrator/Desktop/log.txt")
if err != nil {
    log.Fatal(err)
}
defer f.Close()
l := log.New(f, log.Prefix(), log.Flags())

// Create logger
// l := log.New(log.Writer(), log.Prefix(), log.Flags())
// Parse flags
fs.Parse(os.Args[1:])

// Run bootstrap
l.Printf("Running app built at %s\n", BuiltAt)
if err := bootstrap.Run(bootstrap.Options{
    AstilectronOptions: astilectron.Options{
        AppName:            AppName,
        AppIconDarwinPath:  "resources/bitbug_favicon.icns",
        AppIconDefaultPath: "resources/bitbug_favicon.ico",
        SingleInstance:     true, //true只能启动一个,false能启动多个
        VersionAstilectron: VersionAstilectron,
        VersionElectron:    VersionElectron,
    },
    Debug:  *debug,
    Logger: l,
    OnWait: func(app *astilectron.Astilectron, ws []*astilectron.Window, _ *astilectron.Menu, _ *astilectron.Tray, _ *astilectron.Menu) error {

        W = ws[0]
        W.OpenDevTools()

        // SendMessage("goToJs", "go send to js", func(m *bootstrap.MessageIn) {

        //  // Unmarshal
        //  var s string
        //  if err := json.Unmarshal(m.Payload, &s); err != nil {
        //      return
        //  }

        //  // Process message
        //  log.Printf("received %s\n", s)

        //  SendMessage("goToJs", s, func(m *bootstrap.MessageIn) {

        //      // Unmarshal
        //      var s string
        //      if err := json.Unmarshal(m.Payload, &s); err != nil {
        //          return
        //      }

        //      // Process message
        //      log.Printf("received %s\n", s)
        //  })

        // })

        return nil
    },
    Windows: []*bootstrap.Window{{
        Homepage:       "index.html",
        MessageHandler: handler.handleMessages,
        Options: &astilectron.WindowOptions{
            Width:           astikit.IntPtr(780),
            Height:          astikit.IntPtr(850),
            MinWidth:        astikit.IntPtr(780),
            MinHeight:       astikit.IntPtr(850),
            BackgroundColor: astikit.StrPtr("#0d0e13"),
            UseContentSize:  astikit.BoolPtr(true),
            Center:          astikit.BoolPtr(true),
            Frame:           astikit.BoolPtr(false), //取消标题栏
            WebPreferences: &astilectron.WebPreferences{
                DevTools:           astikit.BoolPtr(true),
                EnableRemoteModule: astikit.BoolPtr(true),
                WebviewTag:         astikit.BoolPtr(true),
                WebSecurity:        astikit.BoolPtr(true),
            },
            // Icon: astikit.StrPtr("C:/Users/Administrator/go/src/github.com/asticode/go-astilectron-demo/resources/icon.ico"),
        },
    }},
    // 任务栏右下角功能区出现了icon
    // TrayOptions: &astilectron.TrayOptions{
    //  Image: astikit.StrPtr("C:/Users/Administrator/go/src/github.com/asticode/go-astilectron-demo/resources/icon.ico"),
    // },
}); err != nil {
    l.Fatal(fmt.Errorf("running bootstrap failed: %w", err))

}

}

do i do it in the right way?

linclt commented 2 years ago

Could you replace

// Create logger
l := log.New(log.Writer(), log.Prefix(), log.Flags())

with

// Create logger
f, err := os.Open("/your/path/log.txt")
if err != nil {
  log.Fatal(err)
}
defer f.Close()
l := log.New(f, log.Prefix(), log.Flags())

Make sure to replace "/your/path/log.txt" with a valid path for a new log file. Run test.exe again and share the content of this new log file.

package main

import ( "flag" "fmt" "log" "os" "time"

"github.com/asticode/go-astikit"
"github.com/asticode/go-astilectron"
bootstrap "github.com/asticode/go-astilectron-bootstrap"
"github.com/asticode/go-astilectron-demo/goend/cache"
"github.com/asticode/go-astilectron-demo/goend/regedit"
"github.com/asticode/go-astilectron-demo/parameters"

)

// Constants const htmlAbout = Welcome on <b>Astilectron</b> demo!<br> This is using the bootstrap and the bundler.

// Vars injected via ldflags by bundler var ( AppName string BuiltAt string VersionAstilectron string VersionElectron string )

// Application Vars var ( fs = flag.NewFlagSet(os.Args[0], flag.ContinueOnError) debug = fs.Bool("d", false, "enables the debug mode") W astilectron.Window h Handler R *regedit.Regedit )

func main() { // 初始化全局变量

// 初始化message handler
handler := new(Handler)
handler.Parameters = parameters.New()

// 初始化cache
cache.InitGoCache()
cache.GoCache.Set("cacheStatus", "cache is ready", 24*time.Hour)

// 初始化配置注册表
R = regedit.New("`SOFTWARE\\NeMatRepair`").Init()

// Create logger
// Create logger
f, err := os.Open("C:/Users/Administrator/Desktop/log.txt")
if err != nil {
  log.Fatal(err)
}
defer f.Close()
l := log.New(f, log.Prefix(), log.Flags())

// Create logger
// l := log.New(log.Writer(), log.Prefix(), log.Flags())
// Parse flags
fs.Parse(os.Args[1:])

// Run bootstrap
l.Printf("Running app built at %s\n", BuiltAt)
if err := bootstrap.Run(bootstrap.Options{
  AstilectronOptions: astilectron.Options{
      AppName:            AppName,
      AppIconDarwinPath:  "resources/bitbug_favicon.icns",
      AppIconDefaultPath: "resources/bitbug_favicon.ico",
      SingleInstance:     true, //true只能启动一个,false能启动多个
      VersionAstilectron: VersionAstilectron,
      VersionElectron:    VersionElectron,
  },
  Debug:  *debug,
  Logger: l,
  OnWait: func(app *astilectron.Astilectron, ws []*astilectron.Window, _ *astilectron.Menu, _ *astilectron.Tray, _ *astilectron.Menu) error {

      W = ws[0]
      W.OpenDevTools()

      // SendMessage("goToJs", "go send to js", func(m *bootstrap.MessageIn) {

      //  // Unmarshal
      //  var s string
      //  if err := json.Unmarshal(m.Payload, &s); err != nil {
      //      return
      //  }

      //  // Process message
      //  log.Printf("received %s\n", s)

      //  SendMessage("goToJs", s, func(m *bootstrap.MessageIn) {

      //      // Unmarshal
      //      var s string
      //      if err := json.Unmarshal(m.Payload, &s); err != nil {
      //          return
      //      }

      //      // Process message
      //      log.Printf("received %s\n", s)
      //  })

      // })

      return nil
  },
  Windows: []*bootstrap.Window{{
      Homepage:       "index.html",
      MessageHandler: handler.handleMessages,
      Options: &astilectron.WindowOptions{
          Width:           astikit.IntPtr(780),
          Height:          astikit.IntPtr(850),
          MinWidth:        astikit.IntPtr(780),
          MinHeight:       astikit.IntPtr(850),
          BackgroundColor: astikit.StrPtr("#0d0e13"),
          UseContentSize:  astikit.BoolPtr(true),
          Center:          astikit.BoolPtr(true),
          Frame:           astikit.BoolPtr(false), //取消标题栏
          WebPreferences: &astilectron.WebPreferences{
              DevTools:           astikit.BoolPtr(true),
              EnableRemoteModule: astikit.BoolPtr(true),
              WebviewTag:         astikit.BoolPtr(true),
              WebSecurity:        astikit.BoolPtr(true),
          },
          // Icon: astikit.StrPtr("C:/Users/Administrator/go/src/github.com/asticode/go-astilectron-demo/resources/icon.ico"),
      },
  }},
  // 任务栏右下角功能区出现了icon
  // TrayOptions: &astilectron.TrayOptions{
  //  Image: astikit.StrPtr("C:/Users/Administrator/go/src/github.com/asticode/go-astilectron-demo/resources/icon.ico"),
  // },
}); err != nil {
  l.Fatal(fmt.Errorf("running bootstrap failed: %w", err))

}

}

do i do it in the right way?

i run test.exe and log.txt is empty,but still get this: image

asticode commented 2 years ago

Can you replace *debug with true?

linclt commented 2 years ago

Can you replace *debug with true?

i replace it with true, but still get the same result

asticode commented 2 years ago

log.txt is still empty?

linclt commented 2 years ago

log.txt is still empty?

yes

asticode commented 2 years ago

Did you manage to solve your problem ?

linclt commented 2 years ago

Did you manage to solve your problem ?

Finally, I found the reason, it `is because of Asset: Asset,AssetDir: AssetDir, I delete them