meteor-desktop icon indicating copy to clipboard operation
meteor-desktop copied to clipboard

Override function in autoupdate module

Open gerwinbrunner opened this issue 7 years ago • 10 comments

What would be the best way to override the checkForUpdates function in the skeleton/modules/autoupdate/ module for a desktop application?

Any hint would be very appreciated.

Cheers, Gerwin

gerwinbrunner avatar Apr 11 '17 11:04 gerwinbrunner

Hey,

firstly, what do you need that for 🙂 ?

In the desktop.js you receive a modules parameter. So in the constructor of desktop.js you should be able to do modules.autoupdate.checkForUpdates = function() {}

wojtkowiak avatar Apr 11 '17 13:04 wojtkowiak

We have separated out the hot code push servers and use a custom ddp connection for them. So I need to fix that function to fit this req.

I'll try your idea and let you know if it works. Thx

On 11 Apr 2017, at 20:54, Bartosz Wojtkowiak [email protected] wrote:

Hey,

firstly, what do you need that for 🙂 ?

In the desktop.js you receive a modules parameter. So in the constructor of desktop.js you should be able to do modules.autoupdate.checkForUpdates = function() {}

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

gerwinbrunner avatar Apr 11 '17 15:04 gerwinbrunner

I just tried what you suggested, by

        modules.autoupdate.checkForUpdates = function(){
            this.log.debug('JUHUHU');
            const runtimeConfig = this.currentAssetBundle.getRuntimeConfig();
            const rootUrl = runtimeConfig.public.AutoupdateServer;
            if (!rootUrl) {
                this.log.error('no rootUrl found in the current asset bundle');
                this.module.send(
                    'error',
                    'checkForUpdates requires a rootURL to be configured'
                );
                return;
            }

            this.assetBundleManager.checkForUpdates(url.resolve(rootUrl, '__cordova/'));
        };

I also added a logging to the original function in my forked package. It seems that the original function is called and not the overwritten :(

gerwinbrunner avatar Apr 12 '17 08:04 gerwinbrunner

I printed the function before and after overriding it. console.log('HELLO', modules.autoupdate.checkForUpdates);

Here is the log output

verbose: [autoupdate] initializing autoupdate module
verbose: [autoupdate] trying to read initial bundle version
verbose: [autoupdate] [AssetBundle] making bundle object for /Users/ap/Documents/workspaces/VilangoWork/le3/le3.desktop-apollo/app/.meteor/desktop-build/meteor.asar
verbose: [autoupdate] [AssetBundle] loading manifest from /Users/ap/Documents/workspaces/VilangoWork/le3/le3.desktop-apollo/app/.meteor/desktop-build/meteor.asar
debug: [autoupdate] [AssetManifest] 94 entries. (Version: ba9cd69f976a5ae8af31a543864ee6b551f83a90)
verbose: [autoupdate] [AssetBundle] trying to read desktop version for ba9cd69f976a5ae8af31a543864ee6b551f83a90
verbose: [autoupdate] [AssetBundle] the desktop version is 6644e551807bfe891bb80ff86dc61fd094ea4b6d
info: [autoupdate] detected new bundled version, removing versions directory if it exists
info: [autoupdate] created versions dir
verbose: [autoupdate] using initial asset bundle
HELLO checkForUpdates() {
        this.log.debug('XUXUXUXU :(');

        const rootUrl = this.currentAssetBundle.getRootUrlString();
        if (!rootUrl) {
            this.log.error('no rootUrl found in the current asset bundle');
            this.module.send(
                'error',
                'checkForUpdates requires a rootURL to be configured'
            );
            return;
        }

        this.assetBundleManager.checkForUpdates(url.resolve(rootUrl, '__cordova/'));
    }
HELLO function () {
            this.log.debug('JUHUHU');
            const runtimeConfig = this.currentAssetBundle.getRuntimeConfig();
            const rootUrl = runtimeConfig.public.AutoupdateServer;
            if (!rootUrl) {
                this.log.error('no rootUrl found in the current asset bundle');
                this.module.send('error', 'checkForUpdates requires a rootURL to be configured');
                return;
            }

            this.assetBundleManager.checkForUpdates(url.resolve(rootUrl, '__cordova/'));
        }
debug: [main] desktop loaded
info: [localServer] will serve from:  /Users/ap/Documents/workspaces/VilangoWork/le3/le3.desktop-apollo/app/.meteor/desktop-build/meteor.asar
info: [localServer] assigned port 8036
verbose: [autoupdate] started startup timer
debug: [autoupdate] timer set to 60000
verbose: [localStorage] storage from port 8054 migrated to 8036
info: [meteor-desktop-localstorage] loaded storage file /Users/ap/Library/Application Support/LinguajetDesktop/localstorage.json
info: [meteor-desktop-localstorage] have 0 keys
verbose: [meteor-desktop-splash-screen] [splashWindow] enabling click through
verbose: [meteor-desktop-localstorage] getAll received
verbose: [meteor-desktop-localstorage] sent storage to renderer
verbose: [autoupdate] startup did complete, stopping startup timer (startup took 1078ms)
info: [main] assuming meteor webapp has loaded
debug: [main] showing main window
debug: [main] received did-stop-loading
info: [main] assuming meteor webapp has loaded
debug: [main] window already loaded
debug: [autoupdate] XUXUXUXU :(
info: [autoupdate] [AssetBundleManager] checkForUpdates http://localhost:3000/__cordova/
info: [autoupdate] [AssetBundleManager] trying to query http://localhost:3000/__cordova/manifest.json
error: [autoupdate] [AssetManifest] error parsing asset manifest: Unexpected token < in JSON at position 0
debug: [autoupdate] [AssetBundleManager] fail: error parsing asset manifest: Unexpected token < in JSON at position 0
error: [autoupdate] download failure: error parsing asset manifest: Unexpected token < in JSON at position 0


gerwinbrunner avatar Apr 12 '17 08:04 gerwinbrunner

Hmm that is weird. I do not have that much time now to check it but would it help if you could pass this custom url for hcp in settings.json?

wojtkowiak avatar Apr 13 '17 07:04 wojtkowiak

Sure.

I actually pass it already thru meteor.settings

Mit freundlichen Grüßen Gerwin Brunner

On 13 Apr 2017, at 14:45, Bartosz Wojtkowiak [email protected] wrote:

Hmm that is weird. I do not have that much time now to check it but would it help if you could pass this custom url for hcp in settings.json?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

gerwinbrunner avatar Apr 13 '17 09:04 gerwinbrunner

Released https://github.com/wojtkowiak/meteor-desktop/commit/6dc362f6410a85cd6e40463841ddc9b0389a2bc9 in 0.6.2

wojtkowiak avatar Apr 13 '17 12:04 wojtkowiak

Tested it and works!

We do have multiple destination Url for with we need to build separate versions of the client. I was thinking to create several files for it. I.e. development-settings.json, staging-settings.json, production-settings.json. Similar to we way you can deal with settings files in meteor.

Is there a way to pass in the settings file to use in the way you can do it in meteor? I did not really find a way.

gerwinbrunner avatar Apr 14 '17 04:04 gerwinbrunner

Not at the moment. Would it be ok if the files would be named: settings-dev.json settings-production.json settings-anyname.json and you could specify it through command line switch like npm run desktop -- -s dev or npm run desktop -- --settings anyname?

wojtkowiak avatar Apr 14 '17 07:04 wojtkowiak

Awesome. That would be exactly what I was looking for! The filenames you proposed would be totally fine.

gerwinbrunner avatar Apr 14 '17 07:04 gerwinbrunner