I build an electron app with auto-update enabled. After running the application on Windows, I got an error emitted by my application which is "Error: Can not find Squirrel".
After look into the code of electron project for finding the error message.
checkForUpdates () {
const url = this.updateURL;
if (!url) {
return this.emitError(new Error('Update URL is not set'));
}
if (!squirrelUpdate.supported()) {
return this.emitError(new Error('Can not find Squirrel'));
}
this.emit('checking-for-update');
squirrelUpdate.checkForUpdate(url, (error, update) => {
if (error != null) {
return this.emitError(error);
}
if (update == null) {
return this.emit('update-not-available');
}
this.updateAvailable = true;
this.emit('update-available');
squirrelUpdate.update(url, (error) => {
if (error != null) {
return this.emitError(error);
}
const { releaseNotes, version } = update;
// Date is not available on Windows, so fake it.
const date = new Date();
this.emit('update-downloaded', {}, releaseNotes, version, date, this.updateURL, () => {
this.quitAndInstall();
});
});
});
}
And after check the function squirrelUpdate.supported(). I know it is because the install location has no file "Update.exe".
I use electron-builder to generate my application and there is no Update.exe in unpacked packaged directory. How do I generate the Update.exe file?
The block of configuration of electron-builder in package.json is blow:
"win": {
"target": [
"nsis"
],
"defaultArch": "x64",
"verifyUpdateCodeSignature": false
},
How to solve the problem? Thanks.
The reason there is no update.exe is because you have "nsis" as the target package type.
The auto updater package you are trying to use is meant to be compatible with Squirrel.Windows. If you change your target to "squirrel" it will have the update.exe you are looking for.
There are additional dependencies required when using Squirrel.Windows; see below:
https://www.electron.build/configuration/win
Related
We are building an electron desktop application for macos, linux, and windows.
Here is our electron-forge config:
// forge.config.js
const os = require('os')
const package = require('./package.json')
function getExtraResource() {
const p = os.platform()
switch (p) {
case 'darwin':
return ['./static/bin/pasteld-mac']
case 'linux':
return ['./static/bin/pasteld-linux']
case 'win32':
return ['./static/bin/pasteld-win.exe']
default:
throw new Error(
'forge.config.js error: your OS is not supported. Supported OS are: darwin, linux, win32',
)
}
}
function getIcon() {
const p = os.platform()
switch (p) {
case 'darwin':
return './static/icons/icon.icns'
case 'linux':
return './static/icons/icon.png'
case 'win32':
return './static/icons/icon.ico'
default:
throw new Error(
'forge.config.js error: your OS is not supported. Supported OS are: darwin, linux, win32',
)
}
}
module.exports = {
packagerConfig: {
name: package.productName,
executableName: package.name,
icon: getIcon(),
asar: true,
extraResource: getExtraResource(),
protocols: [
{
protocol: package.name,
name: package.name,
schemes: [package.protocolSchemes.native],
},
],
},
makers: [
{
name: '#electron-forge/maker-squirrel',
config: {
exe: `${package.name}.exe`,
setupIcon: './static/icons/icon.ico',
loadingGif: './static/icons/icon.gif',
iconUrl:
'https://raw.githubusercontent.com/pastelnetwork/pastel-electron-wallet/master/static/icons/icon.ico',
title: package.productName,
setupExe: `${package.productName} Setup - v${package.version}.exe`,
skipUpdateIcon: true,
},
},
{
name: '#electron-forge/maker-dmg',
config: {
icon: './static/icons/icon.icns',
name: package.productName,
},
},
{
name: '#electron-forge/maker-deb',
config: {
options: {
icon: './static/icons/icon.png',
},
},
},
],
plugins: [
[
'#electron-forge/plugin-webpack',
{
mainConfig: './webpack.main.config.js',
renderer: {
config: './webpack.renderer.config.js',
entryPoints: [
{
html: './src/index.html',
js: './src/renderer.tsx',
name: 'main_window',
},
],
},
},
],
],
}
As you can see in the above file, getExtraResource() detects the os type and pick the right executable file based on it. In other words, running run make on a proper platform is all we need to build the application.
However, we are now going to build the windows installer on linux wine image, more specifically using electronuserland/builder:wine-mono image.
Everything is working as expected so far, except one thing - we still need to add a step to the switch clause in the getExtraResource() to pick the windows executable in the builder image instead of linux executable(note that the builder image is still a linux image!).
It will be something like this:
# forge.config.js
//...
function getExtraResource() {
const p = os.platform()
switch (p) {
case 'darwin':
return ['./static/bin/pasteld-mac']
case 'linux':
if (build_arg === 'win32') {
return ['./static/bin/pasteld-win.exe']
}
return ['./static/bin/pasteld-linux']
case 'win32':
return ['./static/bin/pasteld-win.exe']
default:
throw new Error(
'forge.config.js error: your OS is not supported. Supported OS are: darwin, linux, win32',
)
}
}
//...
How can I get the build_arg in the above file?
Build command is yarn make --platform=win32 in the wine builder image.
Thanks in advance!
Electron Forge supports hooks and some of them get passed the platform and arch which you could save globally.
Currently the earliest hook that gets passed these is packageAfterCopy which might be called too late for your usage but worth a try:
plugins: [
// ...
],
hooks: {
packageAfterCopy: async (
forgeConfig,
buildPath,
electronVersion,
platform,
arch
) => {
console.log(buildPath, electronVersion, platform, arch);
},
}
}
I've also opened a PR to add these parameters to the generateAssets hook.
We could resolve this by using process.argv.
More specifically, we run this command to build windows installer in linux container:
yarn make --platform=win32
And the string win32 could be caught by process.argv[3] anywhere.
See the detailed implementation here.
Please advice if you have a better solution!
I had lot of difficulties after upgrading signalR & .NET version.
Previously I had 1.XX version now I have 2.4.0 signal R version.
This question is directly connected with - https://github.com/SignalR/SignalR/issues/4339
But after upgrade signal R doesn't work.
Now the problem is client-side functions cannot call.
I just tried this: Signalr doesn't call client side functions
and fixed it according to the correct answer:
In your init prior to $.connection.hub.start call your _subscribe method.
Later I went through a bit deeper down on this issue, and added console.log below place in my signalr.js
connection.socket.onmessage = function (event) {
var data;
try {
console.log(event.data);
data = connection._parseResponse(event.data);
}
catch (error) {
transportLogic.handleParseFailure(connection, event.data, error, onFailed, event);
console.log("socket error" + event.data);
return;
}
if (data) {
transportLogic.processMessages(connection, data, onSuccess);
}
};
After every one joins meeting -> meeting start and ask for vote (this place we should call signalR)
From vote asking person side I see console log like this:
Normal user ( voting persons console log looks like this:
This is from Firefox - another user:
I think it already triggering - client hub event 'sendOnlineMeetingVoteRequest' on hub 'NotificationHub'.
It already hit server-side function too but the thing is it never hits this part of the code:
notificationHub.client.sendOnlineMeetingVoteRequest = function (token, meetingId, meetingVoteId) {
debugger;
if (token == '#Model.Organization' && '#Model.MeetingId' == meetingId) {
ShowMeetingOnlineMeetingVotePopup(meetingId, meetingVoteId);
}
};
I went through http://localhost:33852/signalr/hubs
/*!
* ASP.NET SignalR JavaScript Library v2.3.0-rtm
* http://signalr.net/
*
* Copyright (c) .NET Foundation. All rights reserved.
* Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
*
*/
/// <reference path="..\..\SignalR.Client.JS\Scripts\jquery-1.6.4.js" />
/// <reference path="jquery.signalR.js" />
(function ($, window, undefined) {
/// <param name="$" type="jQuery" />
"use strict";
if (typeof ($.signalR) !== "function") {
throw new Error("SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/js.");
}
var signalR = $.signalR;
function makeProxyCallback(hub, callback) {
return function () {
// Call the client hub method
callback.apply(hub, $.makeArray(arguments));
};
}
function registerHubProxies(instance, shouldSubscribe) {
var key, hub, memberKey, memberValue, subscriptionMethod;
for (key in instance) {
if (instance.hasOwnProperty(key)) {
hub = instance[key];
if (!(hub.hubName)) {
// Not a client hub
continue;
}
if (shouldSubscribe) {
// We want to subscribe to the hub events
subscriptionMethod = hub.on;
} else {
// We want to unsubscribe from the hub events
subscriptionMethod = hub.off;
}
// Loop through all members on the hub and find client hub functions to subscribe/unsubscribe
for (memberKey in hub.client) {
if (hub.client.hasOwnProperty(memberKey)) {
memberValue = hub.client[memberKey];
if (!$.isFunction(memberValue)) {
// Not a client hub function
continue;
}
// Use the actual user-provided callback as the "identity" value for the registration.
subscriptionMethod.call(hub, memberKey, makeProxyCallback(hub, memberValue), memberValue);
}
}
}
}
}
$.hubConnection.prototype.createHubProxies = function () {
var proxies = {};
this.starting(function () {
// Register the hub proxies as subscribed
// (instance, shouldSubscribe)
registerHubProxies(proxies, true);
this._registerSubscribedHubs();
}).disconnected(function () {
// Unsubscribe all hub proxies when we "disconnect". This is to ensure that we do not re-add functional call backs.
// (instance, shouldSubscribe)
registerHubProxies(proxies, false);
});
proxies['NotificationHub'] = this.createHubProxy('NotificationHub');
proxies['NotificationHub'].client = { };
proxies['NotificationHub'].server = {
sendMeetingStartMessage: function (token, meetingId) {
return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendMeetingStartMessage"], $.makeArray(arguments)));
},
sendMeetingStopMessage: function (token, meetingId) {
return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendMeetingStopMessage"], $.makeArray(arguments)));
},
sendMeetingTreeRefreshRequest: function (token, meetingId) {
return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendMeetingTreeRefreshRequest"], $.makeArray(arguments)));
},
sendMessage: function (token, meetingId, agendaGroupItemId, motionId) {
return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendMessage"], $.makeArray(arguments)));
},
sendOnlineMeetingVoteCloseRequest: function (token, meetingId, meetingVoteId) {
return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendOnlineMeetingVoteCloseRequest"], $.makeArray(arguments)));
},
sendOnlineMeetingVoteRequest: function (token, meetingId, meetingVoteId) {
return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendOnlineMeetingVoteRequest"], $.makeArray(arguments)));
},
sendOnlineVoteCloseRequest: function (token, meetingId, agendaGroupItemId, motionId) {
return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendOnlineVoteCloseRequest"], $.makeArray(arguments)));
},
sendOnlineVoteRequest: function (token, meetingId, agendaGroupItemId, motionId) {
return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendOnlineVoteRequest"], $.makeArray(arguments)));
},
sendOnlineVoteResult: function (token, meetingId, agendaGroupItemId, motionId, selectedVotingOptionId) {
return proxies['NotificationHub'].invoke.apply(proxies['NotificationHub'], $.merge(["sendOnlineVoteResult"], $.makeArray(arguments)));
}
};
return proxies;
};
signalR.hub = $.hubConnection("/signalr", { useDefaultPath: false });
$.extend(signalR, signalR.hub.createHubProxies());
}(window.jQuery, window));
So I didn't found any error on it too.
Still, I cannot figure it out why this is happening but I went through the sample project that uses signalR 2.0.3.0 version
I went to reference & just noted that this reference - Microsoft.AspNet.SignalR.Owin is not included in that sample project that I downloaded.
I did some investigation furthermore & find out this:
'The call is ambiguous between the following methods or properties'
This error will occur if a reference to Microsoft.AspNet.SignalR.Owin
is not removed. This package is deprecated; the reference must be
removed and the 1.x version of the SelfHost package must be
uninstalled.
(https://learn.microsoft.com/en-us/aspnet/signalr/overview/releases/upgrading-signalr-1x-projects-to-20)
Do I need to remove that?
In my web config, there is no code like this.
I just call this function purely from another place - about us page. only add relevant script and function.
from that place, it worked.
after that, I changed some scripts placing and fix this issue.
the main thing is I didn't get any error or anything. thing looks working all the time. but because of some script placement, it doesn't work.
When I run the application from command prompt using npm start command it works well. It returning the result from speech api.
I am using binaryServer and binaryclient to stream audio to google cloud API.
When I create package for electron application everything works but it not returning the result from speech api.
Here are my code snippe:
Package.json
{
"name": "test",
"version": "1.0.0",
"description": "test Web Server",
"main": "main.js",
"scripts": {
"start": "electron main.js"
},
"devDependencies": {
"electron": "^1.4.12"
},
"dependencies": {
"binaryjs": "^0.2.1",
"connect": "^3.3.4",
"biased-opener": "^0.2.8",
"serve-static": "^1.9.1",
"uaparser": "^0.0.2",
"#google-cloud/speech" : "^0.5.0"
}
}
Here is my main.js
app.on('ready', function () {
load_app();
});
var workerProcess = child_process.spawn('node', __dirname + '/binaryServer.js');
workerProcess.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
workerProcess.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
workerProcess.on('close', function (code) {
console.log('child process exited with code ' + code);
});
processes.push(workerProcess);
function load_app () {
// Launches the browser window
mainWindow = new BrowserWindow({ width: 1080, height: 1920 });
// Load just launched server in browser window
mainWindow.loadURL("http://localhost:" + config.port);
if (config.devMode) {
mainWindow.webContents.openDevTools();
}
else {
mainWindow.setFullScreen(true);
}
}
here is my binary server
var binaryServer = require('binaryjs').BinaryServer,
https = require('http'),
connect = require('connect'),
serveStatic = require('serve-static');
var config = require('./config');
var server = connect()
.use(serveStatic(__dirname));
var speech = require('#google-cloud/speech')({
projectId: config.speech.projectId,
keyFilename: config.speech.keyFilename
});
httpServer = https.createServer(server);
httpServer.timeout = 0;
httpServer.listen(config.port);
var binarySer = binaryServer({ server: httpServer });
console.log("server pid" + process.pid);
binarySer.on('connection', function (client) {
console.log("new connection...");
client.on('stream', function (stream, meta) {
var options = {
config: {
encoding: 'LINEAR16',
sampleRate: meta.sampleRate,
languageCode: "en-IN"
},
singleUtterance: false,
interimResults: true,
verbose: true
};
// Create a recognize stream
const recognizeStream = speech.createRecognizeStream(options)
.on('error', console.error)
.on('data', function (data) { if (stream.writable && !stream.destroyed) stream.write(data) }); // send data to client
if (recognizeStream.writable && !recognizeStream.destroyed && stream.readable && !stream.destroyed)
stream.pipe(recognizeStream); // pipe audio to cloud speech
});
client.on('close', function () {
console.log("Connection Closed");
});
});
Thanks for your help
Taking a shot in the dark here (without much familiarity with binaryServer, which realistically could be the issue). I'm also a bit unclear about where the audio stream actually comes from:
Electron packages its own version of V8. When you run npm install it will install (or compile on the fly) the native binaries targeted for the version of V8 that are installed on your machine (local version). When you spawn the child process it uses that same local version.
However, when you package your electron app it will try to spawn the process with Electron's version of V8 and there will be binary incompatibilities.
Put simply
[Your version of V8] != [Electron's version of V8]
On to potential solutions
Sonus is compatible with
Electron provided that you
Re-compile dependencies with
electron-recompile
I'm trying to use the method setMetadata, using the File plugin, but it seems does not work.
No Success or Fail callback is executed. When I use console.log(entry.setMetadata), it prints the correct method. I use the File plugin to access, create and delete files and folders without problems. Only the setMetadata doesn't work.
Example:
localFileSystem = LocalFileSystem.PERSISTENT;
subFolder = "Backups";
metadataKey = "com.apple.MobileBackup";
metadataValue = 1;
window.requestFileSystem(localFileSystem, 0, function(fileSystem) {
fileSystem.root.getDirectory(subFolder, {create: true, exclusive: false}, function(parent) {
var data = {};
data[metadataKey] = metadataValue;
console.log(data); // OK
console.log(parent); // OK
parent.setMetadata(function() {
console.log("success setting metadata"); // Nothing
}, function() {
console.log("error setting metadata"); // Nothing
}, data);
}, function() {
console.log("error getting dir"); // Nothing, directory is OK
});
}, function(error) {
console.log(error.code); // No error here
});
It was a bug on the File plugin. I checked with the developers on Github:
https://github.com/apache/cordova-plugin-file/pull/39
Just waiting for changes on the Phonegap site.
I get an exception when i try to upgrade my indexedDB database with a higher version then the browser currently has,
but the funny part abort is that, it gets upgraded. Is this by design or have i done something wrong.
I got very inspired from the dart sample Todo, so my code ended up looking like this.
void open_db(String DB_name, int Version, String Store_Name){
var request = window.indexedDB.open(DB_name, Version);
request.on.success.add((e) => _onDbOpened(request.result));
request.on.error.add((e) => print("Error opening db"));
request.on.upgradeNeeded.add((e) => _onUpgradeNeeded(request.transaction, Store_Name));
}
void _onDbOpened(IDBDatabase db){
_db = db;
print("DB opened");
}
void _onUpgradeNeeded(IDBTransaction changeVersionTransaction, String Store_Name){
changeVersionTransaction.on.error.add((e) => print("Error upgrading db"));
changeVersionTransaction.on.complete.add((e) => print("Success upgrading db"));
changeVersionTransaction.db.createObjectStore(Store_Name);
}
When I run this with version=4 and the browser only have version=3, then it jumps to _onUpgradeNeeded as expected, but I get an IDBDatabaseException with message: "ConstraintError: DOM IDBDatabase Exception 4".
So where is it I go wrong?
Thanks for your question!
You may need to check if the store exists first.
if (db.objectStoreNames.indexOf(storeName) == -1) {
db.createObjectStore(storeName);
}
Here is some code to update your IndexedDB database, using Dart. Note, this compensates for the two ways to upgrade (an old way that Chrome used, and the new way that Firefox and newer versions of Chrome use)
_openDb(afterOpen()) {
var request = window.indexedDB.open(DB_NAME, VERSION);
if (request is IDBOpenDBRequest) {
// New upgrade protocol. FireFox 15, Chrome 24, hopefully IE10.
request.on.success.add(expectAsync1((e) {
db = e.target.result;
afterOpen();
}));
request.on.upgradeNeeded.add((e) {
guardAsync(() {
_createObjectStore(e.target.result);
});
});
request.on.error.add(fail('open'));
} else {
// Legacy setVersion upgrade protocol. Chrome < 23.
request.on.success.add(expectAsync1((e) {
db = e.target.result;
if (db.version != '$VERSION') {
var setRequest = db.setVersion('$VERSION');
setRequest.on.success.add(
expectAsync1((e) {
_createObjectStore(db);
var transaction = e.target.result;
transaction.on.complete.add(
expectAsync1((e) => afterOpen()));
transaction.on.error.add(fail('Upgrade'));
}));
setRequest.on.error.add(fail('setVersion error'));
} else {
afterOpen();
}
}));
request.on.error.add(fail('open'));
}
}
_createObjectStore(db) {
try {
// Nuke object store if it already exists.
db.deleteObjectStore(STORE_NAME);
}
on IDBDatabaseException catch(e) { } // Chrome
on DOMException catch(e) { } // Firefox
db.createObjectStore(STORE_NAME);
}
Note, this code is from this test: http://code.google.com/p/dart/source/browse/trunk/dart/tests/html/indexeddb_3_test.dart